I am trying to compile a simple project which uses one of my headers. I am on Windows and I am using MinGW-W64-builds-4.3.5
Suppose the project is called test.cpp
and I want to compile it using my headerosmanip
which requires also the linking of its created static library libosmanip.lib
. The static library has been compiled and created in MSYS2 and then copied into Windows filesystem. If I try to compile with:
g -std=c 17 -losmanip .\test.cpp
To search for the system headers and library path I did:
g -v test.cpp
and decided to put headers into C:\MinGW\bin\..\lib\gcc\i686-w64-mingw32\8.1.0\include\c
and the static library into C:\MinGW\lib\gcc\i686-w64-mingw32\8.1.0\
.
I got the following error:
C:/MinGW/bin/../lib/gcc/i686-w64-mingw32/8.1.0/../../../../i686-w64-mingw32/bin/ld.exe:
cannot find -losmanip
collect2.exe: error: ld returned 1 exit status
I've tried also by adding the -L
option, linking the library path, or editing the LIBRARY_PATH
variable ( $Env:LIBRARY_PATH =";C:/MinGW/bin/../lib/gcc/i686-w64-mingw32/8.1.0/"
), but it still doesn't work.
I tried to move the library into the same folder of the test.cpp
file and compile, but again the same error occurs.
It's strange because I tried same thing on Ubuntu, MacOS, MSYS2 and Cygwin64 and it works.
Can you help, me please?
CodePudding user response:
I finally solved the issue. The problem was related to the fact the the suffix of my library was .lib
. By changing it in .a
and rebuilding the library passing the correct static library name to the ar
command the problem disappeared.