I have the following problem. I have a separate {bin,lib,include} tree on my Linux machine where CMake and all my libraries I need for my development work are installed. But only the PATH environment variable is set to this bin directory and for several reason I can not set the LD_LIBRARY_PATH. All programs inside this tree are build using RPATHs. The CMake 3.3.1 I am using is also inside this tree.
Now the problem I want to compile a program using libcurl and set up the following CMakeLists.txt
PROJECT(EXAMPLE)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
FIND_PACKAGE(CURL REQUIRED)
FIND_PACKAGE(OpenSSL REQUIRED)
INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR})
SET(LIBS ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES})
ADD_EXECUTABLE(curl_ex src/curl_ex.c)
TARGET_LINK_LIBRARIES(curl_ex ${LIBS})
When I now run CMake the curl and the OpenSSL setup out of my personal software tree is found due to the fact that it resides inside the same prefix as CMake.
But when I build the project using make VERBOSE=1
I see the following linking command:
gcc CMakeFiles/curl_ex.dir/src/curl_ex.c.o -o curl_ex -rdynamic -lcurl -lssl -lcrypto
and the build executable refers to the system-wide installed curl and openssl libraries instead of the one cmake found during the configuration.
How can I force CMake to use the libraries it found when it performs the linking?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…