.cpp文件在编译后消失 [英] .cpp file vanishes after compilation
问题描述
我无法解释如果我无法恢复此文件,绝对会令人沮丧。老实说,我觉得没有,但是我需要明白到底是怎么回事,所以我可以采取预防措施。基本上,我正在制作一个简单的OOP项目,涉及EMACS中的假银行帐户,在编译期间,我的所有类代码的.cpp文件都会消失。
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
如您所见,BankAccount.cpp刚刚起编译后消失。发生了什么事,还有还有什么要恢复文件?
As you can see, BankAccount.cpp just up and disappears after compilation. What happened and is there anyway to recover the file?
推荐答案
当你这样做:
g++ -o BankAccount.cpp main.cpp
你正在告诉 g ++
编译 main.cpp
,并将输出写入一个名为 BankAccount.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.
这篇关于.cpp文件在编译后消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!