NominSim
NominSim

Reputation: 8511

Why does g++ fail on the exact same files, but on different computer

I'm sure I am doing something wrong but... I worked on a c++ project on one computer, with same version of Ubuntu installed, same version of g++, it compiled fine there. I put the files into a DropBox folder so that I could work on it at home, the same exact files are here, and the same exact g++ command results in errors. It is giving me several "multiple definition of '_' " errors.

Does anyone know what I am doing wrong here?

Example error:

g++ -o*.C *.cpp

/tmp/ccdFZtkq.o:(.bss+0x718): multiple definition of `done'

Upvotes: 0

Views: 203

Answers (3)

NominSim
NominSim

Reputation: 8511

The problem was that DropBox was appending suffixes to files that I can best describe as being in "intermediate" states. DropBox also created files without the suffixes that were not in the intermediate states. I am still unsure quite what was happening, but sometime as g++ ran, it was using both the intermediate files and the non-intermediate ones, thereby running into issues of basically the same files being loaded multiple times.

I solved my problem by removing the files from the DropBox folder and recompiling, worked perfectly fine then.

Upvotes: 1

David Schwartz
David Schwartz

Reputation: 182743

You types this into your shell:

g++ -o*.C *.cpp

But this causes your shell to generate the command. Most likely, different commands got generated in the two instances. If you take the actual command issued in the case that worked and repeat that command in the case that didn't work, I bet it would work.

You can find the command by going to the machine where it worked and typing this:

echo g++ -o*.C *.cpp

That will show you the command the shell generated for you. If you try that command on the other machine, I bet it will work.

(Also, your command makes no sense. What was the -o*.C supposed to be? Did you mean -o something *.C?)

Upvotes: 0

P.P
P.P

Reputation: 121347

Do a clean build. Remove all the old object files and compile again.

rm -rf *.o
g++ -o *.C *.cpp

My guess-engine ran out of fuel. Can't give a better answer unless you show some code and info on what are the files there in your DropBox, declaration & definition of done etc.

Upvotes: 0

Related Questions