Как команда `make` ссылается на Python lib? - PullRequest
0 голосов
/ 05 октября 2018

Файл проекта C ++, xxx.cpp, вызвал функцию python следующим образом:

  if(FindLoggingBehavior){

    // Initialize python module
    Py_Initialize();
    if(!Py_IsInitialized()){
        return 0;
    }
    PyRun_SimpleString("import sys");
    PyRun_SimpleString("sys.path.append('/Users/abc/source/script/segment/')");
    pName = PyString_FromString("segment");
    pModule = PyImport_Import(pName);
    if(!pModule){
        printf("can't find segment.py");
        return 0;
    }
    pDict = PyModule_GetDict(pModule);
    if(!pDict){
        printf("can't find dict");
        return 0;
    }
    pFunc = PyDict_GetItemString(pDict, "segment");
    if(!pFunc || !PyCallable_Check(pFunc)){
        printf("can't find function [segment]");
        return 0;
    }

Когда я запускаю make для компиляции проекта, произошли следующие ошибки:

[ 86%] Linking CXX executable ../../../../bin/clang-smartlog
CMakeFiles/clang-smartlog.dir/src/SmartLog.cpp.o: In function `main':
SmartLog.cpp:(.text.startup.main+0x250): undefined reference to `Py_Initialize'
SmartLog.cpp:(.text.startup.main+0x255): undefined reference to 
`Py_IsInitialized'
SmartLog.cpp:(.text.startup.main+0x121c): undefined reference to 
`PyRun_SimpleStringFlags'
 SmartLog.cpp:(.text.startup.main+0x122a): undefined reference to 
`PyRun_SimpleStringFlags'
SmartLog.cpp:(.text.startup.main+0x1236): undefined reference to 
`PyString_FromString'
SmartLog.cpp:(.text.startup.main+0x1248): undefined reference to 
`PyImport_Import'
SmartLog.cpp:(.text.startup.main+0x1263): undefined reference to 
`PyModule_GetDict'
SmartLog.cpp:(.text.startup.main+0x1285): undefined reference to 
`PyDict_GetItemString'
SmartLog.cpp:(.text.startup.main+0x12a0): undefined reference to 
`PyCallable_Check'
SmartLog.cpp:(.text.startup.main+0x35f5): undefined reference to 
`Py_Finalize'
CMakeFiles/clang-smartlog.dir/src/FindLoggingBehavior.cpp.o: In function 
`FindLoggingVisitor::spiltWord(std::__cxx11::basic_string<char, 
std::char_traits<char>, std::allocator<char> >)':
FindLoggingBehavior.cpp: 

 (.text._ZN18FindLoggingVisitor9spiltWordENSt7__cxx1112basic_stringIcSt11char_tra 
itsIcESaIcEEE+0x8c): undefined reference to `PyObject_CallFunction'
FindLoggingBehavior.cpp: 
  (.text._ZN18FindLoggingVisitor9spiltWordENSt7__cxx1112basic_stringIcSt11char_tra 
itsIcESaIcEEE+0xdc): undefined reference to `PyList_GetItem'
FindLoggingBehavior.cpp: 
 (.text._ZN18FindLoggingVisitor9spiltWordENSt7__cxx1112basic_stringIcSt11char_tra 
itsIcESaIcEEE+0x101): undefined reference to `PyString_AsString'
collect2: error: ld returned 1 exit status
tools/clang/tools/SmartLog/CMakeFiles/clang-smartlog.dir/build.make:445: recipe 
for target 'bin/clang-smartlog' failed
make[2]: *** [bin/clang-smartlog] Error 1
CMakeFiles/Makefile2:26568: recipe for target 
'tools/clang/tools/SmartLog/CMakeFiles/clang-smartlog.dir/all' failed
make[1]: *** [tools/clang/tools/SmartLog/CMakeFiles/clang-smartlog.dir/all] 
Error 2
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2

Как make может ссылаться на Python lib?

1 Ответ

0 голосов
/ 06 октября 2018

решаемая.Я добавляю LINK_LIBRARIES(".../libpython2.7.so") в CMakeLists.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...