LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-29-2003, 10:22 AM   #1
qanopus
Senior Member
 
Registered: Jul 2002
Location: New York
Distribution: Slackware
Posts: 1,358

Rep: Reputation: 45
linking problem: "multiple definition of .."


Hi,
I have some problems linking a program that I created. I get these errors:

/tmp/cciJGmJZ.o(.data+0x0): multiple definition of `operators'
/tmp/ccAQ8C4f.o(.data+0x0): first defined here
/tmp/cciJGmJZ.o(.data+0x8): multiple definition of `fNames'
/tmp/ccAQ8C4f.o(.data+0x8): first defined here
/tmp/cciJGmJZ.o(.data+0x1c): multiple definition of `countFunctions'
/tmp/ccAQ8C4f.o(.data+0x1c): first defined here
/tmp/cciJGmJZ.o(.bss+0x0): multiple definition of `currentExpression'
/tmp/ccAQ8C4f.o(.bss+0x0): first defined here
collect2: ld returned 1 exit status
make: *** [all] Error 1

because the source files are to big to be posted here, I'l just give a link to where they are at;
link
You will find three files, ES.cpp, ES.h and main.h
The thing is, I need the stuff that's in "ES.h" in both "ES.cpp" and "main.cpp". That's why I have an "#include "ES.h" " in both. And I think this results in the error.
Can someone help me?
 
Old 01-29-2003, 10:28 AM   #2
cybercop12us
Member
 
Registered: Aug 2001
Posts: 60

Rep: Reputation: 15
you can give -Xlinker -zmuldefs option to g++ if you are using g++

or if you are using ld to link u can give -zmuldefs
 
Old 01-29-2003, 10:37 AM   #3
qanopus
Senior Member
 
Registered: Jul 2002
Location: New York
Distribution: Slackware
Posts: 1,358

Original Poster
Rep: Reputation: 45
Hi,
it didn't work. This is my makefile:

#!/bin/bash

all:

g++ ES.cpp main.cpp -Xlinker -zmuldefs -o calc


It still says the same
 
Old 01-29-2003, 11:32 AM   #4
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
Make sure that in your .h files, the #ifndef line is the very first thing, so you should remove the comment at the beginning of that file.
 
Old 01-29-2003, 12:14 PM   #5
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
And I could be wrong but it might be the case that you have to export the variables defined in other files. It might have something to do with scope rules.

Last edited by GtkUser; 01-29-2003 at 12:17 PM.
 
Old 01-30-2003, 04:40 AM   #6
qanopus
Senior Member
 
Registered: Jul 2002
Location: New York
Distribution: Slackware
Posts: 1,358

Original Poster
Rep: Reputation: 45
Hello,
GtkUser, I don't know how to do that. How do yuou export variables?
 
Old 01-30-2003, 05:00 AM   #7
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
To tell you the truth, I have not used it for before, but I've read about it. Infact I should have said 'extern' rather than export.

So in your .h file your declaration can be like this:
extern int value;

But not this:
int value = 0;
Or this is wrong too:
int value;

Extern means that value is defined somewhere else in a .cpp file. Also you can not initialize variables in the .h file, because that means they become a definition. Apparently the header file should only contain definitions for INLINE functions or objects. And the rest is declarations. A non-inline definition belongs in the .cpp file. At least that is what I gather.

Last edited by GtkUser; 01-30-2003 at 05:02 AM.
 
Old 01-30-2003, 05:08 AM   #8
GtkUser
Member
 
Registered: Sep 2002
Location: Canada
Distribution: Redhat 9.0
Posts: 637

Rep: Reputation: 30
The header file is a centralized location for all extern object declarations, function declarations, and inline function definitions. That's all.

Files that must use or define and object or function include the header file(s).

So in other words, you have variable definitions in your header file, and those should be removed or made extern, or made inline.

Last edited by GtkUser; 01-30-2003 at 05:10 AM.
 
Old 01-30-2003, 05:11 AM   #9
qanopus
Senior Member
 
Registered: Jul 2002
Location: New York
Distribution: Slackware
Posts: 1,358

Original Poster
Rep: Reputation: 45
Thanks. I have a friend here sugesting the same thing. So I'l try and report back
 
Old 01-30-2003, 05:21 AM   #10
qanopus
Senior Member
 
Registered: Jul 2002
Location: New York
Distribution: Slackware
Posts: 1,358

Original Poster
Rep: Reputation: 45
Thanks a million. It worked.
 
Old 02-02-2010, 02:06 AM   #11
Sanjeev Sawargi
LQ Newbie
 
Registered: Feb 2010
Posts: 1

Rep: Reputation: 0
Smile Thanks

Quote:
Originally Posted by schatoor View Post
Thanks a million. It worked.
It works...
 
Old 05-03-2012, 03:04 AM   #12
lastsurvivor
LQ Newbie
 
Registered: Aug 2007
Posts: 11
Blog Entries: 1

Rep: Reputation: 0
Thank you very much
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Debian Boot Up Problem - stuck at "BR" & "I" jc70417 Debian 2 08-30-2005 04:36 PM
problem "make"ing gtk+ "/usr/bin/env: perl -w" caid Linux - Newbie 8 07-29-2005 04:51 AM
Sound problem with "alsamixer" or "alsaconf" or sth else maybe... Mikuda Linux - Games 4 05-01-2004 11:09 AM
G++ Linking Error "undefined reference" djjumper9 Programming 2 04-13-2004 09:36 AM
localhost:901 gets redirected to "Power Linking" web site advertisement condosolon Linux - Newbie 2 03-04-2004 12:23 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration