尝试在macOS上编译ASIFT算法的C++源代码时,我遇到了OpenMP库的问题。
编译器是Apple Clang,macOS版本为11.3。
首先,编译器告诉我找不到“omp.h”。我参考了this question并通过HomeBrew安装了
这解决了之前的“未找到omp.h”错误。
但是,在执行
我还在Xcode中编写了一个更简单的代码,只是为了测试。
代码无法正确编译。
似乎编译器找不到在omp.h中声明的函数
以下是
我不确定是编译器参数问题还是OpenMP没有正确安装。我已经确认
编译器是Apple Clang,macOS版本为11.3。
首先,编译器告诉我找不到“omp.h”。我参考了this question并通过HomeBrew安装了
libomp
。在正确安装后,我更改了源文件中的以下代码:#include "omp.h"
to:
#include "/usr/local/opt/libomp/include/omp.h"
这解决了之前的“未找到omp.h”错误。
但是,在执行
make
命令后,项目源代码仍无法正确编译。Clang会抛出链接器错误。终端输出如下:Undefined symbols for architecture x86_64:
"_omp_get_num_procs", referenced from:
compute_asift_matches(int, int, int, int, int, int, int, std::__1::vector<std::__1::vector<std::__1::vector<keypoint, std::__1::allocator<keypoint> >, std::__1::allocator<std::__1::vector<keypoint, std::__1::allocator<keypoint> > > >, std::__1::allocator<std::__1::vector<std::__1::vector<keypoint, std::__1::allocator<keypoint> >, std::__1::allocator<std::__1::vector<keypoint, std::__1::allocator<keypoint> > > > > >&, std::__1::vector<std::__1::vector<std::__1::vector<keypoint, std::__1::allocator<keypoint> >, std::__1::allocator<std::__1::vector<keypoint, std::__1::allocator<keypoint> > > >, std::__1::allocator<std::__1::vector<std::__1::vector<keypoint, std::__1::allocator<keypoint> >, std::__1::allocator<std::__1::vector<keypoint, std::__1::allocator<keypoint> > > > > >&, std::__1::vector<std::__1::pair<keypoint, keypoint>, std::__1::allocator<std::__1::pair<keypoint, keypoint> > >&, siftPar&) in compute_asift_matches.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [demo_ASIFT] Error 1
我还在Xcode中编写了一个更简单的代码,只是为了测试。
#include "/usr/local/opt/libomp/include/omp.h"
#include <iostream>
int main()
{
int num = omp_get_num_procs();
std::cout<<num<<std::endl;
}
代码无法正确编译。
似乎编译器找不到在omp.h中声明的函数
omp_get_num_procs()
的实现。以下是
omp_get_num_procs()
在omp.h中的声明(第69行):extern int __KAI_KMPC_CONVENTION omp_get_num_procs (void);
我不确定是编译器参数问题还是OpenMP没有正确安装。我已经确认
libomp.a
和libomp.dylib
已正确放置在/usr/local/opt/libomp/lib
目录中。
请问有人能够提供一些关于这个问题的建议吗?谢谢。