【发布时间】:2015-05-19 23:20:28
【问题描述】:
我目前正在尝试使用 CMake 编译一个 c++ 文件。 但由于我使用的是 Boost::python 它不会编译。 我设置了一个小测试文件来弄清楚我需要做什么,但我就是无法让它工作。 任何帮助将不胜感激!
测试文件:
#include <Python.h>
#include <boost/python.hpp>
#include <iostream>
using std::cout;
using std::endl;
int main()
{
namespace py = boost::python;
Py_Initialize();
// Retrieve the main module's namespace
py::object global(py::import("__main__").attr("__dict__"));
py::exec("print 'Hello from Python!' \n", global, global);
return 0;
}
如果我只是使用它会编译,
clang++ -I/usr/include/python2.7 -lpython2.7 -lboost_python -std=c++11 boosttest.cpp -o boosttest
我试过这个 CMakeLists.txt 让它工作。
cmake_minimum_required(VERSION 3.2)
FIND_PACKAGE(PythonLibs)
FIND_PACKAGE(Boost)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS})
LINK_LIBRARIES(${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
add_executable(Test1 boosttest.cpp)
target_link_libraries(Test1 ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
我得到的是
undefined reference to `boost::python::import(boost::python::str)'
还有几个相同的类别。
【问题讨论】: