编译Boost.Python快速入门时出错

时间:2013-03-23 21:50:42

标签: python visual-studio-2010 boost boost-python bjam

我一直在尝试编译Boost.Python'startstart'($ BOOST_PATH \ libs \ python \ examples \ quickstart)示例,并遇到了一个问题。

首先,我的环境:

  • 操作系统:Windows 7旗舰版64位
  • Python版本:2.7 32位
  • C ++编译器:VC10
  • Boost版本:1.53.0

最初,我遇到了编译Boost.Python库文件的问题,但发生在this Stack Overflow线程上,它通过解释如何在VS2010中设置包含目录并将boost编译指向我的python目录来解决我的问题。然后我使用命令编译Boost.Python快速入门示例:

bjam toolset=msvc --verbose-test test

我尝试过的前两次我遇到了一个未解决的外部符号错误,告诉我它找不到boost python库,即使它应该是我在第一个链接中设置的库目录中。现在它给了我以下输出:

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

编辑1:

当您在多个* -config.jam文件中定义python目录时,会发生上面发布的错误消息。现在我收到原始错误消息:

...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 个答案:

答案 0 :(得分:1)

我不确定a)的问题是什么。问题b)似乎是boost示例中的一个错误,jam文件试图从可执行文件而不是静态lib或cpp文件生成测试可执行文件。

documented what I had to do让embed示例运行。