Boost C++ Libraries: Ticket #2615: boost 1.37.0 does not link against libpython https://svn.boost.org/trac10/ticket/2615 <p> libboost_python.so is calling python functions, but there is no direct linking to libpython, which will cause undefined references when building with LDFLAGS="-Wl,--no-undefined" </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2615 Trac 1.4.3 Marshall Clow Sat, 27 Dec 2008 20:51:57 GMT owner set https://svn.boost.org/trac10/ticket/2615#comment:1 https://svn.boost.org/trac10/ticket/2615#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Dave Abrahams</span> </li> </ul> Ticket Dave Abrahams Sat, 27 Dec 2008 23:22:33 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2615#comment:2 https://svn.boost.org/trac10/ticket/2615#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> I don't believe this can be considered a bug. Indeed, when Boost.Python is used for extending Python, it is important that libboost_python.so <em>not</em> be linked against libpython, since that will cause duplicate symbol errors. Python itself already contains all the symbols. Unless you can convince me that we should build otherwise-identical separate versions of libboost_python for extending and embedding (seems crazy to me), my answer is "don't use --no-undefined." If you have a good counterargment, please feel free to reopen this ticket. </p> Ticket Jürgen Hunold Mon, 29 Dec 2008 19:41:13 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/2615#comment:3 https://svn.boost.org/trac10/ticket/2615#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">invalid</span> </li> </ul> <p> I think that "direct linking" against libpython.so (for dynamic linking only, of course) will not embed the symbols in libboost_python.so, but enable the linker to verify that all weak references into libpython.so can be resolved at runtime. Using "--no-undefined" is a way to check that you explicitly link against _all_ required libraries. If linking "normally" gnu ld will link everything together happily (with weak symbols) and trust the runtime loader to pull everything together. In this case, your builds might fail on the windows platform for example where the msvc linker (and dllexport/-import) always enforce explicit listing of all needed libraries at link time. Qt &gt; 4.3 uses this flag to improve cross platform consistency (in addition to gcc visibility support). </p> Ticket Dave Abrahams Mon, 29 Dec 2008 20:14:44 GMT <link>https://svn.boost.org/trac10/ticket/2615#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2615#comment:4</guid> <description> <p> I have some questions; please excuse my ignorance. </p> <ul><li>What does "direct linking" mean, precisely? </li></ul><ul><li>Will "direct linking" against libpython.so force libpython.so to be loaded when the Python executable loads an extension module that uses libboost_python.so? </li></ul><ul><li>What does the windows platform have to do with this? </li></ul> </description> <category>Ticket</category> </item> <item> <dc:creator>Jürgen Hunold</dc:creator> <pubDate>Mon, 29 Dec 2008 21:20:37 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2615#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2615#comment:5</guid> <description> <blockquote class="citation"> <p> What does "direct linking" mean, precisely? </p> </blockquote> <p> adding -lpython to the linker command line when linking libboost_python.so </p> <blockquote class="citation"> <p> Will direct linking" against libpython.so force libpython.so to be loaded when the Python executable loads an extension module that uses libboost_python.so? </p> </blockquote> <p> Yes, of course. Does this cause any problems ? I've just dug out that I've patched python.jam to link extension modules against libpython.so due to a bug in the preview version of gold, the new ld replacement from Google which did not support undefined symbols at that time. Will attach the patch right now, although it seems not to be needed anymore with binutils 2.19. My (one and only experimental) module works fine with and without explicit linking to libpython. </p> <blockquote class="citation"> <p> What does the windows platform have to do with this? </p> </blockquote> <p> Nothing directly. -no-undefined is just a tool to assist in cross-platform development. The usage is to spot unexported/undefined symbols when using gnu ld on unix platforms. Remember, gnu ld allows for symbols to be undefined at link time (this is used when linking libboost_python right now). msvc link.exe needs all symbols to be explicitly exported/imported for all libraries the current .dll depends on. So if you use gcc visibility and -no-undefined you are less likely to check out on windows and hit "missing" symbols due to forgotten "dllexport/-import" specifications." This is the way Qt goes and which I use to minimize broken builds on Windows because my main development platform is Linux. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Jürgen Hunold</dc:creator> <pubDate>Mon, 29 Dec 2008 21:21:56 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/2615 https://svn.boost.org/trac10/ticket/2615 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">pyton.jam.diff</span> </li> </ul> <p> Patch to link explicitly againt libpython </p> Ticket anonymous Tue, 30 Dec 2008 03:14:49 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2615#comment:6 https://svn.boost.org/trac10/ticket/2615#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/2615#comment:5" title="Comment 5">jhunold</a>: </p> <blockquote class="citation"> <blockquote class="citation"> <p> What does "direct linking" mean, precisely? </p> </blockquote> <p> adding -lpython to the linker command line when linking libboost_python.so </p> <blockquote class="citation"> <p> Will direct linking" against libpython.so force libpython.so to be loaded when the Python executable loads an extension module that uses libboost_python.so? </p> </blockquote> <p> Yes, of course. Does this cause any problems ? </p> </blockquote> <p> Yes, of course. It forces a dependency on libpython.so and increases the overall runtime image, aside from very likely causing duplicate copies of the code, and more worryingly, globals. </p> <blockquote class="citation"> <p> I've just dug out that I've patched python.jam to link extension modules against libpython.so due to a bug in the preview version of gold, the new ld replacement from Google which did not support undefined symbols at that time. Will attach the patch right now, although it seems not to be needed anymore with binutils 2.19. My (one and only experimental) module works fine with and without explicit linking to libpython. </p> </blockquote> <p> Can you pass the Boost.Python test suite? </p> <pre class="wiki"> cd libs/python/test bjam </pre><blockquote class="citation"> <blockquote class="citation"> <p> What does the windows platform have to do with this? </p> </blockquote> <p> Nothing directly. -no-undefined is just a tool to assist in cross-platform development. The usage is to spot unexported/undefined symbols when using gnu ld on unix platforms. Remember, gnu ld allows for symbols to be undefined at link time </p> </blockquote> <p> Believe me, I know </p> <blockquote class="citation"> <p> (this is used when linking libboost_python right now). msvc link.exe needs all symbols to be explicitly exported/imported for all libraries the current .dll depends on. So if you use gcc visibility and -no-undefined you are less likely to check out on windows and hit "missing" symbols due to forgotten "dllexport/-import" specifications." This is the way Qt goes and which I use to minimize broken builds on Windows because my main development platform is Linux. </p> </blockquote> <p> It's a nice technique, but it's not equivalent at all when it comes to Python because on Windows, python.exe uses the python shared library while on unix the python executable does not. </p> <p> Still willing to have you re-open the ticket if you still believe I'm wrong. </p> Ticket Arfrever Sat, 14 Jan 2012 15:55:32 GMT <link>https://svn.boost.org/trac10/ticket/2615#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2615#comment:7</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/2615#comment:6" title="Comment 6">anonymous</a>: </p> <blockquote class="citation"> <p> on Windows, python.exe uses the python shared library while on unix the python executable does not. </p> </blockquote> <p> On Unix, python executable uses python shared library if './configure --enable-shared' has been used during building Python. Majority of GNU/Linux distributions build Python with --enable-shared option. </p> </description> <category>Ticket</category> </item> </channel> </rss>