[英]Linking program with Boost.Asio using waf build system
我正在嘗試在Debian擠壓python 2.6.6上使用waf構建最簡單的Boost.Asio教程示例“ timer1” (位於timer.cpp中)。
root @ ds:/ var / timer#ls
timer.cpp wscript
wscript這是waf的配置:
#! /usr/bin/env python
top = '.'
out = '.'
def options(opt):
opt.load('compiler_cxx')
def configure(conf):
conf.load('compiler_cxx')
conf.env['LINKFLAGS'] = '--verbose -L/usr/local/lib -lboost_system'
def build(bld):
tgen = bld.new_task_gen()
tgen.features = 'cxx cxxprogram'
tgen.source = 'timer.cpp'
tgen.target = 'timer'
tgen.includes = '.'
tgen.update_outputs = True
waf configure
成功。
但是waf --verbose build
完成時出錯(我在下面插入<*>
標記了一行)
Waf: Entering directory `/var/timer'
[1/2] cxx: timer.cpp -> timer.cpp.1.o
[2/2] cxxprogram: timer.cpp.1.o -> timer
timer.cpp.1.o: In function `__static_initialization_and_destruction_0(int, int)':
timer.cpp:(.text+0x103): undefined reference to `boost::system::generic_category()'
timer.cpp:(.text+0x10f): undefined reference to `boost::system::generic_category()'
...
Build failed
-> task in 'timer' failed (exit status 1):
{task 38446736: cxxprogram timer.cpp.1.o -> timer}
<*>
['/usr/bin/g++', '--verbose -L/usr/local/lib -lboost_system', 'timer.cpp.1.o', '-o', '/var/timer/timer', '-Wl,-Bstatic', '-Wl,-Bdynamic']
waf調用的gcc似乎在鏈接期間未找到boost_system庫。
但是,如果我不使用waf通過gcc構建示例,則一切正常。
root@ds:/var/timer# /usr/bin/g++ --verbose -I/var/flake/lib/boost timer.cpp -c -o timer.cpp.1.o
...
<**>
root@ds:/var/timer# /usr/bin/g++ --verbose -L/usr/local/lib -lboost_system timer.cpp.1.o -o timer -Wl,-Bstatic -Wl,-Bdynamic
...
root@ds:/var/timer# ls
timer.cpp timer.cpp.1.o timer wscript
如您所見,waf使用的命令行(用<*>
標記)與<**>
標記的命令行相同。 但是結果卻完全不同。 為什么? 我又該如何強迫waf建造那東西呢? 這里的解決方案對我也不起作用。 也嘗試過
...
opt.tool_options('boost')
...
conf.load('compiler_cxx boost')
conf.check_boost()
...
tgen.uselib = 'BOOST'
...
但沒有任何影響
還有一個問題。 gcc --verbose
輸出比waf --verbose
輸出要廣泛得多。 在我看來, verbose
選項必須迫使waf顯示所有此類信息。 為什么那不是真的? waf選項-vvv也不會顯示此信息。
如果使用增強工具,則應在Playground / boost中檢查waf增強示例,然后會看到check_boost帶有參數。 它將解決您的問題。
另外,如果您不使用該工具,而是使用在可訪問文件夾中設置了庫的真實操作系統,則可以執行以下操作:
conf.env.LIB_BOOST = ['boost_system']
...
bld(
...,
use='BOOST',
...,
)
未來腳本的注意事項:
原因是與Debian捆綁在一起的較舊的Boost 1.42二進制文件位於/ usr / lib中。 當我發現我試圖使/ usr / local / lib具有更高的優先級時(由b2構建的最新Boost二進制文件駐留在此處)。 但是我不能做很多事情,而只是完全卸載了Boost 1.42二進制文件,之后一切正常
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.