Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#36924 closed defect (invalid)

gcc47 @4.7.2 or ld(64) problem

Reported by: angelo.graziosi@… Owned by: mww@…
Priority: Normal Milestone:
Component: ports Version: 2.1.2
Keywords: Cc: jeremyhu (Jeremy Huddleston Sequoia)
Port: gcc47

Description

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

  1. Cygwin with GCC 4.5.3, 4.8-snapshot
  2. GNU/Linux (K)Ubuntu 12.04 with GCC 4.6.3

Ciao, Angelo.

Change History (6)

comment:1 Changed 12 years ago by ryandesign (Ryan Carsten Schmidt)

Cc: mww@… removed
Keywords: gcc ld removed
Owner: changed from macports-tickets@… to mww@…
Summary: GCC-4.7.2 or ld(64) problemgcc47 @4.7.2 or ld(64) problem

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

Cc: jeremyhu@… added

comment:3 Changed 12 years ago by jeremyhu (Jeremy Huddleston Sequoia)

Compile each individually and then link together, so it will tell you which units have the collisions.

comment:4 in reply to:  3 ; Changed 12 years ago by angelo.graziosi@…

Replying to 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.

comment:5 in reply to:  4 Changed 12 years ago by jeremyhu (Jeremy Huddleston Sequoia)

Resolution: invalid
Status: newclosed

Replying to 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.

comment:6 Changed 12 years ago by jeremyhu (Jeremy Huddleston Sequoia)

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.

Note: See TracTickets for help on using tickets.