简体   繁体   English

.cpp文件在编译后消失了

[英].cpp file vanishes after compilation

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. 本质上,我正在制作一个简单的OOP项目,其中涉及EMACS中的伪造银行帐户,并且在编译期间,带有我所有课程代码的.cpp文件消失了。

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. 如您所见,BankAccount.cpp刚好在编译后消失。 What happened and is there anyway to recover the file? 发生了什么事,还有恢复文件的方法吗?

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 . 您正在告诉g++编译main.cpp ,并将输出写入名为BankAccount.cpp的文件。 So you over-write your source file with an executable. 因此,您用可执行文件覆盖了源文件。

juanchopanza explained what happened. juanchopanza解释了发生了什么。

Depending on the way your Filesystem operates, there is still a ( slim, tiny ) chance however to retrieve part (or all) of it... : 根据文件系统的操作方式,仍然有( 微小,微小 )机会来检索其中的一部分(或全部)...:

df .  #to see which /dev/something partition is holding that current directory
dd if='/dev/something' of=- | cat -v | grep -n 'a_specific_string'  2>/dev/null | less

and be veeery patient 并要有耐心
a_specific_string being a string that you know was in that file (and if possible probably nowhere else, to narrow down the search). a_specific_string是您知道该文件中的字符串(如果可能,可能没有其他地方可以缩小搜索范围)。

Then once you get some line numbers, you can dig around (note however that it's entirely possible that the file, if still somewhere, may be split among several different areas of the disk's partition, if your file was over an inode's length) 然后,一旦获得一些行号,就可以进行挖掘(但是请注意,如果文件超过了inode的长度,那么即使文件仍在某个地方,也很有可能会在磁盘分区的多个不同区域之间进行拆分)

Then you could use the line numbers to retrieve the whole file 然后,您可以使用行号来检索整个文件

for example, if you only foudn it at line nnnn : 例如,如果仅在nnnn行添加:

 dd if='/dev/something' of='-' | cat -v | awk ' ( (NR > (nnnn - 100) ) && (NR < (nnnn+100) ) { print ; }'  

(Printing 99 lines before up to 100 lines after the matching line) (在匹配行之后最多打印100行之前打印99行)
(Adjust it more closely if you can, depending on the line you looked for and its place in the file) (如果可能,请更仔细地调整它,具体取决于要查找的行及其在文件中的位置)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Linux中编译后以这样的方式编译c / cpp代码以提供经过预处理的汇编文件和目标文件? - how to compile c/cpp code in such a way that it gives preprocessed assembled and object file after compilation in linux? 在.cpp中调用.o文件的函数时的编译问题 - Compilation issue in calling function of .o file in .cpp Eclipse问题-编译期间不考虑.c和.cpp文件中定义的预处理 - Eclipse Issue - Preprocess defined in .c & .cpp file are not considered during compilation cpp/c++ 编译错误:combaseapi.h - 没有那个文件或目录 - cpp/c++ compilation error: combaseapi.h - No such file or directory #包括 <afxinet.h> 在头文件中会导致很多编译错误,但是,将其包含在cpp文件中是可以的 - #include <afxinet.h> in a header file causes a lot of compilation error, however, include it in a cpp file is ok C ++:包含头文件编译失败,但包含源cpp文件编译 - C++: Including header-file fails compilation but including source cpp file compiles 为什么要包括 <string.h> .cpp文件中的文件导致编译错误(同时包括.h文件也可以) - Why including <string.h> in .cpp file causes compilation errors (while including it .h file is ok) 来自.h和.cpp的条件编译 - Conditional compilation from .h and .cpp iOS项目中的cpp编译问题 - cpp compilation issues in iOS project cc1plus.exe:致命错误:world.cpp:没有此类文件或目录编译终止 - cc1plus.exe: fatal error: world.cpp: No such file or directory compilation terminated
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM