![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Avoid creating temporary files on editing a file in Ubuntu | royalibrahim | Linux | 7 | 11-17-2007 02:57 AM |
| avoid displaying errors while executing a script | vikas027 | Shell Programming and Scripting | 4 | 10-29-2007 11:41 AM |
| combine two files | fredao1 | Shell Programming and Scripting | 1 | 01-08-2007 06:29 PM |
| Adapter Errors and Link Errors | mcastill66 | AIX | 2 | 08-02-2005 03:51 PM |
| Adapter Errors and Link Errors | mcastill66 | UNIX for Advanced & Expert Users | 0 | 08-02-2005 03:11 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
What is the proper way to combine C++ files (with g++) to avoid link (ld) errors?
Problem background:
gcc v 4.1 2 .cpp files, 2 .h files Files: main.cpp a.cpp a.h b.h Organization: main.cpp includes a.h (because it calls a.cpp code) a.cpp includes a.h a.h includes b.h (because a class in a.h uses a b.h class) There is no inheritance between a.h or b.h or any of the classes. The problem is that when I try to compile the files like g++ main.cpp a.cpp I get an bunch of linker errors like "duplicate symbol X found..." which are for symbols from b.h Normally I would think this is due to there not being #ifndef or #pragma once guards, but there are "#pragma once" things at the top of all the .h files. To me it seems like what is happening is that gcc is generating main.o separately from a.o and then then ld is called it sees duplication of symbols and it errors out. What is the correct way to tell g++ to compile them both while looking at them both? I would think it would be something like --combine, but the man page and testing show that's only valid for C files. I have also tried -shared which makes ld not complain but which says it's for making a shared library, so it doesn't seem correct for building an executable. Will using -shared lead to any strange behavior down the road (I need to know now since the application itself isn't in a state that I can test it, and I don't want to end up finding out it was the -shared flag's fault) I have also tried -fwhole-program, which again works, but the man page says it's for optimization, so that also doesn't seem correct. Same question with regards to possible weird behavior down the road. Thanks much for any help. John |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Maybe you have duplicate global variables defined in header file (e.g. "a.h"). Make sure the all global are declared with "extern" keyword.
|
|||
| Google The UNIX and Linux Forums |