问题
I've been trying to compile the Boost.Python 'quickstart' ($BOOST_PATH\libs\python\examples\quickstart) examples and have run into an issue.
First, my environment:
- OS: Windows 7 Ultimate 64 bit
- Python version: 2.7 32 bit
- C++ Compiler: VC10
- Boost version: 1.53.0
Initially, I had issues compiling the Boost.Python library files but happened upon this Stack Overflow thread which solved my issue by explaining how to set include directories in VS2010 and point the boost compile to my python directory. I then went to compile the Boost.Python quickstart examples using the command:
bjam toolset=msvc --verbose-test test
The first couple of times I attempted this I hit an unresolved external symbol error telling me it couldn't find the boost python libary even though it should have been the in the library directory I set per my first link. Now it's giving me the following output:
error: No best alternative for /python_for_extensions
next alternative: required properties: <python>2.7 <target-os>windows
matched
next alternative: required properties: <python>2.7 <target-os>windows
matched
error: No best alternative for /python_for_extensions
next alternative: required properties: <python>2.7 <target-os>windows
matched
next alternative: required properties: <python>2.7 <target-os>windows
matched
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\property.jam:649: in find-replace from module object(property-map)@1
error: Ambiguous key <target-type>PYTHON_EXTENSION <abi>ms <asynch-exceptions>off <binary-format>pe <debug-store>object <debug-symbols>on <embed-manifest>on <exception-handling>on <extern-c-nothrow>off <hardcode-dll-paths>true <host-os>windows <include>../../../.. <inlining>off <install-dependencies>off <library>object(file-target)@1112 <library>object(file-target)@1114 <library>object(file-target)@1116 <link>shared <main-target-type>PYTHON_EXTENSION <midl-robust>yes <midl-stubless-proxy>yes <optimization>off <os>NT <pch>on <preserve-test-targets>on <profiling>off <python-debugging>off <python.interpreter>C:\Python27\python <python>2.7 <rtti>on <runtime-debugging>on <runtime-link>shared <stdlib>native <strip>off <suppress-import-lib>true <symlink-location>project-relative <target-os>windows <target>object(file-target)@1132 <threadapi>win32 <threading>multi <toolset-msvc:version>10.0 <toolset>msvc <user-interface>console <variant>debug <warnings-as-errors>off <warnings>on <xdll-path>/C:/Program Files (x86)/boost/boost_1_53_0/bin.v2/libs/python/build/msvc-10.0/debug/threading-multi
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\property.jam:626: in object(property-map)@1.find from module object(property-map)@1
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\type.jam:335: in generated-target-ps-real from module type
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\type.jam:360: in generated-target-ps from module type
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\type.jam:270: in type.generated-target-suffix from module type
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\virtual-target.jam:511: in virtual-target.add-prefix-and-suffix from module virtual-target
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\virtual-target.jam:470: in _adjust-name from module object(file-target)@1132
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\virtual-target.jam:253: in abstract-file-target.__init__ from module object(file-target)@1132
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\virtual-target.jam:564: in object(file-target)@1132.__init__ from module object(file-target)@1132
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/kernel\class.jam:88: in class.new from module class
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\generators.jam:565: in generator.generated-targets from module object(msvc-linking-generator)@1127
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/tools\builtin.jam:869: in linking-generator.generated-targets from module object(msvc-linking-generator)@1127
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/tools\msvc.jam:1061: in generated-targets from module object(msvc-linking-generator)@1127
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\generators.jam:463: in construct-result from module object(msvc-linking-generator)@1127
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\generators.jam:416: in run-really from module object(msvc-linking-generator)@1127
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\generators.jam:390: in generator.run from module object(msvc-linking-generator)@1127
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/tools\builtin.jam:784: in object(msvc-linking-generator)@1127.run from module object(msvc-linking-generator)@1127
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\generators.jam:978: in try-one-generator-really from module generators
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\generators.jam:1040: in try-one-generator from module generators
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\generators.jam:1254: in construct-really from module generators
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\generators.jam:1338: in generators.construct from module generators
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\targets.jam:1495: in construct from module object(typed-target)@71
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\targets.jam:1298: in object(typed-target)@71.generate from module object(typed-target)@71
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\targets.jam:732: in generate-really from module object(main-target)@932
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\targets.jam:704: in object(main-target)@932.generate from module object(main-target)@932
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\targets.jam:848: in targets.generate-from-reference from module targets
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\targets.jam:1217: in generate-dependencies from module object(typed-target)@77
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\targets.jam:1269: in object(typed-target)@77.generate from module object(typed-target)@77
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\targets.jam:732: in generate-really from module object(main-target)@934
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\targets.jam:704: in object(main-target)@934.generate from module object(main-target)@934
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\targets.jam:848: in targets.generate-from-reference from module targets
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\targets.jam:1217: in generate-dependencies from module object(alias-target-class)@81
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\targets.jam:1269: in object(alias-target-class)@81.generate from module object(alias-target-class)@81
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\targets.jam:732: in generate-really from module object(main-target)@936
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2/build\targets.jam:704: in object(main-target)@936.generate from module object(main-target)@936
C:/Program Files (x86)/boost/boost_1_53_0/tools/build/v2\build-system.jam:736: in load from module build-system
C:\Program Files (x86)\boost\boost_1_53_0\libs\python\example\quickstart\..\..\..\..\tools\build\v2/kernel\modules.jam:283: in import from module modules
C:\Program Files (x86)\boost\boost_1_53_0\libs\python\example\quickstart\..\..\..\..\tools\build\v2/kernel/bootstrap.jam:142: in boost-build from module
C:\Program Files (x86)\boost\boost_1_53_0\libs\python\example\quickstart\boost-build.jam:7: in module scope from module
EDIT 1:
Turns out the error message I posted above occurs when you define your python directory in more than one of the *-config.jam files. Now I get the original error message:
...patience...
...patience...
...found 1745 targets...
...updating 10 targets...
compile-c-c++ bin\msvc-10.0\debug\threading-multi\extending.obj
extending.cpp
msvc.link.dll bin\msvc-10.0\debug\threading-multi\extending.pyd
Creating library bin\msvc-10.0\debug\threading-multi\extending.lib and object bin\msvc-10.0\debug\threading-multi\extending.exp
msvc.manifest.dll bin\msvc-10.0\debug\threading-multi\extending.pyd
capture-output bin\test_ext.test\msvc-10.0\debug\threading-multi\test_ext
1 file(s) copied.
====== BEGIN OUTPUT ======
Trying:
from extending import *
Expecting nothing
ok
Trying:
hi = hello('California')
Expecting nothing
ok
Trying:
hi.greet()
Expecting:
'Hello from California'
ok
Trying:
invite(hi)
Expecting:
'Hello from California! Please come soon!'
ok
Trying:
hi.invite()
Expecting:
'Hello from California! Please come soon!'
ok
Trying:
class wordy(hello):
def greet(self):
return hello.greet(self) + ', where the weather is fine'
Expecting nothing
ok
Trying:
hi2 = wordy('Florida')
Expecting nothing
ok
Trying:
hi2.greet()
Expecting:
'Hello from Florida, where the weather is fine'
ok
Trying:
invite(hi2)
Expecting:
'Hello from Florida! Please come soon!'
ok
1 items had no tests:
test_extending.run
1 items passed all tests:
9 tests in test_extending
9 tests in 2 items.
9 passed and 0 failed.
Test passed.
EXIT STATUS: 0
====== END OUTPUT ======
**passed** bin\test_ext.test\msvc-10.0\debug\threading-multi\test_ext.test
msvc.link bin\test_embed.test\msvc-10.0\debug\threading-multi\test_embed.exe
LINK : warning LNK4001: no object files specified; libraries used
LINK : error LNK2001: unresolved external symbol _mainCRTStartup
bin\test_embed.test\msvc-10.0\debug\threading-multi\test_embed.exe : fatal error LNK1120: 1 unresolved externals
call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 >nul
link /NOLOGO /INCREMENTAL:NO /DEBUG /MACHINE:X86 /subsystem:console /out:"bin\test_embed.test\msvc-10.0\debug\threading-multi\test_embed.exe" /LIBPATH:"C:\Python27\libs" @"bin\test_embed.test\msvc-10.0\debug\threading-multi\test_embed.exe.rsp"
if %ERRORLEVEL% NEQ 0 EXIT %ERRORLEVEL%
...failed msvc.link bin\test_embed.test\msvc-10.0\debug\threading-multi\test_embed.exe bin\test_embed.test\msvc-10.0\debug\threading-multi\test_embed.pdb...
...removing bin\test_embed.test\msvc-10.0\debug\threading-multi\test_embed.pdb
...skipped <pbin\test_embed.test\msvc-10.0\debug\threading-multi>test_embed.run for lack of <pbin\test_embed.test\msvc-10.0\debug\threading-multi>test_embed.exe...
...failed updating 2 targets...
...skipped 2 targets...
...updated 6 targets...
回答1:
I'm not sure what the problem is with a). Problem b) appears to be a bug in the boost example, the jam file is trying to make a test executable from an executable instead of a static lib or cpp file.
I documented what I had to do to get the embed example running.
来源:https://stackoverflow.com/questions/15592485/error-compiling-boost-python-quickstart