无法编译c++程序
Unable to compile C++ program
我试着在Ubuntu上编译。所以我输入了这么小的程序:
#include <iostream>
using namespace std;
int main(){
int cases;
cin>>cases;
return 0;
}
这个给出了很多错误:
umair@ubuntu:~/cpp$ gcc -Wall -W -Werror 2.cpp -o 1
/tmp/ccU4nAIg.o: In function `main':
2.cpp:(.text+0x10): undefined reference to `std::cin'
2.cpp:(.text+0x15): undefined reference to `std::istream::operator>>(int&)'
/tmp/ccU4nAIg.o: In function `__static_initialization_and_destruction_0(int, int)':
2.cpp:(.text+0x4d): undefined reference to `std::ios_base::Init::Init()'
2.cpp:(.text+0x5c): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccU4nAIg.o:(.eh_frame+0x13): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status
我可以很容易地在"C"中做到这一点。
用g++
代替gcc
来构建c++程序
虽然gcc
知道如何编译 c++,但默认情况下,它不会链接针对程序所需的c++库。
从手册:
<>之前编译c++程序c++源文件通常使用。C、。cc、。cpp、。cpp、.c++、。cp或。cxx;c++头文件通常使用。hh或。h;和预处理的c++文件使用后缀.ii。GCC识别具有这些名称的文件并进行编译即使您以与for相同的方式调用编译器,它们也可以作为c++程序使用编译C程序(通常命名为gcc)。然而,使用gcc并不会增加c++库。g++是一个程序调用GCC并将。C,。h和。i文件视为c++源文件而不是C源文件,除非使用-x,并自动指定指向的链接c++库。这个程序在预编译C头文件时也很有用带有.h扩展名,以便在c++编译中使用。在许多系统上,g++也是以c++的名字安装。编译c++,调用g++
而不是gcc
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- C++,系统无法执行指定的程序
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 重载操作程序时出错>>用于类中的字符串 memebr
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 试图在visual studio上用C++创建一个桌面应用程序
- 模板元程序查找相似的连续类型名称
- FFmpeg:制作一个应用程序比直接使用ffmepg更好吗
- 如何通过cpp程序运行shell脚本
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- IPC使用多个管道和分支进程来运行Python程序
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- 使用C++程序合并排序没有得到正确的输出
- 基于boost的程序的静态链接——zlib问题
- 程序崩溃并显示"std::out_of_range"错误
- 在C应用程序中运行C++(带有STL)函数
- 使用mongocxx驱动程序时包含头文件问题
- 如何在c++程序中找到函数的地址