Is there a built in way to create dynamic libraries with hxcpp?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Is there a built in way to create dynamic libraries with hxcpp?

Batuhan Bozkurt
Hi all,

Is there a simple way to create binary libraries to link against with haxecpp?

Thanks,
Batuhan

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Is there a built in way to create dynamic libraries with hxcpp?

Paul Zirkle
Yes, you can use "haxelib run hxcpp BuildFile.xml" method

Just like writing a haxelib, you would write your code then create a BuildFile.xml which contains the compilation instructions. Then use the hxcpp build-tool to create your .dll  (look at the Build.xml file in the NME haxlib project folder for examples of building for different targets)

On Wed, Mar 16, 2011 at 4:00 PM, Batuhan Bozkurt <[hidden email]> wrote:
Hi all,

Is there a simple way to create binary libraries to link against with haxecpp?

Thanks,
Batuhan

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Is there a built in way to create dynamic libraries with hxcpp?

Tony Polinelli
That is if you need the output to build for multiple platforms, in an automated way. If you are just looking in general, just build a .dll (in visual studio, etc) and link against it using the Loader (neko.Loader? cpp.Loader? - cant remember the exact class)  - look at nme again for how link into it. 



On Thu, Mar 17, 2011 at 11:43 AM, Paul Zirkle <[hidden email]> wrote:
Yes, you can use "haxelib run hxcpp BuildFile.xml" method

Just like writing a haxelib, you would write your code then create a BuildFile.xml which contains the compilation instructions. Then use the hxcpp build-tool to create your .dll  (look at the Build.xml file in the NME haxlib project folder for examples of building for different targets)

On Wed, Mar 16, 2011 at 4:00 PM, Batuhan Bozkurt <[hidden email]> wrote:
Hi all,

Is there a simple way to create binary libraries to link against with haxecpp?

Thanks,
Batuhan

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org



--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Is there a built in way to create dynamic libraries with hxcpp?

Tony Polinelli
http://haxe.org/doc/cpp/ffi?lang=en

On Thu, Mar 17, 2011 at 3:18 PM, Tony Polinelli <[hidden email]> wrote:
That is if you need the output to build for multiple platforms, in an automated way. If you are just looking in general, just build a .dll (in visual studio, etc) and link against it using the Loader (neko.Loader? cpp.Loader? - cant remember the exact class)  - look at nme again for how link into it. 



On Thu, Mar 17, 2011 at 11:43 AM, Paul Zirkle <[hidden email]> wrote:
Yes, you can use "haxelib run hxcpp BuildFile.xml" method

Just like writing a haxelib, you would write your code then create a BuildFile.xml which contains the compilation instructions. Then use the hxcpp build-tool to create your .dll  (look at the Build.xml file in the NME haxlib project folder for examples of building for different targets)

On Wed, Mar 16, 2011 at 4:00 PM, Batuhan Bozkurt <[hidden email]> wrote:
Hi all,

Is there a simple way to create binary libraries to link against with haxecpp?

Thanks,
Batuhan

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org



--
Tony Polinelli
http://touchmypixel.com



--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Is there a built in way to create dynamic libraries with hxcpp?

Batuhan Bozkurt
Thanks a lot. I've been looking into the Build.xml scripts and such but due to my lack of adequate experience in C++ realm, I'm stuck in wrapping my head around some simple seemingly simple concepts. Sorry if this all sounds too elementary.

I have a collection of haxe classes that I want to compile to cpp files. Then I want to be able to compile a binary library out of them, and I want to use that library with external C++ code. I also want to be able to link against the library statically.

Maybe I'm getting the mechanics behind the process utterly wrong, but the thing I am curious about is that, when I want to compile any haxe code to cpp, haxe requires me to specify an entry point for an "application", a "main" function.  Since my library consists of a bunch of classes, it isn't an application by itself. Does this matter at all? Should I provide a dummy entry point for a non existing application? Is there a better way to do it? I've been going through the docs but couldn't find this mentioned anywhere.

Suppose I have this code:

class MyLib
{
var myVal : Float;
public function new(argVal : Float)
{
trace("initializing!");
myVal = 42;
}
public function giveVal() : Float
{
trace(myVal);
return myVal;
}
}

What I want to do is to emit cpp code out of this and compile it into a library so that I can instantiate and use the class in my external C++ code. My first hurdle is the lack of an entry point in the library, so I can't compile it unless I add a main() function somewhere. Does what I'm saying makes any sense? :)

Thanks.



On Thu, Mar 17, 2011 at 6:18 AM, Tony Polinelli <[hidden email]> wrote:
http://haxe.org/doc/cpp/ffi?lang=en


