compiling .cpp with gcc
compiling .cpp with gcc
好吧,这是我无意中做的,使用gcc而不是g++编译.cpp
但我实际上想逐行理解控制台的输出,如果它有意义的话。
struct a{
int pointer;
int rollno;
};
struct a student,*studentref;
studentref = &student;
studentref->rollno = 141;
studentref->pointer = 8;
cout<<studentref->rollno<<") : "<<studentref->pointer<<endl;
使用gcc structpointers.cpp -o structp
编译此代码会得到以下输出:
sourab@sourab:/home/gbear/coding/learningds$ gcc structpointers.cpp -o structp
/tmp/ccXrq1Cv.o: In function `main':
structpointers.cpp:(.text+0x2e): undefined reference to `std::cout'
structpointers.cpp:(.text+0x33): undefined reference to `std::ostream::operator<<(int)'
structpointers.cpp:(.text+0x38): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
structpointers.cpp:(.text+0x40): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/tmp/ccXrq1Cv.o: In function `__static_initialization_and_destruction_0(int, int)':
structpointers.cpp:(.text+0x6e): undefined reference to `std::ios_base::Init::Init()'
structpointers.cpp:(.text+0x7d): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
在.cpp
文件上调用g++
和gcc
之间最显著的区别是g++
在C++标准库中自动链接,而gcc
没有;您看到的所有错误都是缺少对C++标准库提供的内容的引用的链接器错误。
(请注意,这并不是唯一的差异;有关详细信息,请参阅此问题)
g++和gcc是GNU编译器集合的编译器驱动程序,它们有后端,一旦编译模式启动,它们就会自动连接。像""这样的错误
structpointers.cpp:(.text+0x2e): undefined reference to `std::cout'
是链接错误,因为您使用了gcc来编译cpp,所以不存在专门用于cpp的标准库,所以它找不到std::cout等语法。
您也可以参考:使用g++编译
相关文章:
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 奇怪的结构&GCC&clang(void*返回类型)
- GCC本机矩阵运算库
- PowerPC ppc64le上的Gcc Woverloaded虚拟错误
- gcc和c++17的过载解析失败
- 数据成员SFINAE的C++17测试:gcc vs clang
- GCC对可能有效的代码抛出init list生存期警告
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- 如何在 GCC 中启用 C/C++ "Conditional with Omitted Operand"(又名猫王操作员 "?:" )
- 在独立(裸金属)项目上使用std::tuple with arm none eabi gcc
- 不理解 gcc --with-local-prefix, --with-native-system-header-dir=
- Boost 1.49/1.50/1.51 ASIO with MinGW & GCC 4.7.0 中的转换错误
- gcc 未给出的 Clang 错误"attempted to construct a reference element in a tuple with an rvalue"
- GCC with Cygwin/Win7: missing syscall.h
- GCC with Windows SDK?
- compiling .cpp with gcc
- icpc C++11 with gcc stdlib
- templates C++ with GCC
- Eclipse CDT with MinGW GCC Make Error 127
- #pragma pack(show) with GCC