0

I am writing code for a project on a raspberry pi via ssh and using g++ to compile my files. My header files are contained in a directory called headers and my codefiles in a directory called codefiles. To compile, I run this code.

g++ -I headers -o test codefiles/*.cpp

It has been working fine since I started the project, until today when it gave me this error:

/usr/bin/ld: /tmp/ccZXxmDc.o: in function `main': main.cpp:(.text+0x48): undefined reference to `File::readFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)' /usr/bin/ld: main.cpp:(.text+0x94): undefined reference to `File::saveFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)' collect2: error: ld returned 1 exit status

I went to check the file.cpp file and it was completely gone from my directory. Why is this happening?

Edit for a little more context: this happened multiple times, giving the same error. The first time it happened was a smaller code file that I rewrote and when tried to compile it got rid of the file.cpp file.

  • 2
    I don't think g++ will delete your source code. Most likely it was deleted accidentally. Run `history` in all terminals to check the commands you run. – sxu Oct 22 '22 at 03:20
  • Be careful of the `-o` parameter, it wont delete your file but you can mistakenly tell your compiler to name your executable `file.cpp` – drescherjm Oct 22 '22 at 03:24
  • https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – Jesper Juhl Oct 22 '22 at 03:37
  • Even with `-o file.cpp` parameter, it will not delete `file.cpp`. It will overwrite it. – sxu Oct 22 '22 at 03:55
  • @JaMiT No, I'm certain it is g++ because it happened multiple times. The first time it happened, it deleted a fairly short .cpp file that I know was there before compilation. I rewrote that file and tried again and it took the file.cpp file. – Matt Mangels Oct 22 '22 at 04:09
  • 3
    Corrupted file system and / or SD card on the Raspberry Pi? I can't see how it would be g++. Suggest backing things up while you still can, just in case! – Tony Oct 22 '22 at 04:19
  • 1
    Shot in the dark guess: Wildcard expansion of `codefiles/*.cpp` is corrupting your command line. For example if any of your .cpp files have spaces in their names.... – selbie Oct 22 '22 at 07:37

0 Answers0