LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 12-09-2003, 11:39 AM   #1
ooagentbender
Member
 
Registered: Sep 2003
Distribution: Vector Linux
Posts: 110

Rep: Reputation: 15
Basic C++ question


::UhUnix2:: make
gcc -o prj2 interface.o llist.o database.o
ld: fatal: symbol `findRecord(Record*, char*)' is multiply-defined:
(file llist.o type=FUNC; file database.o type=FUNC);
ld: fatal: symbol `deleteARecord(Record**, char*)' is multiply-defined:
(file llist.o type=FUNC; file database.o type=FUNC);
ld: fatal: symbol `readafile(Record**, char*)' is multiply-defined:
(file llist.o type=FUNC; file database.o type=FUNC);
ld: fatal: symbol `printAllRecords(Record*)' is multiply-defined:
(file llist.o type=FUNC; file database.o type=FUNC);
ld: fatal: symbol `modRecord(Record*, char*, char*, char*)' is multiply-defined:
(file llist.o type=FUNC; file database.o type=FUNC);
ld: fatal: symbol `addARecord(Record**, char*, char*, int, char*)' is multiply-defined:
(file llist.o type=FUNC; file database.o type=FUNC);
ld: fatal: symbol `writeafile(Record*, char*)' is multiply-defined:
(file llist.o type=FUNC; file database.o type=FUNC);
ld: fatal: File processing errors. No output written to prj2
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `prj2'


ok so my problem has to do with some redeclaration of the functions that I declared in the Record.h file, I just can't figure out where im going wrong with my compiler directives and including files. It may be something else but thats what I think it is. Any help would be awesome I have to turn this in by thursday, and i already know the rest of it works because it did in C and im just converting it to c++.

here are the files

thanks


http://www2.hawaii.edu/~benderj/Prj2/Record.h
http://www2.hawaii.edu/~benderj/Prj2/database.cpp
http://www2.hawaii.edu/~benderj/Prj2/interface.cpp
http://www2.hawaii.edu/~benderj/Prj2/llist.cpp
http://www2.hawaii.edu/~benderj/Prj2/llist.h
 
Old 12-09-2003, 12:46 PM   #2
Tramontane
Member
 
Registered: Oct 2003
Distribution: Debian
Posts: 39

Rep: Reputation: 15
you may need to encapsulate your Record.h file with a few preprocessor directives.

Code:
#ifindef __RECORD_H
#define __RECORD_H

struct Record
{
    char               name[25];
    char               telno[15];
    char               address[80];
    int                yearofbirth;
    struct Record *    next;
};

int addARecord (struct Record **, char [], char [], int, char []);
int findRecord (struct Record *, char[]);
int modRecord (struct Record *, char [], char[], char []);
void printAllRecords (struct Record *);
int deleteARecord (struct Record **, char[]);
void readafile(struct Record **, char filename[]);
void writeafile(struct Record *, char filename[]);

#endif
http://www.cplusplus.com/doc/tutorial/tut5-5.html

hmm, I just saw that you had done that in your llist.h file. I've always thought it to be cleaner to do it the way I said. That way you only have to do it once per header, not once per include. So try that and see if it helps.

the problem probably stems from your "#include database.cpp" line. You shouldn't really ever need to include a *.cpp file.

Last edited by Tramontane; 12-09-2003 at 12:54 PM.
 
Old 12-09-2003, 01:21 PM   #3
Tramontane
Member
 
Registered: Oct 2003
Distribution: Debian
Posts: 39

Rep: Reputation: 15
i found this to be pretty informative. He seems to be developing on a windows machine, but the methods are still sound.

http://www.gamedev.net/reference/pro...ures/orgfiles/
 
Old 12-09-2003, 02:25 PM   #4
ooagentbender
Member
 
Registered: Sep 2003
Distribution: Vector Linux
Posts: 110

Original Poster
Rep: Reputation: 15
AHHH now I get this for some reason.... and it makes little sense to me. I tried running the program in Xcode but it runs instead of giving me these errors and just sits there.