On Thu, Mar 17, 2011 at 3:18 PM, Tony Polinelli <[hidden email]> wrote:
That is if you need the output to build for multiple platforms, in an automated way. If you are just looking in general, just build a .dll (in visual studio, etc) and link against it using the Loader (neko.Loader? cpp.Loader? - cant remember the exact class)  - look at nme again for how link into it. 



On Thu, Mar 17, 2011 at 11:43 AM, Paul Zirkle <[hidden email]> wrote:
Yes, you can use "haxelib run hxcpp BuildFile.xml" method

Just like writing a haxelib, you would write your code then create a BuildFile.xml which contains the compilation instructions. Then use the hxcpp build-tool to create your .dll  (look at the Build.xml file in the NME haxlib project folder for examples of building for different targets)

On Wed, Mar 16, 2011 at 4:00 PM, Batuhan Bozkurt <[hidden email]> wrote:
Hi all,

Is there a simple way to create binary libraries to link against with haxecpp?

Thanks,
Batuhan

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org



--
Tony Polinelli
http://touchmypixel.com



--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Is there a built in way to create dynamic libraries with hxcpp?

Tony Polinelli
oh sorry - i read your question incorrectly - i thought you ment the other way. my bad

On Thu, Mar 17, 2011 at 5:11 PM, Batuhan Bozkurt <[hidden email]> wrote:
Thanks a lot. I've been looking into the Build.xml scripts and such but due to my lack of adequate experience in C++ realm, I'm stuck in wrapping my head around some simple seemingly simple concepts. Sorry if this all sounds too elementary.

I have a collection of haxe classes that I want to compile to cpp files. Then I want to be able to compile a binary library out of them, and I want to use that library with external C++ code. I also want to be able to link against the library statically.

Maybe I'm getting the mechanics behind the process utterly wrong, but the thing I am curious about is that, when I want to compile any haxe code to cpp, haxe requires me to specify an entry point for an "application", a "main" function.  Since my library consists of a bunch of classes, it isn't an application by itself. Does this matter at all? Should I provide a dummy entry point for a non existing application? Is there a better way to do it? I've been going through the docs but couldn't find this mentioned anywhere.

Suppose I have this code:

class MyLib
{
var myVal : Float;
public function new(argVal : Float)
{
trace("initializing!");
myVal = 42;
}
public function giveVal() : Float
{
trace(myVal);
return myVal;
}
}

What I want to do is to emit cpp code out of this and compile it into a library so that I can instantiate and use the class in my external C++ code. My first hurdle is the lack of an entry point in the library, so I can't compile it unless I add a main() function somewhere. Does what I'm saying makes any sense? :)

Thanks.



On Thu, Mar 17, 2011 at 6:18 AM, Tony Polinelli <[hidden email]> wrote:
http://haxe.org/doc/cpp/ffi?lang=en


On Thu, Mar 17, 2011 at 3:18 PM, Tony Polinelli <[hidden email]> wrote:
That is if you need the output to build for multiple platforms, in an automated way. If you are just looking in general, just build a .dll (in visual studio, etc) and link against it using the Loader (neko.Loader? cpp.Loader? - cant remember the exact class)  - look at nme again for how link into it. 



On Thu, Mar 17, 2011 at 11:43 AM, Paul Zirkle <[hidden email]> wrote:
Yes, you can use "haxelib run hxcpp BuildFile.xml" method

Just like writing a haxelib, you would write your code then create a BuildFile.xml which contains the compilation instructions. Then use the hxcpp build-tool to create your .dll  (look at the Build.xml file in the NME haxlib project folder for examples of building for different targets)

On Wed, Mar 16, 2011 at 4:00 PM, Batuhan Bozkurt <[hidden email]> wrote:
Hi all,

Is there a simple way to create binary libraries to link against with haxecpp?

Thanks,
Batuhan

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org



--
Tony Polinelli
http://touchmypixel.com



--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org



--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Is there a built in way to create dynamic libraries with hxcpp?

Gamehaxe
In reply to this post by Batuhan Bozkurt
Hi,
The iphone target compiles the hxcpp code into a static library, and then  
links against it.
You will need a "main" in your exe code, and then this can call the haxe  
code. see:

http://code.google.com/p/nekonme/source/browse/trunk/install-tool/iphone/Classes/Main.cpp

You can compile to a static library by passing "-D static" on the haxe  
command line.
You should be able to "#include" the generated files from hxcpp and link  
your
own c++ code to the generated .lib file and then call like in the example.

The hxRunLibrary() will call your "static main()" function, but you can  
leave this
empty and carry on with your C Code. But you do need to call this to get  
the
statics to initialize.

You must also be careful when keeping pointers to hxcpp objects - local  
variables are
OK, but you will need to store them in GC roots if you store them in  
malloced memory.

