Preferred compiler options for compiling/linking multiple files
Colin Thomas
colin@designresources.co.uk
Mon Jul 24 08:30:00 GMT 2000
Hi,
Up till now I have created single file code, but I need to compile multiple files as I have a large project
I would be interested in knowing what the prefered compiler options should be in this situation.
The following scenario might be a useful starting place.
###########################################
I have some global Variables, which are visible to each of the multiple files.
i.e. Global.h
///////////////////////////
#include <string>
string GlobalString;
#define GlobalREAD
///////////////////////////
In each of the mulitple files, I have
///////////////////////////
#ifndef GlobalREAD
#include "Global.h"
#endif
///////////////////////////
Each multiple file is compiled as:
g++ -c -O2 -fno-strength-reduce -o File1.o File1.cpp
g++ -c -O2 -fno-strength-reduce -o File2.o File2.cpp
g++ -c -O2 -fno-strength-reduce -o File3.o File3.cpp
.
.
.
Each compiles individually okay.
When I come to compile the final executable, pulling in File1.o/File2.o/File3.o using
g++ -o Final File1.o File2.o File3.o Final.cpp
I get errors like:
ld: fatal: symbol `GlobalString' is multiply defined:
(file File1.o and file File2.o);
I know that the answer lies in one (of the many) compiler options, but an unsure of the ones for this case.
I am gcc 2.95.2 and on a sparc machine.
I look forward to being guided by your collective wisdom..
best regards
Colin Thomas ... EE not CS :-)
More information about the Gcc-help
mailing list