无法在 C++ 项目中使用 openmp

Can't use openmp in c++ project

本文关键字:openmp 项目 C++      更新时间:2023-10-16

我已经将openmp包含到我的项目中。在编译器标志中有-fopenmp

g++ -std=c++0x -O3 -Wall -c -fmessage-length=0 -march=core2 -fopenmp - fast-math -fPIC

#pragma omp parallel for
for (int i = 0; i < rows; i++) {
    MatrixXd frame = frames.row(i);
    output.row(i) = dem(frame);
}
return output;

当我编译时,我有这样的输出:

hello.cpp:(.text+0x2d88): undefined reference to `omp_get_num_threads'
hello.cpp:(.text+0x2d8f): undefined reference to `omp_get_thread_num'
./hello.o: In function `demodulateMatrix':
hello.cpp:(.text+0x315f): undefined reference to `GOMP_parallel_start'
hello.cpp:(.text+0x316c): undefined reference to `GOMP_parallel_end'

我已经尝试添加-fopenmp标志到链接器,我有这个输出与它

g++: error: unrecognized command line option ‘-fopenmp,’
make: *** [libhello.so] Error 1

您还需要将-fopenmp传递给链接器。看起来您试图这样做,但是您有一个语法错误,导致链接器看到-fopenmp,(末尾有一个散乱的逗号)。检查makefile.

(您似乎将hello.cpp传递给链接器而不是hello.o,因此您的代码编译两次。)