[英]Boost python linking
我正在為我的游戲添加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文件,其中包含<boost/python.hpp>
。 我在編譯時遇到錯誤:
/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個命令?
據我了解,最好的方法是創建子項目並在那里做一些事情。
謝謝。
你在CMakeList.txt中缺少你的include目錄和python的libs。 使用PythonFindLibs宏或用於Boost的相同find_package策略
find_package(Boost COMPONENTS filesystem system date_time python REQUIRED)
message("Include dirs of boost: " ${Boost_INCLUDE_DIRS} )
message("Libs of boost: " ${Boost_LIBRARIES} )
find_package(PythonLibs REQUIRED)
message("Include dirs of Python: " ${PYTHON_INCLUDE_DIRS} )
message("Libs of Python: " ${PYTHON_LIBRARIES} )
include_directories(
${Boost_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS} # <-------
...
)
target_link_libraries(Themisto
${Boost_LIBRARIES}
${PYTHON_LIBRARIES} # <------
...
)
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.