包含 Python.h 但未建立 Py_initialze() 链接
尽管我在 CMake 中引用了 Python 库,但我遇到了 Py_initialize 的链接错误。找到了 Python.h,但未建立链接。
inpainting.cpp:(.text+0x47843): undefined reference to `Py_Initialize'
/usr/bin/ld: inpainting.cpp:(.text+0x47854): undefined reference to
`PyRun_SimpleStringFlags'
/usr/bin/ld: inpainting.cpp:(.text+0x47940): undefined reference to `Py_Finalize'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/imgCodecs.dir/build.make:552: imgCodecs] Error 1
make[1]: *** [CMakeFiles/Makefile2:84: CMakeFiles/imgCodecs.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
这是我的 CMakeList。 https://pastebin.com/QkihgBGm
编辑:添加我尝试编译的方式。我在我的 makefile 上执行 Cmake 和 make。
这是我正在尝试编译的 C++ 代码。
// *********** Begin: Run Python script ************************************************************
// Initialize the Python Interpreter
Py_Initialize();
PyRun_SimpleString("import sys");
char buff[FILENAME_MAX]; //create string buffer to hold path
getcwd( buff, FILENAME_MAX);
string current_working_dir(buff);
string shore_working_dir = current_working_dir +
"/shore_imputation/";
const char * shore_working_dir_c = shore_working_dir.c_str();
qDebug() << shore_working_dir_c;
// Finish the Python Interpreter
Py_Finalize();
// *********** End: Run Python script
**************************************************************
I am facing a linking error for Py_initialize though I have a reference to my Python library in my CMake. The Python.h is found but the link is not established.
inpainting.cpp:(.text+0x47843): undefined reference to `Py_Initialize'
/usr/bin/ld: inpainting.cpp:(.text+0x47854): undefined reference to
`PyRun_SimpleStringFlags'
/usr/bin/ld: inpainting.cpp:(.text+0x47940): undefined reference to `Py_Finalize'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/imgCodecs.dir/build.make:552: imgCodecs] Error 1
make[1]: *** [CMakeFiles/Makefile2:84: CMakeFiles/imgCodecs.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
Here is my CMakeList. https://pastebin.com/QkihgBGm
Edit: Adding how I am trying to compile. I do Cmake and a make on my makefile.
Here is the C++ code that I am trying to compile.
// *********** Begin: Run Python script ************************************************************
// Initialize the Python Interpreter
Py_Initialize();
PyRun_SimpleString("import sys");
char buff[FILENAME_MAX]; //create string buffer to hold path
getcwd( buff, FILENAME_MAX);
string current_working_dir(buff);
string shore_working_dir = current_working_dir +
"/shore_imputation/";
const char * shore_working_dir_c = shore_working_dir.c_str();
qDebug() << shore_working_dir_c;
// Finish the Python Interpreter
Py_Finalize();
// *********** End: Run Python script
**************************************************************
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过几个小时的调查,Cmake 似乎区分大小写,并且需要显式调用才能链接到库。
这使它工作并宾果游戏......干杯!
After many hours of investigation, it seems Cmake is case sensitive and it required an explicit call to link to the libraries.
This made it work and bingo... Cheers!