我已经用brew install tbb安装了tbb库。但是当我尝试用以下命令编译程序时:
g++-10 hello.cpp -o hello --std=c++2a -Wall -ltbb -lpthread -O3我得到了一个错误:
ld: library not found for -ltbb
collect2: error: ld returned 1 exit status所有其他标志都工作正常。
如果我使用-tbb而不是ltbb,我会得到
g++-10: error: unrecognized command-line option '-tbb'我该怎么做呢?
发布于 2021-06-18 06:42:43
发生此错误的原因是链接器在您的Mac上找不到libtbb.dylib。它找不到它,因为Homebrew将TBB库安装在非标准文件夹中(默认情况下,该文件夹不在ld用来搜索.dylib的DYLD_LIBRARY_PATH环境变量中)。
我遇到了同样的问题,发现libtbb.dylib (以及与brew一起安装的所有其他库的符号链接)都在/opt/homebrew/lib中。因此,您可以在运行g++命令之前执行类似export DYLD_LIBRARY_PATH=/opt/homebrew/lib:${DYLD_LIBRARY_PATH}的操作,或者如果您使用的是像CMake这样的构建系统,则可以在CMakeLists.txt中添加类似link_directories("/opt/homebrew/lib")的命令)。
https://stackoverflow.com/questions/64159068
复制相似问题