如何使用相关标头文件在Linux上编译此C 代码
How to compile this C++ code on Linux with relevant header files?
我试图使用g++
在我的Linux
框中编译此C 代码,但它在以下错误时失败:
enigma/Enigma# g++ -I . main.cpp -o main
In file included from machine.h:14:0,
from tests.h:13,
from main.cpp:10:
plug.h:13:2: warning: #import is a deprecated GCC extension [-Wdeprecated]
#import "util.h"
^~~~~~
/tmp/ccxyoEC2.o: In function `main':
main.cpp:(.text+0x10): undefined reference to `test_machine_encode_decode()'
collect2: error: ld returned 1 exit status
我现在明白我需要将对象文件链接在一起,我使用:
g++ -c *.cpp
g++ *.o -o enig
它仍然不起作用,结果二进制用./enig
执行,但已损坏,并且不按预期运行:
Entire encoded message: TZQA
Decoding now...
Entire decoded message: AHOJ
Entire encoded message: HBIU
Decoding now...
Entire decoded message: AHOJ
Entire encoded message: ZSNE
Decoding now...
Entire decoded message: AHOJ
Entire encoded message: ICRH
它只是不断编码和解码这些随机文本,而不是我上面共享的GIT页面上提到的功能。
我缺少什么?
错误表明编译器无法找到tests.h文件中存在的文件。
不,不是。实际上,编译器成功编译了main.cpp
。
错误表明链接器找不到test_machine_encode_decode
。这并不令人惊讶,因为test_machine_encode_decode
在test.cpp
中定义。您必须链接main.cpp
和test.cpp
的对象文件才能获得完整的可执行文件。
如果您查看实际代码,您会看到MAIM仅调用test_machine_encode_decode()
单位检验。您必须自己实现Readme的功能,或者您搜索GIT历史记录并尝试找出该程序是否过去是否有效。
相关文章:
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 如何从Linux编译到SDL2应用程序到Windows?
- 使用 MINGW 和 CPLEX 库链接从 Linux 编译 Windows 可执行文件
- 如何在Visual Studio中添加Linux编译到Cmake Project
- Linux 编译 - 冲突的库
- Linux C++编译错误
- Linux 编译错误 - 无法将类型"字符串"转换为类型"字符串&&"
- 当我在Windows上运行它时,为什么我的Linux编译二进制不起作用
- 使用Linux g++编译带有附加库的c++程序
- 如何在Windows中为Unix/Linux编译C++应用程序
- c++ Linux 编译错误
- 使用链接linux编译GLFW应用程序问题
- C++新手的 Linux 编译
- Linux编译错误-GCC 4.3.4-模板参数列表太少
- Linux g++ 编译错误:错误:预期的"",""或"..."在"||"标记之前
- Linux g++编译错误:/usr/bin/ld:找不到-l/usr/local/include
- Linux 编译"long distance"兄弟姐妹之间的dynamic_cast失败
- 为较旧的Linux编译c++ 11程序
- 如何安装适用于Mingw Linux编译环境的BerkeleyDB
- Windows Linux c++ 编译问题:"no matching function for call"