无法编译简单的 c++ Ubuntu 中的程序
我尝试在终端中构建一个简单的程序。
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("TESTING");
return 1;
}
我运行了 g++ -o test test.cpp
错误:
/usr/include/features.h:323:26: error: bits/predefs.h: No such file or directory
/usr/include/features.h:356:25: error: sys/cdefs.h: No such file or directory
/usr/include/features.h:388:23: error: gnu/stubs.h: No such file or directory
In file included from test.cpp:2:
/usr/include/stdlib.h:42:29: error: bits/waitflags.h: No such file or directory
/usr/include/stdlib.h:43:30: error: bits/waitstatus.h: No such file or directory
/usr/include/stdlib.h:320:49: error: sys/types.h: No such file or directory
In file included from test.cpp:2:
/usr/include/stdlib.h:35: error: ‘__BEGIN_DECLS’ does not name a type
/usr/include/stdlib.h:102: error: expected constructor, destructor, or type conversion before ‘;’ token
/usr/include/stdlib.h:113: error: ‘__END_NAMESPACE_STD’ does not name a type
/usr/include/stdlib.h:122: error: expected constructor, destructor, or type conversion before ‘;’ token
/usr/include/stdlib.h:140: error: expected constructor, destructor, or type conversion before ‘extern’
/usr/include/stdlib.h:145: error: expected constructor, destructor, or type conversion before ‘extern’
/usr/include/stdlib.h:149: error: expected initializer before ‘__THROW’
/usr/include/stdlib.h:152: error: expected initializer before ‘__THROW’
/usr/include/stdlib.h:153: error: ‘__END_NAMESPACE_STD’ does not name a type
/usr/include/stdlib.h:160: error: ‘__END_NAMESPACE_C99’ does not name a type
/usr/include/stdlib.h:168: error: ‘__END_NAMESPACE_STD’ does not name a type
列表以这种方式继续。我希望有人能指出我没有做些什么来使这项工作成功。
I tried to build a simple program in the terminal.
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("TESTING");
return 1;
}
I ran g++ -o test test.cpp
The errors:
/usr/include/features.h:323:26: error: bits/predefs.h: No such file or directory
/usr/include/features.h:356:25: error: sys/cdefs.h: No such file or directory
/usr/include/features.h:388:23: error: gnu/stubs.h: No such file or directory
In file included from test.cpp:2:
/usr/include/stdlib.h:42:29: error: bits/waitflags.h: No such file or directory
/usr/include/stdlib.h:43:30: error: bits/waitstatus.h: No such file or directory
/usr/include/stdlib.h:320:49: error: sys/types.h: No such file or directory
In file included from test.cpp:2:
/usr/include/stdlib.h:35: error: ‘__BEGIN_DECLS’ does not name a type
/usr/include/stdlib.h:102: error: expected constructor, destructor, or type conversion before ‘;’ token
/usr/include/stdlib.h:113: error: ‘__END_NAMESPACE_STD’ does not name a type
/usr/include/stdlib.h:122: error: expected constructor, destructor, or type conversion before ‘;’ token
/usr/include/stdlib.h:140: error: expected constructor, destructor, or type conversion before ‘extern’
/usr/include/stdlib.h:145: error: expected constructor, destructor, or type conversion before ‘extern’
/usr/include/stdlib.h:149: error: expected initializer before ‘__THROW’
/usr/include/stdlib.h:152: error: expected initializer before ‘__THROW’
/usr/include/stdlib.h:153: error: ‘__END_NAMESPACE_STD’ does not name a type
/usr/include/stdlib.h:160: error: ‘__END_NAMESPACE_C99’ does not name a type
/usr/include/stdlib.h:168: error: ‘__END_NAMESPACE_STD’ does not name a type
The list continues this way. Im hoping someone can point out what I haven't done to make this work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的代码适用于同一平台的我。
错误消息看起来像 C 错误。也许使用 C++ 头文件会有所帮助。
您可能还有一些奇怪的别名。有时人们错误地将 gcc 设置为 g++ 的别名。
这就是我在 ubuntu 中设置开发环境的方式:
这设置了所有标准 C++ 库,而无需了解具体细节。
Your code works for me with the same platform.
The error messages look like C errors. Perhaps using the C++ headers will help.
You may also have some weird aliases. Sometimes people setup gcc as an alias for g++ incorrectly.
This is how I setup my dev environment in ubuntu:
This sets up all the standard C++ libraries without needing to know the knitty gritty details.
我遇到了与此非常相似的问题。就我而言,问题是我有一些损坏的头文件,通过尝试查看它们可以证明:
我的解决方案是清除这些文件,然后重新安装它们。
I was having a very similar issue to this. In my case the issue was that I had some corrupted header files as evidenced by trying to view them:
The solution for me was to purge these files and then re-install them.
解决方案:由于之前的一些尝试,我的路径是空的。我使用以下命令创建了一个干净的路径:
编译后我的问题是程序不会显示任何结果。这是因为作为一个新的 Linux 用户,我没有意识到我需要调用前面带有 ./ 的程序。这也可以通过调用在路径中设置:
SOLUTION: My path was empty due to some previous attempts at making it work. I created a clean path using:
My problem after compiling was that the program wouldn't show any results. This was due to the fact that as a new linux user I didnt realize I needed to call a program with ./ in front. This can be set in the path as well by calling: