Opened 4 years ago

Last modified 8 months ago

#42777 assigned defect

gcc47/gcc48 - problem with linking some C++ python extensions (std::ostringstream)

Reported by: wojdyr@… Owned by: macports-tickets@…
Priority: Normal Milestone:
Component: ports Version: 2.2.1
Keywords: Cc: jeremyhu (Jeremy Huddleston Sequoia), larryv (Lawrence Velázquez)
Port: gcc48

Description

I've been tracking a problem with Boost.Python extensions built using GCC from macports. Here is a minimal program that shows the problem:

#include <iostream>
#include <sstream>

extern "C" void run() {
    std::ostringstream o;
    o << 123;
    std::cout << "[" << o.str() << "]\n";
}

It runs fine when dlopen'ed from C, but not from Python (regardless if it's system or macports or manually built Python).

$ g++-mp-4.8 -c -fPIC otest.cc
$ g++-mp-4.8 -bundle -undefined dynamic_lookup otest.o -o otest.so
$ python -c "import ctypes; ctypes.CDLL('./otest.so').run()"
[]

(I'm using ffi here to keep it simple, it's the same with python extension).

If I replace g++-mp-4.8 with g++ when linking it works as expected:

$ g++ -bundle -undefined dynamic_lookup otest.o -o otest.so
$ python -c "import ctypes; ctypes.CDLL('./otest.so').run()"
[123]

Alternatively, if I take the linking command from g++-mp-4.8:

/opt/local/bin/ld -dynamic -arch x86_64 -bundle -macosx_version_min 10.6.8 -undefined dynamic_lookup -weak_reference_mismatches non-weak -undefined dynamic_lookup -o otest.so -L/opt/local/lib/gcc48/gcc/x86_64-apple-darwin10/4.8.2 -L/opt/local/lib/gcc48/gcc/x86_64-apple-darwin10/4.8.2/../../.. otest.o -lstdc++ -no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lSystem

and remove -lstdc++, it also works.

I'm using OSX 10.6. This problem happens with gcc47 and gcc48 from macports, but not with GCC from xcode and clang-3.3 from macports. Is it fixable?

Change History (7)

comment:1 Changed 4 years ago by wojdyr@…

I've realized that ostringstream is not necessary, any stream fed with integer or float will do. For example this function:

#include <iostream>
extern "C" void run() { std::cout << 123 << "\n"; }

does not print anything when built with macports gcc and called from python.

comment:2 Changed 4 years ago by mf2k (Frank Schima)

  • Cc jeremyhu@… added
  • Owner changed from macports-tickets@… to mww@…

comment:3 Changed 4 years ago by mf2k (Frank Schima)

In the future, please Cc the port maintainers (port info --maintainers gcc48).

comment:4 Changed 4 years ago by larryv (Lawrence Velázquez)

  • Cc larryv@… added

Cc Me!

comment:5 Changed 4 years ago by petrrr

  • Cc Peter.Danecek@… added

Cc Me!

comment:6 Changed 15 months ago by petrrr

  • Cc Peter.Danecek@… removed

comment:7 Changed 8 months ago by kurthindenburg (Kurt Hindenburg)

  • Owner changed from mww@… to macports-tickets@…
  • Status changed from new to assigned
Note: See TracTickets for help on using tickets.