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

Joachim Ziegler ziegler at mpi-sb.mpg.de
Thu Oct 30 08:50:01 EDT 2008


Hello!

Maybe this has been asked here 100 times before, but I've searched 
through the archives and could not find a solution to my problem:

I have a program that I want to link statically agains tthe NSPR libs, 
and, if this is possible, against the Winsock2 libs.

So far, I have in

D:\nspr-4.6\lib

the files

libnspr4.dll
libnspr4.lib
libnspr4_s.dll

The following excerpt from my CMakeLists.txt works fine

if(CMAKE_HOST_WIN32)
   INCLUDE_DIRECTORIES(D:/nspr-4.6/include)
   LINK_DIRECTORIES(D:/nspr-4.6/lib)
   ADD_EXECUTABLE(testPR PRifdefd.cpp ${BASEFILES})
   TARGET_LINK_LIBRARIES(testPR nspr4 Ws2_32)
...

To run the executable, I have to copy the lib files libnspr4.dll and 
libnspr4.lib into the build directory (where the executable testPR is 
built). (Can I avoid this somehow?)

But now, what if I want to compile statically against NSPR (and maybe 
Winsock2), so that I can give away my executable to a customer?

Greetings,
Joachim











More information about the CMake mailing list