问题
This is probably a really basic question but I haven't been able to find a solution anywhere. I'm building a Python extension in C++ using Boost.Python and need to link my project with libpcap, but nothing I specify seems to point bjam to the correct location. Pcap is currently installed to /usr/local/include (OS X 10.9) and I can import it with XCode, Make, or any other build system. However when I try to run bjam it gives me the linker error "Undefined symbols for architecture x86_64."
I got past the first round of linker errors by adding the other source files to the python-extension definition but obviously can't do the same for an external library. Here's my bjam file (copied from their example and slightly modified):
import python ;
if ! [ python.configured ]
{
ECHO "notice: no Python configured in user-config.jam" ;
ECHO "notice: will use default configuration" ;
using python ;
}
use-project boost : ../../../Downloads/boost_1_55_0 ;
# Set up the project-wide requirements that everything uses the
# boost_python library from the project whose global ID is
# /boost/python.
project
: requirements
<library>/boost/python//boost_python
<implicit-dependency>/boost//headers
: usage-requirements <implicit-dependency>/boost//headers
;
python-extension pcap_ext : PacketWarrior/pcap_ext.cc PacketWarrior/PacketEngine.h PacketWarrior/PacketEngine.cc PacketWarrior/Packet.h ;
# Put the extension and Boost.Python DLL in the current directory, so
# that running script by hand works.
install convenient_copy
: pcap_ext
: <install-dependencies>on <install-type>SHARED_LIB <install-type>PYTHON_EXTENSION
<location>.
;
# A little "rule" (function) to clean up the syntax of declaring tests
# of these extension modules.
local rule run-test ( test-name : sources + )
{
import testing ;
testing.make-test run-pyd : $(sources) : : $(test-name) ;
}
# Declare test targets
run-test pcap : pcap_ext pcap.py ;
I'm sure it's just adding something to the project requirements, but the syntax eludes me and none of the variations of <libary>
I could find from [0] seemed to work. I tried looking for equivalents of passing the llibpcap flag to GCC but to no avail. Any guidance is greatly appreciated!
[0] - https://wiki.python.org/moin/boost.python/BuildingExtensions
回答1:
Figured it out. I was trying to link to the header paths when it needed the dynamic library. I added this to the requirements rule and bjam was able to compile it correctly.
<library>/usr/lib/libpcap.dylib
来源:https://stackoverflow.com/questions/20322027/including-system-libraries-with-bjam-for-boost-python