无法在Ubuntu中编译简单的c++程序
Cannot compile simple c++ program in Ubuntu
我试图在终端中构建一个简单的程序。
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("TESTING");
return 1;
}
我运行了g++-o测试.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
列表以这种方式继续。我希望有人能指出我没有做些什么来使这件事成功。
您的代码适用于我的同一平台。
错误消息看起来像C错误。也许使用C++标头会有所帮助。
#include <cstdio>
#include <cstdlib>
int main(int argc, char *argv[]) {
printf("TESTING");
return 0;
}
你可能也有一些奇怪的别名。有时人们会错误地将gcc设置为g++的别名。
tom@flim:~$ set | grep g++
tom@flim:~$ alias grep
alias grep='grep --color=auto'
tom@flim:~$ alias g++
bash: alias: g++: not found
tom@flim:~$ which g++
/usr/bin/g++
tom@flim:~$ ll `which g++`
lrwxrwxrwx 1 root root 7 2011-08-14 02:17 /usr/bin/g++ -> g++-4.6*
tom@flim:~$ g++ --version
g++ (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
这就是我在ubuntu:中设置开发环境的方式
sudo apt-get install build-essential
这就建立了所有的标准C++库,而不需要知道细节。
我遇到了一个非常类似的问题。在我的情况下,问题是我有一些损坏的头文件,通过尝试查看它们来证明:
/usr/include/x86_64-linux-gnu/sys$ cat * | grep "Input/outpu error"
cat: ioctl.h: Input/output error
cat: types.h: Input/output error
对我来说,解决方案是清除这些文件,然后重新安装它们。
sudo apt-get purge libc6-dev
sudo apt-get install libc6-dev
解决方案:由于之前的一些尝试,我的路径是空的。我创建了一个干净的路径使用:
export PATH= /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
编译后我的问题是程序不会显示任何结果。这是因为作为一个新的linux用户,我没有意识到我需要用调用一个程序。/在前面。这也可以通过调用在路径中设置
export PATH: $PATH:./
相关文章:
- 在c++中用vector填充一个简单的动态数组
- (C++)分析树以计算返回错误值的简单算术表达式
- 我的简单if-else语句是如何无法访问的代码
- 使用简单类型列表实现的指数编译时间.为什么
- 如何在BST的这个简单递归实现中消除警告
- 一种在C++中读取TXT配置文件的简单方法
- 关于简单C++函数(is_palindrome)的逻辑的问题
- 显示错误输出的简单数组排序程序
- 当无法使用模板和宏时,生成类型变体C++代码的最简单方法是什么?
- 退出简单while循环时出现问题
- 为什么简单的算术减法在"if"条件下不起作用?
- C++-字符串是否包含一个带有简单循环的单词
- 关于 c++ 函数中指针赋值的简单问题
- 从函数返回任意简单类型的数据
- 如何在没有函数的情况下编写此代码并使C++更简单?
- 有没有办法简单地从 GPU 调用多个 cpp 输出文件?
- 在简单示例中,Python3 + ctypes 回调会导致内存泄漏
- 当简单捕获中的标识符显示为参数的声明符 ID 时,没有编译器诊断
- 如何使用 samtools C API 构建一个简单的主.cpp文件
- CPU 瓶颈;处理具有许多非静态对象的 3D 场景渲染的简单方法