code compiles in C++ but not linux

Fullmetal Chocobo

Moderator<br>Distributed Computing
Moderator
May 13, 2003
13,704
7
81
I have a piece of code that is part of a larger project, and it compiles in Windows just fine (using Bloodshed Dev C++). When I try to compile it in linux, it doesn't work. In Ubuntu, I get an "song.h:66: error: extra qualification 'song::' on member 'operator==' for each of the operators I'm trying to overload in the song class.

In the universities linux environment (either CentOS or RedHat--going to command line from SSH Secure File Transfer Client), it compiles fine, but segment faults when the sort is trying to run (once again back to the overload operator of the Song class).

Yes, this is for class, and the professor isn't sure why this is happening either.
I have my source files for the Song class (song.cpp & song.h) here.

The closest I have found in something relating to this is the 'extra qualification of members' on this page.

Anyone have any idea?
 

Fullmetal Chocobo

Moderator<br>Distributed Computing
Moderator
May 13, 2003
13,704
7
81
Tried your suggestion. Now it gets lots of undefined references to <, etc.

$ make
g++ tsuPod.cpp
/usr/lib/gcc/i386-redhat-linux/3.4.6/../../../crt1.o(.text+0x18): In function `_start':
: undefined reference to `main'
/tmp/ccIs0QDV.o(.text+0x85b): In function `TsuPod::addInOrder(Song)':
: undefined reference to `Song:: operator<(Song const&)'
/tmp/ccIs0QDV.o(.text+0xb53): In function `TsuPod::shuffle()':
: undefined reference to `Song::Song(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)'
/tmp/ccIs0QDV.o(.text+0xccb): In function `TsuPod::shuffle()':
: undefined reference to `Song::Song(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)'
/tmp/ccIs0QDV.o(.text+0x1277): In function `TsuPod::sortSongList()':
: undefined reference to `Song::Song(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)'
/tmp/ccIs0QDV.o(.text+0x13ef): In function `TsuPod::sortSongList()':
: undefined reference to `Song::Song(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)'
/tmp/ccIs0QDV.o(.text+0x1695): In function `TsuPod::sortSongList()':
: undefined reference to `Song:: operator>(Song const&)'
/tmp/ccIs0QDV.o(.gnu.linkonce.t._ZN6TsuPod8SongNodeC1Ev+0x60): In function `TsuPod::SongNode::SongNode()':
: undefined reference to `Song::Song(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)'
collect2: ld returned 1 exit status
make: *** [tsuPod.o] Error 1

 

nickbits

Diamond Member
Mar 10, 2008
4,122
1
81
Those errors are from linking not compiling. I think your source files are OK and your make file has something wrong. Notice it is complaining about missing the main function as well as the overloads.

 

Fullmetal Chocobo

Moderator<br>Distributed Computing
Moderator
May 13, 2003
13,704
7
81
#this is the makefile
final: TsuPod_Driver.o TsuPod.o Song.o
[tab]g++ -otest TsuPod_Driver.o TsuPod.o Song.o
driver: TsuPod_Driver.cpp TsuPod.h Song.h
[tab]g++ TsuPod_Driver.cpp
tsuPod.o: TsuPod.cpp TsuPod.h Song.h
[tab]g++ TsuPod.cpp
song.o: Song.cpp Song.h
[tab]g++ Song.cpp

#[tab] = tab. Whitespace not showing up in normal post.
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
For all of your *.o targets:
1) use 'g++ -c' instead of 'g++'
2) add '-o song.o' or '-o tsuPod.o' as appropriate to the end of each command. e.g.:

song.o: Song.cpp Song.h
[tab]g++ -c Song.cpp -o song.o

In general:
obj.o: source1.cpp header1.h
[tab]compiler -c source1.cpp -o obj1.o
 

Fullmetal Chocobo

Moderator<br>Distributed Computing
Moderator
May 13, 2003
13,704
7
81
It compiles if you just compile the *.cpp files, so my professor don't worry about it, and that he will figure out the makefile error later. That bothers me, but I guess I don't have a choice, as it is up to him anyway. Weird.
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
Originally posted by: Fullmetal Chocobo
#this is the makefile
final: TsuPod_Driver.o TsuPod.o Song.o
[tab]g++ -otest TsuPod_Driver.o TsuPod.o Song.o
driver: TsuPod_Driver.cpp TsuPod.h Song.h
[tab]g++ TsuPod_Driver.cpp
tsuPod.o: TsuPod.cpp TsuPod.h Song.h
[tab]g++ TsuPod.cpp
song.o: Song.cpp Song.h
[tab]g++ Song.cpp

#[tab] = tab. Whitespace not showing up in normal post.

Make is also case sensitive (emphasis added above).

Edit: Aw heck I feel sorry for you. Here's a should-be-working Makefile:

myBinary: TsuPod_Driver.o TsuPod.o Song.o
[tab]g++ -o myBinary TsuPod_Driver.o TsuPod.o Song.o

TsuPod_Driver.o: TsuPod_Driver.cpp TsuPod.h Song.h
[tab]g++ -c TsuPod_Driver.cpp -o TsuPod_Driver.o

TsuPod.o: TsuPod.cpp TsuPod.h Song.h
[tab]g++ -c TsuPod.cpp -o TsuPod.o

Song.o: Song.cpp Song.h
[tab]g++ -c Song.cpp -o Song.o
 

Fullmetal Chocobo

Moderator<br>Distributed Computing
Moderator
May 13, 2003
13,704
7
81
Excellent. That makefile did work. Thank you. Now it segmentation faults when it would apply the shuffle(). Oh well. I'll let the professor sort that one out. Thank you very much.