Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.cpp file vanishes after compilation

Tags:

c++

linux

emacs

I can't explain how absolutely frustrating this will be if there is no way for me to recover this file. Honestly, I feel like there isn't, but I need to understand what the hell happened so I can take preventative steps in the future. Essentially, I am making a simple OOP Project involving fake bank accounts in EMACS, and during compilation, the .cpp file with all of my class code up and vanishes.

Here are the terminal commands before and after the vanishing file:

    lin114-11:25% ls
    BankAccount.cpp  BankAccount.h  BankAccount.h~  main.cpp
    lin114-11:26% emacs &
    [1] 23359
    lin114-11:27% g++ -o BankAccount.cpp main.cpp
    /tmp/ccEXMM25.o: In function `main':
    main.cpp:(.text+0x67): undefined reference to `CheckingAccount::driver()'
    main.cpp:(.text+0x78): undefined reference to `CheckingAccount::~CheckingAccount()'
    main.cpp:(.text+0xa1): undefined reference to `CheckingAccount::~CheckingAccount()'
    main.cpp:(.text+0xcc): undefined reference to `CheckingAccount::~CheckingAccount()'
    /tmp/ccEXMM25.o: In function `CheckingAccount::CheckingAccount(double, int,                                                                                        
    std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
    main.cpp:(.text._ZN15CheckingAccountC2EdiSs[_ZN15CheckingAccountC5EdiSs]+0x59):
    undefined reference to `vtable for CheckingAccount'
    collect2: ld returned 1 exit status
    lin114-11:28% ls
    BankAccount.h  BankAccount.h~  main.cpp

As you can see, BankAccount.cpp just up and disappears after compilation. What happened and is there anyway to recover the file?

like image 842
The Alex Avatar asked Sep 12 '26 06:09

The Alex


1 Answers

When you do this:

g++ -o BankAccount.cpp main.cpp

you are telling g++ to compile main.cpp, and write the output to a file called BankAccount.cpp. So you over-write your source file with an executable.

like image 83
juanchopanza Avatar answered Sep 14 '26 23:09

juanchopanza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!