Compiling a module from C++

BlitzMax Forums/BlitzMax Programming/Compiling a module from C++

JoshK(Posted 2006) [#1]
I have a library of C code I would like to use with BlitzMax. It's very big and complicated. I don't know too much about C programming.

Can this just be compiled straight into a BlitzMax module? How do I go about figuring this out? I don't really have a clue where to start.

I have a bunch of .h and .lib files. I mostly just need to get the constants and types into BlitzMax, so that I can call the commands in the dll and have BlitzMax know all the types and constants I need to use.

Who is the best BlitzMax/C++ programmer to talk to about this?


Yan(Posted 2006) [#2]
.


Diablo(Posted 2006) [#3]
i think you can just import them like:

import "csource.c"
' etc

and then just extern any stuff you need like:

extern
somefunction1 % ()
'etc
end extern

at lest thats what i gather.

I think bmax will then complie the c files for you.


DStastny(Posted 2006) [#4]
I think he said he had headers *.h and libs. Now that can still be done but depends on what compiler was used to generate the libs? If it was MS Visual C++ and C++ objects no way is it going to work as BMax uses GCC and the way classes are stored in the object files are different between compilers. Now if the libs are straight C Functins then he "might" be able to link to libs.

Got to love tall the maybes and mights but based upon what was posted cant really tell much. Much easier to do if you have the source then its mostly structuring the imports as Diablo stated.

Doug Stastny


VIP3R(Posted 2006) [#5]
Budman is right, the .lib files are normally generated by the MS Visual C++ compiler, which won't work with BlitzMax.

The equivalent of a '.lib' library file for MinGW (BlitzMax) would be a '.a' library. If you have the full source it may be possible to either build the .a library from that, or try compiling the full source directly in BMax.

There may already be a MinGW compatible version of the library available, you should check that out before proceeding IMO.


Gabriel(Posted 2006) [#6]
If it were just straight functions, you could generate the .a files that GCC needs from the GCC command line tools, but MSVC++ mangles class names such that this won't work.


skidracer(Posted 2006) [#7]
Who is the best BlitzMax/C++ programmer to talk to about this?


I'm up for such a challenge. May require a small fee if it's not for public consumption.


Dreamora(Posted 2006) [#8]
Best thing you can do (and what I would suggest) is using the lib and create a DLL out of it and bind to that one, as BM can use DLLs without "hacking around"

If you can't do that for some reason (Nuclear Glory Collision C++ License is one of those), then there are tools that allow you to make the lib usable by GCC as well.

But yes, the most optimal thing would naturally be C source files to include.


JoshK(Posted 2006) [#9]
Simon, I am emailing you now.

I checked on Messenger, but it doesn't look like you are on.


gman(Posted 2006) [#10]
it depends on how the the exports are in the lib. newton game dynamics for example distributes a lib file usable in MSVC and MingW.
Import "Newton.lib"

i would setup a quick example first and just try to import a lib and call a single function from it to see if the libs of your library will work. if not, there are ways to try and convert a lib to .a format. ive had minimal success with that process though.

something else if the libs dont work, you can also try and create the needed .a file directly from the DLLs. ive had pretty good success with this method.

if your libs do work, then its just a matter of defining all your function exports in BMAX (thats where the .h files come in handy).


kfprimm(Posted 2006) [#11]
the make a .a file from a dll, go to the command prompt and type,
pexports mydll.dll >mydll.def
then,
dlltool -d mydll.def -l libmydll.a
then put libmydll.a into the lib folder in your BlitzMax directory and import it with
Import "-lmydll"



JoshK(Posted 2006) [#12]
Simon, I sent a follow-up email. I'm not sure if it went through, because I am not at home, and I was using a webmail page. Please let me know if you haven't received it.


Filax(Posted 2006) [#13]
any chance to see how to use .lib or .a file with bmax ?


Diablo(Posted 2006) [#14]
Look here filax:

http://blitzmax.com/Community/posts.php?topic=58369#649501


Filax(Posted 2006) [#15]
Many thanks :) i have try the process with : Bass.a but the
compiler return :

C:/Filou/.bmx/test.bmx.gui.release.win32.x86.o(code+0xb9): undefined reference to `BASS_Init@8'
C:/Filou/.bmx/test.bmx.gui.release.win32.x86.o(code+0xc1): undefined reference to `BASS_GetVersion@8'
Build Error: Failed to link C:/Filou/test.exe

You can download my test at :
http://www.blitz3dfr.com/tempo/bass.rar


Diablo(Posted 2006) [#16]
I would love to help but I cant atm ( at college ).

Im sure someone will be able to figure this out if not I'll take a look later.


Dreamora(Posted 2006) [#17]
Error on the definition, should be:

[code]
Extern
Function BASS_GetCPU()="BASS_GetCPU@0"
Function BASS_GetVersion:Int()="BASS_GetVersion@0"
Function BASS_Init(device:Int, freq:Int, flags:Int, hwnd:Int, dsguid:Byte Ptr)="BASS_Init@20"
End Extern[/quote]

As you don't send anything to GetCPU or GetVersion and 5x 4 bytes to Init