Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking a .lib file on Windows 7

I have a C++ program test.cpp and I want to link two .lib files to it(fhlib.lib and gc_lib.lib).I have the .lib files in the same folder as my .cpp program. I'm on Windows 7.

What I have tried so far is the following:

g++ -o main main.cpp -L/Users\Documents\Visual Studio 2015\Projects\My Project -lfhlib

But I get an

No such file or directory error.

I'm sure the path is correct because I copied it from Properties->Location. But I had do delete the "C:\", because it was not compiling.

EDIT: I found this http://www.mingw.org/wiki/Specify_the_libraries_for_the_linker_to_use.

So I tried using

"-I" instead of "-l"

But still doesn't work.I get:

undefined reference to 'fh_set'...
like image 245
lads Avatar asked Jul 26 '16 08:07

lads


1 Answers

If you're compiling with g++ on windows, I guess you're using MinGW: MinGW relies on .a libraries. When using the "-l" option, the compiler is looking for a library file with the extension .a.

Libraries in the format .lib are compiled with visual studio: you can't use it as this. Compile your libraries with MinGW if you have the sources or consider migrating your project to visual studio.

like image 120
rgmt Avatar answered Oct 11 '22 05:10

rgmt