Ubuntu 中的 G++ 编译错误
g++ compiling errors in ubuntu
每次我尝试使用 g++ 在 ubuntu 中编译时,都会收到以下错误
g++ test.cpp -o test
/usr/bin/ld: 1: /usr/bin/ld: /bin: Permission denied
/usr/bin/ld: 2: /usr/bin/ld: test.cpp: not found
/usr/bin/ld: 3: /usr/bin/ld: test.cpp: not found
/usr/bin/ld: 4: /usr/bin/ld: test.cpp: not found
/usr/bin/ld: 5: /usr/bin/ld: test.cpp: not found
/usr/bin/ld: 6: /usr/bin/ld: test.cpp: not found
/usr/bin/ld: 7: /usr/bin/ld: test.cpp: not found
/usr/bin/ld: 8: /usr/bin/ld: test.cpp: not found
/usr/bin/ld: 9: /usr/bin/ld: test.cpp: not found
/usr/bin/ld: 10: /usr/bin/ld: test.cpp: not found
/usr/bin/ld: 11: /usr/bin/ld: test.cpp: not found
/usr/bin/ld: 12: /usr/bin/ld: Syntax error: "(" unexpected
我已经多次删除并重新安装了 g++。/usr/bin 和/usr/bin/ld 的 chmod 是 755,奇怪的是我可以运行它g++ -c test.cpp
但是我无法运行 .o 文件。我不完全确定问题是什么。
首先,.o文件不是用来运行的,它应该与其他目标文件(.o)和库(特别是C++和C标准库)链接在一起。但是,我会从您的错误消息中猜测这可能不起作用。
从您的错误消息来看,听起来您可能正在/bin
目录中运行此命令。这是不恰当的。您应该在某个您具有写入权限的目录中运行它(例如您的主目录)。此外,它告诉您它找不到您的测试.cpp文件,您确定已cd
正确的目录吗?
首先,g++ -c test.cpp
只编译或汇编源代码,而不链接。最终输出是一个对象文件。在您的情况下,这是 .o 文件。不能运行 .o 文件。
如上所述g++ -c test.cpp
忽略链接部分,这样就不会使用ld
,这就是g++ -c test.cpp
适合您的原因。
您可以切换到 root 用户并再次运行g++ test.cpp -o test
。如果它有效,则您可能在/usr/bin
或/usr/bin/ld
上遇到权限问题
相关文章:
- 用MacOS Mojave编译C++:致命错误:mpi.h:没有这样的文件或目录
- std::is_base_of表示ctor编译错误
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- Qt5:使用QCommandLineParser类时出现奇怪的编译错误
- Qt Cmake 错误编译"GuiSupportQt not found"
- Opengl 精度转换错误编译错误 E0415
- 库将ARM架构错误编译为架构X64
- RT 音频 Mac 错误 g++ 编译错误
- 错误编译Boost.log
- 错误编译QT创建者 / QT窗口小部件示例
- 错误编译MIPS32
- Visual Studio 2013 中的错误(编译和运行代码)
- 链接错误编译qt项目在visual 2010
- 无法用模板错误编译nsgmls
- 奇怪的错误.编译失败
- 如果有人调用c++中的方法,则强制错误(编译时)
- 来自autoconf测试的错误编译命令
- 时间限制超出错误C++编译
- SFML 2.3 和 CodeBlocks 错误编译