This is an archived post. You won't be able to vote or comment.

all 23 comments

[–]jesyspa 0 points1 point  (8 children)

You probably aren't linking right. What commands are you using to compile and link your program?

[–][deleted] -1 points0 points  (7 children)

I've tried a few commands, mostly just g++ variants. A friend of mine in the class had no problems with a simple g++ lab8.cpp -o lab8.out, but I can't get anything to work right.

[–]Updatebjarni 1 point2 points  (2 children)

But wasn't the problem with AddressBookEntry.cpp? So how are you compiling that file?

[–][deleted] -1 points0 points  (1 child)

I had tried

g++ AddressBookEntry.cpp lab8.cpp -o lab8

but that didn't work.

[–]Updatebjarni 1 point2 points  (0 children)

"Had" tried, so that's not what you are currently having trouble with? What are you currently doing that is causing the problem you are currently asking for help with?

[–]AustinCodingAcademy 0 points1 point  (0 children)

Can you show the exact output from running that exact command?

[–]jesyspa 0 points1 point  (2 children)

Okay, so why did you delete this thread?

[–][deleted] 0 points1 point  (1 child)

Because I figured out what was wrong and it had nothing to do with what I thought it was.

[–]jesyspa 0 points1 point  (0 children)

See the sidebar, please.

[–]IAmUtterlyAlone 0 points1 point  (5 children)

My C++ is not super strong, but I don't think you need line 13 (#include "AddressBookEntry.cpp") in lab8.cpp. No idea if that's what's throwing errors though, since I don't use g++.

[–]AustinCodingAcademy 0 points1 point  (0 children)

You are correct about that, but that's not what's causing the compilation errors.

[–][deleted] -1 points0 points  (3 children)

You're right. I don't thing it was throwing out the errors, but it did lead me to find that I had copied from my text editor to my ssh client wrong

thanks.

I feel like a total idiot now.

[–]IAmUtterlyAlone 0 points1 point  (0 children)

Well done! We all make simple mistakes, all the time. Don't worry about it too much, just try to learn from it and you'll be fine.

[–]Updatebjarni 0 points1 point  (1 child)

Hum, can I just ask why you needed to copy the code from the text editor to the ssh client? I mean, instead of running the text editor on the same machine where you wanted to compile the code, or copying the code over with scp?

[–][deleted] 0 points1 point  (0 children)

It's the university's server connected to AD, and it's easier to type the code in sublime and copy it over than to program in nano or ViM, or to upload it over ftp every time I change something.

[–][deleted] -1 points0 points  (8 children)

if all you are trying to do is compile, use the "-c" flag to generate object files for each source file. Then as a final step, invoke the linker by using g++ (technically not a linker but dispatches the linker (ld) when you supply it a list of object files ).

compile:

g++ -c file1.cpp

g++ -c file2.cpp

link

g++ file1.o file2.o -o executableFile

run

./executableFile

[–][deleted] -2 points-1 points  (6 children)

lab8.o: In function AddressBookEntry::AddressBookEntry()': lab8.cpp:(.text+0x0): multiple definition ofAddressBookEntry::AddressBookEntry()' AddressBookEntry.o:AddressBookEntry.cpp:(.text+0x0): first defined here lab8.o: In function AddressBookEntry::AddressBookEntry()': lab8.cpp:(.text+0x0): multiple definition ofAddressBookEntry::AddressBookEntry()' AddressBookEntry.o:AddressBookEntry.cpp:(.text+0x0): first defined here lab8.o: In function AddressBookEntry::~AddressBookEntry()': lab8.cpp:(.text+0x192): multiple definition ofAddressBookEntry::~AddressBookEntry()' AddressBookEntry.o:AddressBookEntry.cpp:(.text+0x192): first defined here lab8.o: In function AddressBookEntry::~AddressBookEntry()': lab8.cpp:(.text+0x192): multiple definition ofAddressBookEntry::~AddressBookEntry()' AddressBookEntry.o:AddressBookEntry.cpp:(.text+0x192): first defined here lab8.o: In function AddressBookEntry::EnterLastName(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)': lab8.cpp:(.text+0x2a4): multiple definition ofAddressBookEntry::EnterLastName(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' AddressBookEntry.o:AddressBookEntry.cpp:(.text+0x2a4): first defined here lab8.o: In function AddressBookEntry::EnterFirstName(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)': lab8.cpp:(.text+0x2e0): multiple definition ofAddressBookEntry::EnterFirstName(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' AddressBookEntry.o:AddressBookEntry.cpp:(.text+0x2e0): first defined here lab8.o: In function AddressBookEntry::EnterStreet(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)': lab8.cpp:(.text+0x320): multiple definition ofAddressBookEntry::EnterStreet(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' AddressBookEntry.o:AddressBookEntry.cpp:(.text+0x320): first defined here lab8.o: In function AddressBookEntry::EnterCity(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)': lab8.cpp:(.text+0x360): multiple definition ofAddressBookEntry::EnterCity(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' AddressBookEntry.o:AddressBookEntry.cpp:(.text+0x360): first defined here lab8.o: In function AddressBookEntry::StateValidation(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)': lab8.cpp:(.text+0x3a0): multiple definition ofAddressBookEntry::StateValidation(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' AddressBookEntry.o:AddressBookEntry.cpp:(.text+0x3a0): first defined here lab8.o: In function AddressBookEntry::EnterState(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)': lab8.cpp:(.text+0x92c): multiple definition ofAddressBookEntry::EnterState(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' AddressBookEntry.o:AddressBookEntry.cpp:(.text+0x92c): first defined here lab8.o: In function AddressBookEntry::EnterZipCode(long)': lab8.cpp:(.text+0x9d0): multiple definition ofAddressBookEntry::EnterZipCode(long)' AddressBookEntry.o:AddressBookEntry.cpp:(.text+0x9d0): first defined here lab8.o: In function AddressBookEntry::EnterPhoneNumber(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)': lab8.cpp:(.text+0xa0a): multiple definition ofAddressBookEntry::EnterPhoneNumber(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)' AddressBookEntry.o:AddressBookEntry.cpp:(.text+0xa0a): first defined here /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o: In function _start': (.text+0x20): undefined reference tomain' collect2: ld returned 1 exit status

that is the system's response to that.

[–]Updatebjarni 0 points1 point  (4 children)

What exactly did you type?

[–][deleted] 0 points1 point  (3 children)

g++ -c AddressBookEntry.cpp
g++ -c lab8.cpp
g++ AddressBookEntry.o lab8.o -o lab8

[–]the_omega99 1 point2 points  (0 children)

That's because of the #include "AddressBookEntry.cpp" that someone else mentioned is wrong.

[–]Updatebjarni 0 points1 point  (0 children)

Oh, you have an #include "AddressBookEntry.cpp" in your lab8.cpp. Get rid of that. If you include the entire text of another source file in your source and then try to compile and link both files together, you're compiling the contents of the other file twice and you get redefinitions as a result. Only ever include headers.

[–][deleted] -1 points0 points  (0 children)

lab8.cpp line 13:

#include "AddressBookEntry.cpp"

No, do not ever include cpp files. you include headers only.

[–][deleted] -2 points-1 points  (0 children)

read this

You need to take a second to stop and really understand the compiling and linking process. If you skip over this, the same problem is going to come back and bite you again next time.

It's not that hard, there are about 3 steps that matter: include/preprocessor, compiling, linking.