::UhUnix2:: make
gcc -c database.cpp
gcc -o prj2 interface.o llist.o database.o
Undefined first referenced
symbol in file
std::basic_ofstream<char, std::char_traits<char> >::close()database.o
std::basic_ostream<char, std::char_traits<char> >& std:perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)database.o
std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream[in-charge](char const*, std::_Ios_Openmode)database.o
std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)interface.o
std::basic_ostream<char, std::char_traits<char> >:perator<<(int)interface.o
std::cin interface.o
std::basic_ifstream<char, std::char_traits<char> >::close()database.o
std::basic_istream<char, std::char_traits<char> >& std:perator>><char, std::char_traits<char>, std::allocator<char> >(std::basic_istream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)interface.o
std::basic_ifstream<char, std::char_traits<char> >::~basic_ifstream [in-charge]()database.o
std::basic_istream<char, std::char_traits<char> >& std:perator>><char, std::char_traits<char> >(std::basic_istream<char, std::char_traits<char> >&, char&)database.o
std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream[in-charge](char const*, std::_Ios_Openmode)database.o
std::basic_ofstream<char, std::char_traits<char> >::~basic_ofstream [in-charge]()database.o
find(llist) interface.o
operator new(unsigned) database.o
__gxx_personality_v0 interface.o
std::basic_istream<char, std::char_traits<char> >& std:perator>><char, std::char_traits<char> >(std::basic_istream<char, std::char_traits<char> >&, char*)database.o
change(llist) interface.o
std::basic_ostream<char, std::char_traits<char> >& std:perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)interface.o
std::ios_base::Init::Init[in-charge]()interface.o
std::ios_base::Init::~Init [in-charge]()interface.o
getInfoForNew(llist) interface.o
std::basic_string<char, std::char_traits<char>, std::allocator<char> >::length() constinterface.o
std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string [in-charge]()interface.o
std::basic_string<char, std::char_traits<char>, std::allocator<char> >::at(unsigned)interface.o
std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string[in-charge]()interface.o
std::cout interface.o
operator delete(void*) database.o
std::basic_ostream<char, std::char_traits<char> >:perator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))interface.o
std::basic_ifstream<char, std::char_traits<char> >::is_open()database.o
std::basic_istream<char, std::char_traints<char> >:perator>>(int&)interface.o
std::basic_ios<char, std::char_traits<char> >::eof() constdatabase.o
ld: fatal: Symbol referencing errors. No output written to prj2
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `prj2'
 
Old 12-09-2003, 03:45 PM   #5
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Try using g++ instead of gcc. On most systems, I don't think gcc links in the C++ libraries by default, where g++ does.
 
Old 12-09-2003, 03:48 PM   #6
ooagentbender
Member
 
Registered: Sep 2003
Distribution: Vector Linux
Posts: 110

Original Poster
Rep: Reputation: 15
the only problem then is that it just sits there after I run the program
 
Old 12-09-2003, 03:52 PM   #7
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Define, "just sits there." After succesfully compiling your code, if there are no warnings or errors, you will be brought back to the prompt. You can then execute your program using ./prj2.

Or are you saying after you run ./prj2, it just sits there? If that's the case, it is probably something with your code, which I haven't looked at.
 
Old 12-09-2003, 03:56 PM   #8
ooagentbender
Member
 
Registered: Sep 2003
Distribution: Vector Linux
Posts: 110

Original Poster
Rep: Reputation: 15
it just sits there when I run ./prj2
 
Old 12-09-2003, 04:38 PM   #9
ooagentbender
Member
 
Registered: Sep 2003
Distribution: Vector Linux
Posts: 110

Original Poster
Rep: Reputation: 15
ok now the problem is that for some reason my start variable ends up getting set equal to something other than NULL somehwere in there so it gets into the look that will find the next variable thats equal to temp and never gets out. I used the xcode debugger to get to the point where for some reason the statement

if(temp != NULL)

isn't working because it shows that temp = 0x0 in hex which is null right?


whats more when i try and open the file, there shouldn't be one named addressbook.txt anywhere so why is it opening that file
 
Old 12-10-2003, 06:56 PM   #10
ooagentbender
Member
 
Registered: Sep 2003
Distribution: Vector Linux
Posts: 110

Original Poster
Rep: Reputation: 15
Ok I got it figured out, and my program ran fine once I removed the semicolon that was next to the if statement that checked to see if the file was open.

thanks all
 
Old 12-10-2003, 09:34 PM   #11
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Heheh, those pesky misplaced semi-colons...
 
  


Reply



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
Basic Question insyte Linux - Wireless Networking 4 09-16-2004 11:57 AM
*very* basic c question usernamed Programming 9 08-21-2003 08:29 AM
Very basic question rajanr Linux - Newbie 2 07-23-2003 03:13 AM
A really basic question pilotgi Linux - Newbie 10 10-14-2002 04:57 PM
basic question kurgan70 Linux - General 2 12-06-2001 03:42 PM

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

All times are GMT -5. The time now is 09:44 PM.

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