Cmake ignores static library request

I was looking for a watch on how to solve this, and everything I tried does not work. I am trying to link statically with some libraries (libPoco, libmysqlcpp, libmysqlclient, libssl).

I use cmake, and although I define a static library, cmake is just looking for a dynamic one. I know that I have all the necessary libraries in a static archive in my file system, and I know where they are.

set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /lib /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64 /usr/lib/x86_64-linux-gnu) find_library(POCO_NET NAMES libPocoNet.a PATHS CMAKE_LIBRARY_PATH STATIC IMPORTED) find_library(POCO_UTIL NAMES libPocoUtil.a PATHS CMAKE_LIBRARY_PATH STATIC IMPORTED) find_library(POCO_XML NAMES libPocoXML.a PATHS CMAKE_LIBRARY_PATH STATIC IMPORTED) find_library (MYSQL_CLIENT NAMES libmysqlclient.a PATHS CMAKE_LIBRARY_PATH STATIC IMPORTED) find_library (MYSQL_CPP NAMES libmysqlpp.a PATHS CMAKE_LIBRARY_PATH STATIC IMPORTED) find_library (LIBSSL NAMES libssl.a PATHS CMAKE_LIBRARY_PATH STATIC IMPORTED) if (POCO_NET AND POCO_UTIL AND POCO_XML AND MYSQL_CLIENT AND MYSQL_CPP AND LIBSSL) message(STATUS ${POCO_NET}) message(STATUS ${POCO_UTIL}) message(STATUS ${POCO_XML}) message(STATUS ${MYSQL_CLIENT}) message(STATUS ${MYSQL_CPP}) message(STATUS ${LIBSSL}) target_link_libraries(icarus PocoNet PocoUtil PocoXML mysqlpp mysqlclient ssl) else () message(FATAL_ERROR "FATAL ERROR: missing library") endif (POCO_NET AND POCO_UTIL AND POCO_XML AND MYSQL_CLIENT AND MYSQL_CPP AND LIBSSL) 

But when I started cmake .. , I get:

 -- /usr/local/lib/libPocoNet.so -- /usr/local/lib/libPocoUtil.so -- /usr/local/lib/libPocoXML.so -- /usr/lib/x86_64-linux-gnu/libmysqlclient.so -- /usr/lib/libmysqlpp.so -- /usr/lib/libssl.so 

And when I try to compile, I get undefined links, since I use the -static flag. What am I missing here? Is there a way to get cmake to look for static libraries instead of dynamic ones? Am I really wrong? Thanks.

+4
source share
1 answer

It looks like you are a little confused between the add_library and find_library commands. find_library does not accept STATIC or IMPORTED .

In addition, you did not wrap the CMAKE_LIBRARY_PATH in ${} in your find_library call, so you effectively pass the 3 paths "CMAKE_LIBRARY_PATH", "STATIC" and "IMPORTED" to the CMake search program, rather than the supposed 6 paths ${CMAKE_LIBRARY_PATH} .

Finally, since ${CMAKE_LIBRARY_PATH} already the first call port in the CMake search routine, there is no need to explicitly add it to find_library .

So you can do something like:

 set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /lib /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64 /usr/lib/x86_64-linux-gnu) find_library(POCO_NET NAMES libPocoNet.a) find_library(POCO_UTIL NAMES libPocoUtil.a) find_library(POCO_XML NAMES libPocoXML.a) find_library(MYSQL_CLIENT NAMES libmysqlclient.a) find_library(MYSQL_CPP NAMES libmysqlpp.a) find_library(LIBSSL NAMES libssl.a PATHS) if(POCO_NET AND POCO_UTIL AND POCO_XML AND MYSQL_CLIENT AND MYSQL_CPP AND LIBSSL) message(STATUS ${POCO_NET}) message(STATUS ${POCO_UTIL}) message(STATUS ${POCO_XML}) message(STATUS ${MYSQL_CLIENT}) message(STATUS ${MYSQL_CPP}) message(STATUS ${LIBSSL}) target_link_libraries(icarus ${POCO_NET} ${POCO_UTIL} ${POCO_XML} ${MYSQL_CLIENT} ${MYSQL_CPP} ${LIBSSL}) else() message(FATAL_ERROR "FATAL ERROR: missing library") endif() 
+7
source

All Articles