[MacPorts] #36924: GCC-4.7.2 or ld(64) problem
#36924: GCC-4.7.2 or ld(64) problem -------------------------------+-------------------------------- Reporter: angelo.graziosi@… | Owner: macports-tickets@… Type: defect | Status: new Priority: Normal | Milestone: Component: ports | Version: 2.1.2 Keywords: gcc,ld | Port: gcc47 -------------------------------+-------------------------------- I have found a "duplicate symbol" error that seems to occurs only with gcc-4.7.2 from MacPorts. The simplest way to reproduce is to follow these steps (they take only few minutes): {{{ 1. mkdir work 2. cd work 3. wget http://warp.povusers.org/FunctionParser/fparser4.5.zip 4. unzip fparser4.5.zip 5. cd examples 6. g++-mp-4.7 example.cc ../fparser.cc ../fpoptimizer.cc -o example.out }}} the result is a lot of: {{{ duplicate symbol FunctionParserBase<double>::FunctionWrapper::FunctionWrapper() in: /var/folders/rn/j8bb78_n0mq1q0597prsldc00000gn/T//cctcdQVl.o /var/folders/rn/j8bb78_n0mq1q0597prsldc00000gn/T//ccXBMFPC.o duplicate symbol FunctionParserBase<double>::FunctionWrapper::FunctionWrapper() in: [...] }}} If I use clang++ (4.1 x86_64-apple-darwin11.4.2, Xcode 4.5.2) the above example builds and works fine without linker errors. The same (i.e. it buils and works) occurs on a. Cygwin with GCC 4.5.3, 4.8-snapshot b. GNU/Linux (K)Ubuntu 12.04 with GCC 4.6.3 Ciao, Angelo. -- Ticket URL: <https://trac.macports.org/ticket/36924> MacPorts <http://www.macports.org/> Ports system for Mac OS
#36924: gcc47 @4.7.2 or ld(64) problem --------------------------------+------------------- Reporter: angelo.graziosi@… | Owner: mww@… Type: defect | Status: new Priority: Normal | Milestone: Component: ports | Version: 2.1.2 Resolution: | Keywords: Port: gcc47 | --------------------------------+------------------- Changes (by ryandesign@…): * cc: mww@… (removed) * keywords: gcc,ld => * owner: macports-tickets@… => mww@… -- Ticket URL: <https://trac.macports.org/ticket/36924#comment:1> MacPorts <http://www.macports.org/> Ports system for Mac OS
#36924: gcc47 @4.7.2 or ld(64) problem --------------------------------+------------------- Reporter: angelo.graziosi@… | Owner: mww@… Type: defect | Status: new Priority: Normal | Milestone: Component: ports | Version: 2.1.2 Resolution: | Keywords: Port: gcc47 | --------------------------------+------------------- Changes (by macsforever2000@…): * cc: jeremyhu@… (added) -- Ticket URL: <https://trac.macports.org/ticket/36924#comment:2> MacPorts <http://www.macports.org/> Ports system for Mac OS
#36924: gcc47 @4.7.2 or ld(64) problem --------------------------------+------------------- Reporter: angelo.graziosi@… | Owner: mww@… Type: defect | Status: new Priority: Normal | Milestone: Component: ports | Version: 2.1.2 Resolution: | Keywords: Port: gcc47 | --------------------------------+------------------- Comment (by jeremyhu@…): Compile each individually and then link together, so it will tell you which units have the collisions. -- Ticket URL: <https://trac.macports.org/ticket/36924#comment:3> MacPorts <http://www.macports.org/> Ports system for Mac OS
#36924: gcc47 @4.7.2 or ld(64) problem --------------------------------+------------------- Reporter: angelo.graziosi@… | Owner: mww@… Type: defect | Status: new Priority: Normal | Milestone: Component: ports | Version: 2.1.2 Resolution: | Keywords: Port: gcc47 | --------------------------------+------------------- Comment (by angelo.graziosi@…): Replying to [comment:3 jeremyhu@…]:
Compile each individually and then link together, so it will tell you which units have the collisions.
This is the result: {{{ g++-mp-4.7 -c ../fparser.cc g++-mp-4.7 -c ../fpoptimizer.cc g++-mp-4.7 -c example.cc g++-mp-4.7 fparser.o fpoptimizer.o example.o -o example.out duplicate symbol FunctionParserBase<double>::FunctionWrapper::FunctionWrapper() in: fparser.o fpoptimizer.o duplicate symbol FunctionParserBase<double>::FunctionWrapper::FunctionWrapper() in: fparser.o fpoptimizer.o duplicate symbol FunctionParserBase<double>::FunctionWrapper::FunctionWrapper(FunctionParserBase<double>::FunctionWrapper const&) in: fparser.o fpoptimizer.o [...] }}} Anyway, I am not searching for what causes the error between fparser, fpoptimizer, example... Really I discovered the error in a completely different way.. I was interfacing in Fortran 2003 the parser (http://warp.povusers.org/FunctionParser), and after interfacing the Optimize() member function, I got that error. So I searched for a simpler test case to flag to the parser peoples and I found that step 6 above gives the same error. I flagged this to the parser peoples which answered {{{ Which version of gcc are you using? There's nothing in the constructor of FunctionWrapper that should cause this because it's an inline function (which, by definition, should cause no duplicated symbols.) I think some compilers have a bug where explicitly instantiating a templated class in different compilation units would cause even inline functions to cause duplicate symbol errors, but AFAIK that's a bug and a problem with the compiler itself. }}} and after I replayed it was gcc47 on Mac OSX Lion+Xcode 4.5.2+MacPorts the suggestion was {{{ You should also try clang on the Mac. [...] Since this is a linker error, I'm wondering if the problem is with the linker in Mac OS X. }}} And indeed, with clang++, step 6 above works {{{ clang++ example.cc ../fparser.cc ../fpoptimizer.cc -o example.out ./example.out [bla bla bla...] }}} After this, for curiosity, I tried the same on Cygwin and GN/Linux: all the GCC there works as expected. Only the MacPors gcc47, gcc46, gcc45 fails with that error! (Now I have tried also gcc45 and gcc46) However, you can test steps 1 - 6 above yourself. It take less tha 5 minutes... :-) Ciao, Angelo. -- Ticket URL: <https://trac.macports.org/ticket/36924#comment:4> MacPorts <http://www.macports.org/> Ports system for Mac OS
#36924: gcc47 @4.7.2 or ld(64) problem --------------------------------+-------------------- Reporter: angelo.graziosi@… | Owner: mww@… Type: defect | Status: closed Priority: Normal | Milestone: Component: ports | Version: 2.1.2 Resolution: invalid | Keywords: Port: gcc47 | --------------------------------+-------------------- Changes (by jeremyhu@…): * status: new => closed * resolution: => invalid Comment: Replying to [comment:4 angelo.graziosi@…]: ...
I was interfacing in Fortran 2003 the parser (http://warp.povusers.org/FunctionParser), and after interfacing the Optimize() member function, I got that error.
So I searched for a simpler test case to flag to the parser peoples and I found that step 6 above gives the same error. I flagged this to the parser peoples which answered
{{{ Which version of gcc are you using? There's nothing in the constructor of FunctionWrapper that should cause this because it's an inline function (which, by definition, should cause no duplicated symbols.)
I think some compilers have a bug where explicitly instantiating a templated class in different compilation units would cause even inline functions to cause duplicate symbol errors, but AFAIK that's a bug and a problem with the compiler itself. }}}
No, it's not a bug in the compiler. That comment above is incorrect. It is not true for inline functions. It is true for *static* functions. -- Ticket URL: <https://trac.macports.org/ticket/36924#comment:5> MacPorts <http://www.macports.org/> Ports system for Mac OS
#36924: gcc47 @4.7.2 or ld(64) problem --------------------------------+-------------------- Reporter: angelo.graziosi@… | Owner: mww@… Type: defect | Status: closed Priority: Normal | Milestone: Component: ports | Version: 2.1.2 Resolution: invalid | Keywords: Port: gcc47 | --------------------------------+-------------------- Comment (by jeremyhu@…): http://www.greenend.org.uk/rjk/tech/inline.html:
In this example, one of the declarations does not mention inline: {{{ // a declaration not mentioning inline int max(int a, int b);
// a definition mentioning inline inline int max(int a, int b) { return a > b ? a : b; } }}} In either example, the function will be callable from other files.
-- Ticket URL: <https://trac.macports.org/ticket/36924#comment:6> MacPorts <http://www.macports.org/> Ports system for Mac OS
participants (1)
-
MacPorts