Sponsored Content
Top Forums Programming What is the proper way to combine C++ files (with g++) to avoid link (ld) errors? Post 302171728 by johnqsmith on Friday 29th of February 2008 09:30:51 AM
Old 02-29-2008
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
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Adapter Errors and Link Errors

$ errpt | more IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION 3074FEB7 0802050205 T H fscsi1 ADAPTER ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR 3074FEB7 0802050205 T H fscsi0 ADAPTER ERROR B8113DD1 ... (0 Replies)
Discussion started by: mcastill66
0 Replies

2. AIX

Adapter Errors and Link Errors

$ errpt | more IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION 3074FEB7 0802050205 T H fscsi1 ADAPTER ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR 3074FEB7 0802050205 T H fscsi0 ADAPTER ERROR B8113DD1 ... (2 Replies)
Discussion started by: mcastill66
2 Replies

3. Shell Programming and Scripting

avoid displaying errors while executing a script

Hi all, I am running a script on bash shell, although it gives me the desired output, it displays some errors at the prompt like this directory doesnt exists unary operator etc etc Is there someway to avoid these errors ?? Its very annoying to have these errors while the script is... (4 Replies)
Discussion started by: vikas027
4 Replies

4. Shell Programming and Scripting

Checking for proper number of files in dir

Using Solaris 10 and sh. I have three files. mydirs.txt /dir1/dir2/dir3 /dir4/dir5/dir6 mydirshave.txt 1 2 mydirsshouldhave.txt 2 2 For each directory listed in mydirs.txt I should have the number of files equal to mydirshouldhave.txt. But using -ls |wc -l- on the dirs I get what... (2 Replies)
Discussion started by: crowman
2 Replies

5. Solaris

Any way to avoid these errors?

Hello, this is solaris 10 on SF v440, I know below errors might go away if I put a new PS or put the original one back in socket but is there any other way to stop these errors from appearing in /var/adm/messages ? I do not want to put the failed PS1 in socket neither do we want to spend on... (5 Replies)
Discussion started by: upengan78
5 Replies

6. AIX

Link Errors in AIX

Hi Can any suggest me how to work on this particular issue i am facing. Below is the error message received on vio servers. IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION 4B436A3D 0326102912 T H fscsi1 LINK ERROR 4B436A3D 0325212712 T H fscsi1 LINK ERROR 4B436A3D... (2 Replies)
Discussion started by: ganiiee
2 Replies

7. Shell Programming and Scripting

Combine multiline to one line with proper format

Hello Guys, I have a file say FILE1.txt contains below data:- A B C D E F G H I J K L I need the output in another file as FILE2 as:- 'A', 'B', 'C', 'D', 'E', (7 Replies)
Discussion started by: jassi10781
7 Replies

8. UNIX for Advanced & Expert Users

CentOS 6.8 with Rocks Cluster: ldconfig is not a symbolic link errors

Any help appreciated just logging in to this server which is a front end for Rocks Cluster 6.1.1. Getting the below errors: ldconfig ldconfig: /usr/lib/libX11.so.6 is not a symbolic link ldconfig: /usr/lib/libjpeg.so.62 is not a symbolic link ldconfig: /usr/lib/libpng12.so.0 is not a symbolic... (3 Replies)
Discussion started by: RobbieTheK
3 Replies

9. UNIX for Beginners Questions & Answers

Automate splitting of files , scp files as each split completes and combine files on target server

i use the split command to split a one terabyte backup file into 10 chunks of 100 GB each. The files are split one after the other. While the files is being split, I will like to scp the files one after the other as soon as the previous one completes, from server A to Server B. Then on server B ,... (2 Replies)
Discussion started by: malaika
2 Replies

10. AIX

How to avoid errors when moving files in a bff?

I am building a bff using mkinstallp. My template file is : Package Name: svr_exForum Package VRMF: 7.2 Update: N Fileset Fileset Name: svr_exForum.rte Fileset VRMF: 7.2 USRLIBLPPFiles Pre-installation Script: /lppdir/lpp/exForum/F_pre_i ... (2 Replies)
Discussion started by: kevinl
2 Replies
lupdate(1)						      General Commands Manual							lupdate(1)

NAME
lupdate - update Qt Linguist translation files SYNOPSIS
lupdate [ options ] project-file lupdate [ options ] source-files -ts ts-files DESCRIPTION
This page documents the Qt Linguist Update tool for the Qt GUI toolkit. Lupdate reads a qmake/tmake project file (.pro file), finds the translatable strings in the specified source, header and interface files, and updates the translation files (.ts files) specified in it. The translation files are given to the translator who uses Qt Linguist to read the files and insert the translations. The .ts file format is a simple human-readable XML format that can be used with version control systems if required. OPTIONS
-help Display the usage and exit. -noobsolete Drop all obsolete strings. -verbose Explain what is being done. -version Display the version of lupdate and exit. USAGE
Here is an example .pro file that can be given to lupdate: HEADERS = funnydialog.h wackywidget.h SOURCES = funnydialog.cpp main.cpp wackywidget.cpp FORMS = fancybox.ui TRANSLATIONS = gnomovision_dk.ts gnomovision_fi.ts gnomovision_no.ts gnomovision_se.ts When running lupdate on this project file, the translatable strings in all the files listed in the HEADERS, SOURCES and FORMS entries will be put in the translation files listed in the TRANSLATIONS entry. Previous translations will be reused as far as possible, and translated strings that have vanished from the source files are marked obsolete. Lupdate can also be invoked with a list of C++ source files, .ui files and .ts files: lupdate *.cpp *.h *.ui -ts gnomovision_dk.ts SEE ALSO
lrelease(1) and http://doc.trolltech.com/i18n.html Trolltech AS 18 October 2001 lupdate(1)
All times are GMT -4. The time now is 01:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy