EDIT ===================
apr-1 是 apache 可移植运行时,我自己下载并编译它来创建共享库(所以它不是由 cmake 制作的)。在目标系统上运行 CPack 后,我需要链接到这个库。
我的开发项目目录:
read_config/bin
/libs
/include
/src
/build
对于我的 CMakeLists.txt,一切安装正常,但现在我遇到了链接问题,因为它找不到库的新位置。
我已经删除了,LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/libs)
因为我现在不需要这个,因为我正在使用FIND_LIBRARY
.
并添加了以下内容:
# Find the library in the libs folder
FIND_LIBRARY(APR_LIBS NAMES "apr-1" PATHS ${PROJECT_SOURCE_DIR}/libs)
# Print out the path to see if its correct
MESSAGE(${APR_LIBS})
# Link the library with the executable
TARGET_LINK_LIBRARIES(cfg ${APR_LIBS})
# Install the libs folder
INSTALL(DIRECTORY ${PROJECT_SOURCE_DIR}/libs/
DESTINATION libs)
# Install the executable in the bin folder
INSTALL(TARGETS cfg
RUNTIME DESTINATION bin)
一切都安装好了,但是当我检查可执行文件以查看它链接到的库时找不到它,apr-1
因为它看起来在错误的位置。
libapr-1.so.0 => not found
这是因为我已将安装包解压缩到与编译位置不同的新位置。从编译的目录中我得到了这个,它运行正常:
libapr-1.so.0 => /home/devel/projects/read_config/libs/libapr-1.so.0 (0xf7746000)
我安装后我在目标安装机器上有这个目录结构,所以可执行文件将链接到新libs/apr-1
库:
target directory/
/bin
/libs/apr-1
非常感谢您提供任何进一步的建议,
========================================
gcc (GCC) 4.7.2 cmake 版本 2.8.9 Fedora 17
你好,
我收到以下错误:
CMake Error at src/CMakeLists.txt:14 (INSTALL):
install TARGETS given target "apr-1" which does not exist in this
directory.
我有以下目录:
read_config/
/build - out of source build
/CMakeLists.txt
/include - apr include files
/libs - apr libraries
/src - project source files *.h *.c CMakeLists.txt
在我的根 CMakeLists.txt 中,我有以下内容:
# Name of project and compiler to use
PROJECT(read_cfg C)
# Set compiler flags
IF(CMAKE_COMPILER_IS_GNUCC)
MESSAGE(STATUS "COMPILER IS GNUCC")
SET(CMAKE_C_FLAGS "-Wall -Wextra -m32 -Wunreachable-code -ggdb -O0 -D_DEBUG -D_LARGEFILE64_SOURCE")
ENDIF(CMAKE_COMPILER_IS_GNUCC)
# Where the include files can be found
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/read_config/include)
# Where the libraries can be found
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/read_config/libs)
ADD_SUBDIRECTORY(src)
在我的 src 目录中,我有以下 CMakeLists.txt
# Create the executable and link the libraries into it
ADD_EXECUTABLE(cfg test_config.c)
# Place executable in bin directory
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)
# Add libraries
IF(CMAKE_COMPILER_IS_GNUCC)
MESSAGE(STATUS "Linking cfg library")
TARGET_LINK_LIBRARIES(cfg apr-1)
ENDIF(CMAKE_COMPILER_IS_GNUCC)
INSTALL(TARGETS cfg
RUNTIME
DESTINATION bin)
INSTALL(TARGETS apr-1
ARCHIVE
DESTINATION lib)
SET(CPACK_PACKAGE_NAME "rd_cfg")
SET(CPACK_PACKAGE_VENDOR "sun.com")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "rd_cfg - CPack read_config installation")
SET(CPACK_PACKAGE_VERSION "1.0.0")
SET(CPACK_PACKAGE_VERSION_MAJOR "1")
SET(CPACK_PACKAGE_VERSION_MINOR "0")
SET(CPACK_PACKAGE_VERSION_PATCH "0")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "Read_config_install_dir")
INCLUDE(CPack)
问题是这里的这一行:
INSTALL(TARGETS apr-1
ARCHIVE
DESTINATION lib)
我尝试过以下操作
INSTALL(TARGETS ${CMAKE_SOURCE_DIR}/libs/apr-1
ARCHIVE
DESTINATION lib)
但它仍然无法找到图书馆。
并且还使用这样的路径:
INSTALL(TARGETS src/libs
ARCHIVE
DESTINATION lib)
我希望能够像这样将目录放在那里,这样我就不必指定每个库,而只需像这样的目录:
INSTALL(TARGETS ${CMAKE_SOURCE_DIR}/libs
ARCHIVE
DESTINATION lib)
因此它可以找到该目录中的所有库。我有大约5个。
非常感谢您的任何建议,