msg4158 - (view) |
Author: Nobody/Anonymous (nobody) |
Date: 2001-04-04 00:42 |
When building c++ extension using distutils setup, the compiler that was used to build python distribution is always called. On Linux, it is normally gcc. When gcc is called to link shared library, it does not link certain c++ runtime stuff. As a result, when extension is imported, missing symbols are reported, e.g.: >>> import ex_ext1 Traceback (most recent call last): File "", line 1, in ? ImportError: ./ex_ext1.so: undefined symbol: __vt_13runtime_error >>> I tried to use "extra_link_args = ['-x c++']" in setup.py (it tells gcc to link as c++), but that gets added to the end of compiler's command line, which results in: gcc -shared build/temp.linux-i686-2.1/ex_ext1.o -L../boost/libs/python -lboost_python -o build/lib.linux-i686-2.1/ex_ext1.so -x c++ gcc: Warning: `-x c++' after last input file has no effect Proposed solution: either use CXX= variable from Python Makefile when c++ files are involved, or prepend extra_link_args to compiler's arguments instead of appending them. |
|
|
msg4159 - (view) |
Author: Andrei Tovtchigretchko (andreitd) |
Date: 2001-04-05 00:23 |
Logged In: YES user_id=189208 Follow-up: If I link with a static library (-lboost_python is libboost_python.a in bug post example), the problem shows. If I link with shared c++ library (libboost_python.so), everything is ok. |
|
|
msg4160 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2001-04-10 15:51 |
Logged In: YES user_id=6380 Assigning this to Andrew, who is the current distutils maintainer. |
|
|
msg4161 - (view) |
Author: Anthony Baxter (anthonybaxter)  |
Date: 2002-04-18 06:47 |
Logged In: YES user_id=29957 can this be closed as a duplicate of 454030? That one has a real submitter, and some more info... |
|
|
msg4162 - (view) |
Author: Guido van Rossum (gvanrossum) *  |
Date: 2002-04-18 12:55 |
Logged In: YES user_id=6380 reassigned to amk who should know |
|
|
msg4163 - (view) |
Author: Gustavo Niemeyer (niemeyer) *  |
Date: 2002-11-05 02:19 |
Logged In: YES user_id=7887 I'm attaching a proposed solution. Here is how the magic is done: There's a new CCompiler.detect_language() method, which based on the sources extensions and on language_map and language_order class variables (subclasses can overload these), determine what's the "target language" of a set of source files. This target language is passed to every CCompiler method which deals with the linkage step (create_static_lib(), link(), and link_*()). UnixCCompiler uses this information to replace the linking command (if the target language is c++) with cpp_linker[0], which is set on sysconfig.py:customize_compiler(). Other classes, such as msvccompiler.py, could also use the same infrastructure to remove some of the hardcoded extension tests already there. Additionally, an Extension can set the "language" parameter to hardcode a language in setup.py. (PS. this patch also fixes some wrong prototypes of create_static_libs()) |
|
|
msg4164 - (view) |
Author: Martin v. Löwis (loewis) *  |
Date: 2002-11-05 08:12 |
Logged In: YES user_id=21627 A couple of comments: - distutils should stay compatible with earlier versions of Python, back to 1.5.2. So don't use isinstance(value, list), as list might be a function - cpp_ might be confused as having to do with the preprocessor; I recommend to use cxx_ throughout - You should check whether CXX is set. If it isn't, and you need to compile a C++ file, you should probably raise an exception. |
|
|
msg4165 - (view) |
Author: Gustavo Niemeyer (niemeyer) *  |
Date: 2002-11-05 12:42 |
Logged In: YES user_id=7887 (I just realized I posted the patch to this bug, and not the one I told. Sorry) Ok.. I'm attaching a new patch including your suggestions. A few comments: - Instead of setting cpp_linker, I'm now using compiler_cxx, as that's what it really is right now, from a Makefile point of view. Other compilers may want to use it in different places. - I'm now checking if compiler_cxx is set before using it. In the worst case, the old behavior will be used, hoping for the best. |
|
|
msg4166 - (view) |
Author: Martin v. Löwis (loewis) *  |
Date: 2002-11-05 12:53 |
Logged In: YES user_id=21627 This patch looks fine, please apply it. If you have spare time, please check out the distutils CVS module, and see whether the tests still pass. |
|
|
msg4167 - (view) |
Author: Gustavo Niemeyer (niemeyer) *  |
Date: 2002-11-05 16:15 |
Logged In: YES user_id=7887 Applied as: bcppcompiler.py:1.13->1.14 ccompiler.py:1.49->1.50 cygwinccompiler.py:1.18->1.19 emxccompiler.py:1.8->1.9 extension.py:1.12->1.13 msvccompiler.py:1.49->1.50 mwerkscompiler.py:1.10->1.11 sysconfig.py:1.51->1.52 unixccompiler.py:1.48->1.49 command/build_ext.py:1.87->1.88 command/config.py:1.12->1.13 Thank you! |
|
|