Click here to Skip to main content
15,795,402 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi, I was wondering whether it is possible to create lib files with gcc and use them also with gcc. As lib files I mean the files produced by Microsoft CL that have the extension lib and look like "advapi32.lib". My platform is Windows NT. I already know that I can produce and use .a files from .o files. An ideal set of commands for me to build the whole thing would be like this:

For the library:
gcc -c libfile1.c -o libfile1.o
gcc -c libfile2.c -o libfile2.o
gcc -o sample.lib libfile1.o libfile2.o

And for the program:
gcc -c appfile1.c -o appfile1.o
gcc -c appfile2.c -o appfile2.o
gcc -o app.exe appfile1.o appfile2.o -l sample.lib

1 solution

Nope. No can do.

MS compiler produces .lib files, GCC produces .a files.

You can't link .a files to projects with Visual Studio. Nor an you link .lib files to projects with GCC.

What you trying to do/achieve?
Share this answer
iPick12 3-Jul-12 12:09pm    
I'm trying to create an IDE that runs on Win32 and I thought it'd be nice to have Visual Studio compatibility. Apparently I can't, but anyway, thanks for your help.
enhzflep 3-Jul-12 12:13pm    
Okay, well in that instance - you can write the code such that it will build with both VS and GCC.
If you're using Code::Blocks, you can even setup both build targets for the same project, since CB will let you use any one of a whole bunch of build tools with no problems.
So, typically a new project will have Debug and Release configurations. You can add 2 new configs - Debug VS & Release VS. You just have to point to the correct compiler and setup any environment vars.

Never bothered myself, I just create 2 project files - one for CB and the other for VS - but all of the .cpp .h .rc and sound/image files are shared between both projects - it just means another short period to build with the alternate tool. Got a pdf creation lib that works fine for both - no changes needed or compiler specific hacks. (Just stay away from the nasty practise of using the #pragma directive as a way to link libraries in VS - it doesn't work in GCC)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900