增强 python 链接
我正在为我的游戏添加 boost.python 。我为我的类编写包装器以在脚本中使用它们。问题在于将该库链接到我的应用程序。我正在使用 cmake
构建系统。
现在我有一个简单的应用程序,其中包含 1 个文件和 makefile:
PYTHON = /usr/include/python2.7
BOOST_INC = /usr/include
BOOST_LIB = /usr/lib
TARGET = main
$(TARGET).so: $(TARGET).o
g++ -shared -Wl,--export-dynamic \
$(TARGET).o -L$(BOOST_LIB) -lboost_python \
-L/usr/lib/python2.7/config -lpython2.7 \
-o $(TARGET).so
$(TARGET).o: $(TARGET).cpp
g++ -I$(PYTHON) -I$(BOOST_INC) -c -fPIC $(TARGET).cpp
这可以工作。它为我构建了一个“so”文件,我可以从 python 导入该文件。
现在的问题是:如何为 cmake 获取这个?
我在主CMakeList.txt
中写道:
...
find_package(Boost COMPONENTS filesystem system date_time python REQUIRED)
message("Include dirs of boost: " ${Boost_INCLUDE_DIRS} )
message("Libs of boost: " ${Boost_LIBRARIES} )
include_directories(
${Boost_INCLUDE_DIRS}
...
)
target_link_libraries(Themisto
${Boost_LIBRARIES}
...
)
...
message
调用显示:
Include dirs of boost: /usr/include
Libs of boost: /usr/lib/libboost_filesystem-mt.a/usr/lib/libboost_system-mt.a/usr/lib/libboost_date_time-mt.a/usr/lib/libboost_python-mt.a
好的,所以我为我的项目添加了简单的.cpp文件,其中包含
。我在编译时遇到错误:
/usr/include/boost/python/detail/wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or directory
所以它不需要所有需要的包含目录。
还有第二问题:
如何组织 script-cpp 文件的两步构建?在makefile中我显示有TARGET.o和TARGET.so,如何在cmake中处理这2个命令?
据我了解,最好的方法是创建子项目并在那里做一些事情。
谢谢。
I'm adding boost.python for my Game. I write wrappers for my classes to use them in scripts. The problem is linking that library to my app. I'm using cmake
build system.
Now I have a simple app with 1 file and makefile for it:
PYTHON = /usr/include/python2.7
BOOST_INC = /usr/include
BOOST_LIB = /usr/lib
TARGET = main
$(TARGET).so: $(TARGET).o
g++ -shared -Wl,--export-dynamic \
$(TARGET).o -L$(BOOST_LIB) -lboost_python \
-L/usr/lib/python2.7/config -lpython2.7 \
-o $(TARGET).so
$(TARGET).o: $(TARGET).cpp
g++ -I$(PYTHON) -I$(BOOST_INC) -c -fPIC $(TARGET).cpp
And this works. It builds a 'so' file for me which I can import from python.
Now the question: how to get this for cmake?
I wrote in main CMakeList.txt
:
...
find_package(Boost COMPONENTS filesystem system date_time python REQUIRED)
message("Include dirs of boost: " ${Boost_INCLUDE_DIRS} )
message("Libs of boost: " ${Boost_LIBRARIES} )
include_directories(
${Boost_INCLUDE_DIRS}
...
)
target_link_libraries(Themisto
${Boost_LIBRARIES}
...
)
...
message
calls show:
Include dirs of boost: /usr/include
Libs of boost: /usr/lib/libboost_filesystem-mt.a/usr/lib/libboost_system-mt.a/usr/lib/libboost_date_time-mt.a/usr/lib/libboost_python-mt.a
Ok, so I've added simple .cpp-file for my project with include of <boost/python.hpp>
. I get an error at compiling:
/usr/include/boost/python/detail/wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or directory
So it doesn't take all need include directories.
And second question:
How to organize 2-step building of script-cpp files? In makefile I showed there are TARGET.o and TARGET.so, how to process that 2 commands in cmake?
As I understand, the best way is to create subproject and do something there.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 CMakeList.txt 中缺少 python 的包含目录和库。使用 PythonFindLibs 宏或与 Boost 相同的 find_package 策略
You are missing your include directory and libs for python in your CMakeList.txt. Use the PythonFindLibs macro or the same find_package strategy you used for Boost