[CMake] How to link against a static lib under windows/minGW

Werner Smekal smekal at iap.tuwien.ac.at
Thu Oct 30 10:47:44 EDT 2008


>> Hi,


>
> OK, then libnspr4_s.dll must be some other lib, maybe a debug version.
>
> Anyway, changing the CMakeLists line
>  TARGET_LINK_LIBRARIES(testPR nspr4 Ws2_32)
> (with which linking works fine)) just to
>  TARGET_LINK_LIBRARIES(testPR nspr4_s Ws2_32)
>
> prevents the linker from finding the library:
>
>
> D:\MinGW\bin\g++.exe      CMakeFiles\testPR.dir\PRifdefd.cpp.obj  -o  
> testPR.exe
> -Wl,--out-implib,libtestPR.dll.a -Wl,--major-image-version,0,--minor- 
> image-version,0  -LD:\nspr-4.6\lib
> -lnspr4_s -lWs2_32
> D:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin 
> \ld.exe: cannot find -lnspr4_s
>

That's because it tries to link to libnspr4_s.lib which doesn't exist.  
Usually the naming conventions for MinGW libraries are:

libxxx.dll    executable
libxxx.dll.a    import library for dll
libxxx.a   shared library.

Obviously the MinGW linker also tries for libxxx.lib, and that's the  
reason why it works in the first case. But your .lib seems to be the  
import library for the dll, so I don't think you have a static library  
anyways.

Regards,
Werner

> (?)
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake

--
Dr. Werner Smekal
Institut fuer Allgemeine Physik
Technische Universitaet Wien
Wiedner Hauptstr 8-10
A-1040 Wien
Austria

email: smekal at iap.tuwien.ac.at
web: http://www.iap.tuwien.ac.at/~smekal
phone: +43-(0)1-58801-13463 (office), +43-(0)1-58801-13469 (laboratory)
fax: +43-(0)1-58801-13499



More information about the CMake mailing list