Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

squater

macrumors newbie
Original poster
Jun 16, 2007
2
0
I'm trying to compile C++ source that requires a number of libraries. Unfortuantly two libraries contain definitions for the same symbol and results in an error. Is there a way to specify which library take preference in the symbol definition?

I know this is not strictly exclusively a Mac orientated question, but I am compiling on OS X so thought here might be a good place to start. Thanks for any help. Below is a printout of the error I receive:

Input:
/usr/local/mpich-1.2.7/bin/mpicxx -g -O2 -o mpifxcorr mpifxcorr.o fxmanager.o core.o datastream.o visibility.o configuration.o uvw.o mode.o mk5.o polyco.o -Wl,-bind_at_load -L/Library/Frameworks/Intel_IPP.framework/Versions/Current/lib/ -L/Library/Frameworks/Intel_IPP.framework/Versions/Current/lib -L/Users/andrewwoods/corr/rpfits/ -L/Users/andrewwoods/corr/vlba_utils/ -lipps -lguide -lippvm -lvlba_utils -lrpfits -lg2c -lm

Output
/usr/bin/ld: multiple definitions of symbol ___divdi3
/usr/local/lib/libg2c.dylib(_divdi3.o) definition of ___divdi3
/usr/lib/gcc/i686-apple-darwin8/4.0.1/../../../libgcc_s.10.4.dylib(_divdi3_s.o) definition of ___divdi3
collect2: ld returned 1 exit status
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Take a look at the strip command.

From man strip:

strip removes or modifies the symbol table attached to the output of
the assembler and link editor. This is useful to save space after a
program has been debugged and to limit dynamically bound symbols.

It might be possible to use this to remove the symbol from one of the libraries...
 

brkirch

macrumors regular
Oct 18, 2001
191
1
I'm trying to compile C++ source that requires a number of libraries. Unfortuantly two libraries contain definitions for the same symbol and results in an error. Is there a way to specify which library take preference in the symbol definition?

Yes, first attempt to compile again except with the -v option added to the compile command. This will give you the command that is being sent to the linker ld in the output. You then need to add the -m option to the linker command to allow for multiply defined symbols. Here's a description of what the -m option for the linker does:
-m (32-bit only)
Don't treat multiply defined symbols from the linked objects as
a hard error; instead, simply print a warning. The first linked
object defining such a symbol is used for linking; its value is
used for the symbol in the symbol table. The code and data for
all such symbols are copied into the output. The duplicate sym-
bols other than the first symbol may still end up being used in
the resulting output file through local references. This can
still produce a resulting output file that is in error. This
flag's use is strongly discouraged!

Of course you should still try to if possible edit the source of what you are compiling to resolve the conflict, but this may work if editing the source isn't an option.
 

squater

macrumors newbie
Original poster
Jun 16, 2007
2
0
brkirch said:
You then need to add the -m option to the linker command to allow for multiply defined symbols.

Thanks for that, resolved the double symbol definition problem.

Unfortunately I don't have access to the library source, just the binaries. Although I am using the gfortan library from sourceforge so I'm sure it should be available.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.