我试图在构建时将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发布于 2020-08-08 20:42:53
对于子孙后代来说,这仍然是谷歌最早的链接之一。
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})发布于 2017-09-22 15:47:14
过程()命令是您的朋友。使用它运行jemalloc-config可执行文件,然后将其输出放入CMake变量中。
发布于 2022-01-23 08:13:29
/Users/lion/homebrew/Cellar/jemalloc/5.2.1_1/lib/ (我通过brew在macOS上安装了jemalloc )ln -s /Users/lion/homebrew/Cellar/jemalloc/5.2.1_1/lib/* /usr/local/lib那就成功了!
https://stackoverflow.com/questions/46366435
复制相似问题