From: Shriramana Sharma <samjnaa@gmail.com>
To: linux-c-programming@vger.kernel.org
Subject: Multiple declaration problem
Date: Sat, 24 Feb 2007 21:19:23 +0530 [thread overview]
Message-ID: <45E05E83.5010005@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1689 bytes --]
Hello. I have a problem with multiple declaration in a project I am
working on. I have constructed a similar testcase which throws the same
kind of error. Please see the files in the attachment. -g or -g3 did not
give any useful debugging symbols, I don't know why. The following is
the session transcript:
$ ls
main.cpp myheader.cpp myheader.h
$ g++ -c main.cpp
$ g++ -c myheader.cpp
$ g++ -o main main.o myheader.o
myheader.o:(.data+0x0): multiple definition of `b'
main.o:(.data+0x0): first defined here
collect2: ld returned 1 exit status
$ mv main.cpp main.c
$ mv myheader.cpp myheader.c
$ rm *.o
$ gcc -c main.c
$ gcc -c myheader.c
$ gcc -o main main.o myheader.o
myheader.o:(.rodata+0x0): multiple definition of `a'
main.o:(.rodata+0x0): first defined here
myheader.o:(.data+0x0): multiple definition of `b'
main.o:(.data+0x0): first defined here
collect2: ld returned 1 exit status
In my project, I need to put the following statement in a header file:
int lawCurrentEngine = NONE ; // NONE has been enum-med previously
because I need to declare a function
int lawCloseEngine ( int engineID = lawCurrentEngine ) ;
I include the header file containing these two lines in two cpp files,
and I get a multiple definition error for lawCurrentEngine just like in
the given test case. If I push the lawCurrentEngine declaration to one
of the cpp-s (it's not needed in the other cpp) I am unable to provide
the default argument for the lawCloseEngine which can be done only in
the header.
I don't understand how I am getting such an error when I have used the
#ifndef #define #endif technique as per good programming practice.
Please help,
Thanks.
Shriramana Sharma.
[-- Attachment #2: multiple-declaration-problem.tar.gz --]
[-- Type: application/gzip, Size: 611 bytes --]
next reply other threads:[~2007-02-24 15:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-24 15:49 Shriramana Sharma [this message]
2007-02-27 18:42 ` Multiple declaration problem Glynn Clements
2007-02-27 18:57 ` Jesse Ruffin
2007-02-28 15:31 ` Shriramana Sharma
2007-03-07 16:36 ` Glynn Clements
-- strict thread matches above, loose matches on Subject: below --
2007-02-27 10:50 cyon.john
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=45E05E83.5010005@gmail.com \
--to=samjnaa@gmail.com \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).