This scenario has not been well developed though, and what you are
trying to do may well cause you some pain.

Hugh


> Thanks a lot. I've been looking into the Build.xml scripts and such but  
> due
> to my lack of adequate experience in C++ realm, I'm stuck in wrapping my
> head around some simple seemingly simple concepts. Sorry if this all  
> sounds
> too elementary.
>
> I have a collection of haxe classes that I want to compile to cpp files.
> Then I want to be able to compile a binary library out of them, and I  
> want
> to use that library with external C++ code. I also want to be able to  
> link
> against the library statically.
>
> Maybe I'm getting the mechanics behind the process utterly wrong, but the
> thing I am curious about is that, when I want to compile any haxe code to
> cpp, haxe requires me to specify an entry point for an "application", a
> "main" function.  Since my library consists of a bunch of classes, it  
> isn't
> an application by itself. Does this matter at all? Should I provide a  
> dummy
> entry point for a non existing application? Is there a better way to do  
> it?
> I've been going through the docs but couldn't find this mentioned  
> anywhere.
>
> Suppose I have this code:
>
> class MyLib
> {
> var myVal : Float;
>  public function new(argVal : Float)
> {
> trace("initializing!");
> myVal = 42;
> }
>  public function giveVal() : Float
> {
> trace(myVal);
> return myVal;
> }
> }
>
> What I want to do is to emit cpp code out of this and compile it into a
> library so that I can instantiate and use the class in my external C++  
> code.
> My first hurdle is the lack of an entry point in the library, so I can't
> compile it unless I add a main() function somewhere. Does what I'm saying
> makes any sense? :)
>
> Thanks.
>
>
>
> On Thu, Mar 17, 2011 at 6:18 AM, Tony Polinelli  
> <[hidden email]>wrote:
>
>> http://haxe.org/doc/cpp/ffi?lang=en
>>
>>
>> On Thu, Mar 17, 2011 at 3:18 PM, Tony Polinelli  
>> <[hidden email]>wrote:
>>
>>> That is if you need the output to build for multiple platforms, in an
>>> automated way. If you are just looking in general, just build a .dll  
>>> (in
>>> visual studio, etc) and link against it using the Loader (neko.Loader?
>>> cpp.Loader? - cant remember the exact class)  - look at nme again for  
>>> how
>>> link into it.
>>>
>>>
>>>
>>> On Thu, Mar 17, 2011 at 11:43 AM, Paul Zirkle <[hidden email]> wrote:
>>>
>>>> Yes, you can use "haxelib run hxcpp BuildFile.xml" method
>>>>
>>>> Just like writing a haxelib, you would write your code then create a
>>>> BuildFile.xml which contains the compilation instructions. Then use  
>>>> the
>>>> hxcpp build-tool to create your .dll  (look at the Build.xml file in  
>>>> the NME
>>>> haxlib project folder for examples of building for different targets)
>>>>
>>>> On Wed, Mar 16, 2011 at 4:00 PM, Batuhan Bozkurt  
>>>> <[hidden email]>wrote:
>>>>
>>>>> Hi all,
>>>>>
>>>>> Is there a simple way to create binary libraries to link against with
>>>>> haxecpp?
>>>>>
>>>>> Thanks,
>>>>> Batuhan
>>>>>
>>>>> --
>>>>> haXe - an open source web programming language
>>>>> http://haxe.org
>>>>>
>>>>
>>>>
>>>> --
>>>> haXe - an open source web programming language
>>>> http://haxe.org
>>>>
>>>
>>>
>>>
>>> --
>>> Tony Polinelli
>>> http://touchmypixel.com
>>>
>>
>>
>>
>> --
>> Tony Polinelli
>> http://touchmypixel.com
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Is there a built in way to create dynamic libraries with hxcpp?

Batuhan Bozkurt
Thanks Hugh, that helped a lot. It's already causing some pain but that is because I'm not that skilled in this yet. :) I'm willing to give it a try nonetheless...

I've compiled a simple class (as posted above) and trying to load it as a library as in the iphone example code. The only *_register_prims symbols I can find in my compiled library are _std_register_prims, _regexp_register_prims and _zlib_register_prims. I see that these are initiated from hxRunLibrary so I don't have to explicitly call them to load primitives right?

In any case, I am getting linker errors for these three.

  "_std_register_prims", referenced from:



      _main in main.o



      _hxRunLibrary in HxDylib.a(RunLibs.o)



  "_regexp_register_prims", referenced from:



      _hxRunLibrary in HxDylib.a(RunLibs.o)



  "_zlib_register_prims", referenced from:



      _hxRunLibrary in HxDylib.a(RunLibs.o)



ld: symbol(s) not found



collect2: ld returned 1 exit status



From the symbol table of my own compiled library, I see that the symbols are referred as external. I tried adding regexp.dylib, std.dylib and zlib.dylib to my linker but I still get these errors.

If I add the cpp files under /runtime/libs/std to my project, the linker error for std_register_prims() disappear.

If I add the ZLib.cpp file to the project, I get a duplicate entry point error.

If I add the regexp cpp files to the project, the register_prims() linker error for regexp disappears but I can further new linker errors that are probably referenced from Regexp sources. I need to recheck what they are if it is of any help.

I compile my haxe file with this:
-cp src
-cpp cpp
-D static
-main HxDylib

Can't these libs be statically compiled into my lib? 

For the GC issues, I have a feeling that I will be fine for now. In most cases, I'll have the objects in my cpp code initialized once in heap at launch. The subsequent object creations/deletions are handled inside my haxe code encapsulated from the outside world.

In any case if there is any clue as to how I'd go for storing them in "GC roots", I'd feel more secure. :)

Thanks a lot for your time.

Best,
Batuhan

On Thu, Mar 17, 2011 at 5:08 PM, Hugh Sanderson <[hidden email]> wrote:
Hi,
The iphone target compiles the hxcpp code into a static library, and then links against it.
You will need a "main" in your exe code, and then this can call the haxe code. see:

http://code.google.com/p/nekonme/source/browse/trunk/install-tool/iphone/Classes/Main.cpp

You can compile to a static library by passing "-D static" on the haxe command line.
You should be able to "#include" the generated files from hxcpp and link your
own c++ code to the generated .lib file and then call like in the example.

The hxRunLibrary() will call your "static main()" function, but you can leave this
empty and carry on with your C Code. But you do need to call this to get the
statics to initialize.

You must also be careful when keeping pointers to hxcpp objects - local variables are
OK, but you will need to store them in GC roots if you store them in malloced memory.

This scenario has not been well developed though, and what you are
trying to do may well cause you some pain.

Hugh



Thanks a lot. I've been looking into the Build.xml scripts and such but due
to my lack of adequate experience in C++ realm, I'm stuck in wrapping my
head around some simple seemingly simple concepts. Sorry if this all sounds
too elementary.

I have a collection of haxe classes that I want to compile to cpp files.
Then I want to be able to compile a binary library out of them, and I want
to use that library with external C++ code. I also want to be able to link
against the library statically.

Maybe I'm getting the mechanics behind the process utterly wrong, but the
thing I am curious about is that, when I want to compile any haxe code to
cpp, haxe requires me to specify an entry point for an "application", a
"main" function.  Since my library consists of a bunch of classes, it isn't
an application by itself. Does this matter at all? Should I provide a dummy
entry point for a non existing application? Is there a better way to do it?
I've been going through the docs but couldn't find this mentioned anywhere.

Suppose I have this code:

class MyLib
{
var myVal : Float;
 public function new(argVal : Float)
{
trace("initializing!");
myVal = 42;
}
 public function giveVal() : Float
{
trace(myVal);
return myVal;
}
}

What I want to do is to emit cpp code out of this and compile it into a
library so that I can instantiate and use the class in my external C++ code.
My first hurdle is the lack of an entry point in the library, so I can't
compile it unless I add a main() function somewhere. Does what I'm saying
makes any sense? :)

Thanks.



On Thu, Mar 17, 2011 at 6:18 AM, Tony Polinelli <[hidden email]>wrote:

http://haxe.org/doc/cpp/ffi?lang=en


On Thu, Mar 17, 2011 at 3:18 PM, Tony Polinelli <[hidden email]>wrote:

That is if you need the output to build for multiple platforms, in an
automated way. If you are just looking in general, just build a .dll (in
visual studio, etc) and link against it using the Loader (neko.Loader?
cpp.Loader? - cant remember the exact class)  - look at nme again for how
link into it.



On Thu, Mar 17, 2011 at 11:43 AM, Paul Zirkle <[hidden email]> wrote:

Yes, you can use "haxelib run hxcpp BuildFile.xml" method

Just like writing a haxelib, you would write your code then create a
BuildFile.xml which contains the compilation instructions. Then use the
hxcpp build-tool to create your .dll  (look at the Build.xml file in the NME
haxlib project folder for examples of building for different targets)

On Wed, Mar 16, 2011 at 4:00 PM, Batuhan Bozkurt <[hidden email]>wrote:

Hi all,

Is there a simple way to create binary libraries to link against with
haxecpp?

Thanks,
Batuhan

--
haXe - an open source web programming language
http://haxe.org



--
haXe - an open source web programming language
http://haxe.org




--
Tony Polinelli
http://touchmypixel.com




--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org