从python调用openMP共享库时,未定义opnMP函数
Undefined opnMP function when calling a openMP shared library from python
我想用openMP编写一个小的c++代码,将其编译为.so,并使用从python调用它。c++源是-
from ctypes import *
import ctypes
c_lib = cdll.LoadLibrary("libtest.so")
c_lib.openmp_test()
cpp文件如下-
#include<iostream>
#include<omp.h>
void openmp_test()
{
std::cout<<"in c++";
int threads = omp_get_max_threads();
std::cout<<threads;
}
我使用-创建.so文件
g++ -c -fPIC -fopenmp test.cpp -o test.o
g++ test.o -shared -o libtest.so
然而,运行python文件会出现错误-
undefined symbol: omp_get_max_threads
我做错了什么?提前感谢
您应该将库omp添加到程序的库依赖项中。
g++ test.o -shared -lomp -o libtest.so
我为您提供完整的解决方案:
#include<iostream>
#include<omp.h>
extern "C"
{
void openmp_test()
{
std::cout<<"in c++";
int threads = omp_get_max_threads();
std::cout<<threads;
}
}
之后你应该与共享库
g++ -c -fPIC -fopenmp test.cpp -o test.o
g++ test.o -shared -lomp -o libtest.so
然后运行您的python脚本,当然您应该提供库的完整路径。
相关文章:
- 编译C++时未定义的引用
- vscode g++链路故障:体系结构x86_64的未定义符号
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 不知道某个东西是否被忽略会引入未定义的行为吗
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 未定义的引用在哪里
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- c++11评估顺序(未定义的行为)
- 使用mysql c++连接器的未定义引用
- 从python调用openMP共享库时,未定义opnMP函数
- 在 Mac 上使用 CMAKE 将 FFTW 和 FFTWPP 链接到项目中时未定义的符号
- Cmake 链接问题:未定义对 Button::mousePressEvent(QGraphicsSceneMouseE
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 具有外部"c"和程序集的未定义函数
- 此增量后语句是否会导致未定义的行为?
- 尝试调用 .h 文件中定义的变量时出现变量未定义错误
- 在C++中使用内联方法时出现未定义的符号错误
- 对 Scalar ::Scalar() 的未定义引用