How to create and link MSVC .lib files into blitzm
BlitzMax Forums/BlitzMax Programming/How to create and link MSVC .lib files into blitzm
| ||
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 |
| ||
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? |
| ||
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. |
| ||
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? |
| ||
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. |
| ||
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. |
| ||
Did you enclose it in extern "C" { .. }? and on your original question: at best you create a .a file and a dll |
| ||
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 |
| ||
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. |
| ||
Any help on the win32 side would be appreciated |
| ||
Assuming I have the .a file where do I place it and how does the linker know that this file is to be linked. |
| ||
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" |
| ||
Any help on the win32 side? Is the ffmpeg module going to come soon? |
| ||
I managed to link to the Dll using LoadLibraryA I get the mangled function names using the pexports utility pexports dllname |
| ||
Linking to the .a files still fails. Though I have solved my problem through dll use as in previous post. |
| ||
If linking with the .a fails you either didn't use it like Brucey sad or you are compiling it somehow strange with GCC |