gpt4 book ai didi

c++ - 在 macOS 中使用 omp.h 的正确方法

转载 作者:行者123 更新时间:2023-12-04 07:49:02 26 4
gpt4 key购买 nike

在 macOS 上尝试从 C++ 源代码编译 ASIFT 算法时,我遇到了 OpenMP 库的问题。
编译器为 Apple Clang,macOS 版本为 11.3。
首先编译器告诉我找不到“omp.h”。我引用this question并安装 libomp通过 HomeBrew。正确安装后,我在源文件中更改以下代码:

#include "omp.h"
到:
#include "/usr/local/opt/libomp/include/omp.h"
这解决了之前的“omp.h not found”错误。
然而 ,执行 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_get_num_procs()的实现声明于 omp.h .
供引用,这里是 omp_get_num_procs()的声明在 omp.h (第 69 行):
extern int    __KAI_KMPC_CONVENTION  omp_get_num_procs    (void);
我不确定这是编译器参数问题还是未正确安装 OpenMP。我已经确认 libomp.alibomp.dylib正确放置在 /usr/local/opt/libomp/lib目录。
任何人都可以就这个问题提供一些建议吗?谢谢。

最佳答案

也许,您应该将 libomp.a 链接到一个项目。 Here示例如何将静态库链接到 Xcode C++ 项目。

关于c++ - 在 macOS 中使用 omp.h 的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67075832/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com