makefile - 如何使用 cmake 链接 jemalloc 共享库

标签 makefile compiler-errors cmake linker jemalloc

我试图在构建时将 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/

相关文章:

c++ - Cryptonote C++ 编译错误,操作数无效

c++ - OPENCV 错误 : undefined reference to "cvLoadImage"

gcc - 如果编译失败,则执行命令

compiler-errors - 在编译时发出警告?

opencv - 如何通过cmake中的变量$ {OpenCV_LIBS}链接opencv静态库

android - 添加日志时 CMakeLists.txt (target_link_libraries) 中的 CMake 错误

c++ - 如何针对自定义 CUDA 安装使用 OpenCL 构建 GDAL?

Makefile——只编译修改过的 C++ 文件

java - 您如何在Java中定义构造函数?

c++ - Travis CI 找不到头文件