Import a Visual Studio static library

BlitzMax Forums/BlitzMax Programming/Import a Visual Studio static library

JoshK(Posted 2012) [#1]
Is it possible to import a C++ Visual Studio static library? The commands I am interested are externed as C functions. I get a ton of linker errors when I try importing my .lib.


BlitzSupport(Posted 2012) [#2]
I believe you'll have to convert it to a .a file. There are various tools if you Google 'lib to a', though I've no idea how good they are. Here's an example:

http://code.google.com/p/lib2a/


col(Posted 2012) [#3]
Hiya

I'm using MingW gcc 4.6.2 and I can import and use the VS static .lib files straight into BMax. MingW is said to be compatible with VS .lib files nowadays, but how far this goes I'm not sure. I can get it work ok with functions but I've not tried it with classes etc.

Some keynotes:

Say the static library generated from your VS project is called 'foo.lib' then in BMax use

Import "-lfoo"

There's no need to rename the file to foo.a or libfoo.a or similar, but you can if you want to, just change the name within the quotes accordingly.

You can use Import "-L*folder_name*" where *folder_name* is a folder to include when searching for and linking library files. EDIT- This folder path CANNOT have spaces anywhere!

One last thing is the calling convention, I'm sure you already know it's imperative it is the same in your VS project and BMax. I've statically linked Microsofts own VS .lib files straight into BMax with success. I know your'e using the c++ extern"c" to prevent name-mangling but you can still set the calling convention using __stdcall or __cdecl accordingly.

Last edited 2012


JoshK(Posted 2012) [#4]
It still requires a DLL after the .a file is generated. Is there any way to do it without a DLL?

Last edited 2012


col(Posted 2012) [#5]
EDITed as I was chatting gibberish.

There are 2 formats of .lib for VS. One produced when creating a static library project, and a different one produced when creating a .dll
The one I link to is the one created for a .dll.

I'll be quiet now.

Last edited 2012


JoshK(Posted 2012) [#6]
LIB2A wants a DLL.


BlitzSupport(Posted 2012) [#7]
LIB2A might be written especially for the situation where you have your own DLL (ie. with source) that you want to turn into a static lib. Try Googling "convert lib to a", which turns up a fair few pointers... looks like "reimp", part of MinGW, *might* be what you want.

This thread seems to agree with col's first post, though, regarding direct import of .lib files, so my pointer about converting to .a might be irrelevant now anyway:

http://www.gamedev.net/topic/360137-converting-lib-to-a/

However, it might be that your particular .lib 'describes' a DLL as in col's post above, rather than replaces it.

What library are you trying to convert?


JoshK(Posted 2012) [#8]
No, I have a .lib file that is self-contained.

The LIB2A .bat example uses a DLL. From the instructions:
How it works

The conversion process is accomplished in several steps:

Copy your .LIB file and .DLL file into the "convert" folder.

Edit and replace the files names in the four first lines at the LIB2A.bat.

Run LIB2A.bat.

You can find your .A linker library into the "convert" folder.


Last edited 2012