How to create and link MSVC .lib files into blitzm

BlitzMax Forums/BlitzMax Programming/How to create and link MSVC .lib files into blitzm

gameshastra(Posted 2007) [#1]
What is the procedure to create and link a library from MSVC into blitzmax,
1)should we create a .lib file , a .dll file or both?
2) how to convert the .lib to a .a and where should the .a file be placed
3)ALso what are options to select in MSVC to create the .lib file.
Should the file containing the c++ code necessarily have _declspec(__dllexport) .... entries

I would be happy to get full details, as I have not found this anywhere else in the forums


gameshastra(Posted 2007) [#2]
Further on my question posted above. I wonder if the object(.o) file of the c++ code compiled by MSVC file cannot be directly provided to the compiler to link?


Brucey(Posted 2007) [#3]
If the API is exposed as C++ (rather than C), you may have problems with MSVC's C++ name-mangling, which I believe is different from GCC's.
ie. a function in the DLL might have a different mangled name to the one expected by GCC (which BlitzMax uses).

If the API is exposed as C, this should not be a problem.


gameshastra(Posted 2007) [#4]
Is it possible to get the mangled name using dumpbin and change the name in the .def file. What would the procedure be in this case
If the API is exposed as C, what are the other steps to follow?


Brucey(Posted 2007) [#5]
This is what I used for my BaH.DBMySQL module :

[code]
reimp -d libmysql.lib
dlltool -k -d libmysql.def -l libmysql.a
[/quote]
reimp creates the .def file. dlltool uses the .def to create the .a that is linked in to the app.


gameshastra(Posted 2007) [#6]
I have used reimp -d on my library file and it doesn't produce any output

My code has __declspec(dllexport) entries and I have compiled the same in MSVC as a static library. I am not sure this is the right procedure.


Dreamora(Posted 2007) [#7]
Did you enclose it in extern "C" { .. }?

and on your original question: at best you create a .a file and a dll


gameshastra(Posted 2007) [#8]
Isn't the extern "Win32" declaration to be placed in the blitzmax file? what is the need for an extern "C" in the c++ file.

How can I compile both as lib and dll
One requires __declspec(dllexport) and other doesn't


Brucey(Posted 2007) [#9]
what is the need for an extern "C" in the c++ file

As far as I know (and I'm certainly no expert!), exported C++ functions have their names mangled, exported C functions don't. Different C++ compilers mangle their names in different (incompatible) ways.

Can't answer any of your other questions, as I don't know much about Win32. Sorry.


gameshastra(Posted 2007) [#10]
Any help on the win32 side would be appreciated


gameshastra(Posted 2007) [#11]
Assuming I have the .a file where do I place it and how does the linker know that this file is to be linked.


Brucey(Posted 2007) [#12]
If you are using standard BlitzMax, you should put the .a into, BlitzMax/lib

You link against using a line like :

Import "-lstuff"

Where the .a file is named "libstuff.a"


gameshastra(Posted 2007) [#13]
Any help on the win32 side?
Is the ffmpeg module going to come soon?


gameshastra(Posted 2007) [#14]
I managed to link to the Dll using LoadLibraryA
I get the mangled function names using the pexports utility
pexports dllname


gameshastra(Posted 2007) [#15]
Linking to the .a files still fails. Though I have solved my problem through dll use as in previous post.


Dreamora(Posted 2007) [#16]
If linking with the .a fails you either didn't use it like Brucey sad or you are compiling it somehow strange with GCC