我试图在构建时将 jemalloc 库链接到我的应用程序中,将其用作通用实现。根据https://github.com/jemalloc/jemalloc/wiki/Getting-Started要使用的链接标志是:
-L`jemalloc-config --libdir` -Wl,-rpath,`jemalloc-config --libdir` -ljemalloc `jemalloc-config --libs`
所以我做了以下 CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.12.2)
project(widget)
include_directories(include)
file(GLOB SOURCES "src/*.cpp")
add_executable(widget ${SOURCES})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L`jemalloc-config --libdir` -Wl,-rpath,`jemalloc-config --libdir` -ljemalloc `jemalloc-config --libs`")
但是当我执行 make
时,我得到以下错误:
Linking CXX executable widget
c++: error: `jemalloc-config: No such file or directory
c++: error: unrecognized command line option ‘--libdir`’
c++: error: unrecognized command line option ‘--libdir`’
c++: error: unrecognized command line option ‘--libs`’
make[2]: *** [widget] Error 1
make[1]: *** [CMakeFiles/widget.dir/all] Error 2
最佳答案
对于子孙后代,因为这仍然是 Google 上最早出现的链接之一。
Jemalloc 自带 pkg-config 设置,可以这样使用:
find_package(PkgConfig REQUIRED)
pkg_check_modules (JEMALLOC jemalloc)
pkg_search_module(JEMALLOC REQUIRED jemalloc)
include_directories(${JEMALLOC_INCLUDE_DIRS})
target_link_libraries(your_target_name ${JEMALLOC_LIBRARIES})
关于makefile - 如何使用 cmake 链接 jemalloc 共享库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46366435/