c++ - 我有 libstdc++6-dev 但仍然有 STL 链接错误

标签 c++ linux stl debian gcc4.7

我的gcc版本是4.7

这是我的简单源代码: 我安装了libstdc++6-dev,我认为它应该包含STL

#include <iostream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/convex_hull_2.h>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_2 Point_2;
using namespace std;
int main()
{
Point_2 points[5] = { Point_2(0,0), Point_2(10,0), Point_2(10,10), Point_2(6,5), Point_2(4,1) };
Point_2 result[5];
Point_2 *ptr = CGAL::convex_hull_2( points, points+5, result );
std::cout << ptr - result << " points on the convex hull" << std::endl;
return 0;
}

我的编译命令是:

gcc -c hello.cpp -o hello.o
gcc -o hello hello.o 1>info.txt 2>error.txt

错误是:

hello.o: In function `main':
hello.cpp:(.text+0x156): undefined reference to `std::cout'
hello.cpp:(.text+0x15b): undefined reference to `std::ostream::operator<<(long)'
hello.cpp:(.text+0x168): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'

...

STL库好像还是不行,但是我安装了libstdc++6-dev,为什么还是这样?

最佳答案

正如 chris 所说,gcc 不适用于 C++。您可以使用两种不同的方法来解决您的问题

gcc -c hello.cpp -o hello.o
gcc -lstdc++ -o hello hello.o 1>info.txt 2>error.txt

g++ -c hello.cpp -o hello.o
g++ -o hello hello.o 1>info.txt 2>error.txt

关于c++ - 我有 libstdc++6-dev 但仍然有 STL 链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19885847/

相关文章:

linux - 如何计算 nice cpu 百分比,例如在顶部?

linux - read -p 使用 korn shell ksh 返回 "read: no query process"

访问成员 STL 映射时的 C++ 段错误

c++ - boost::managed_shared_memory 可以正确处理 vector 吗?

c++ - map C++ 中的迭代器失效

c++ - OpenCV/C++ 中的优化帮助

c++ - 自定义转换运算符的 Clang 歧义

c++ - 枚举唯一的无向路径的有效方法

c++ - 修改 std::vector 的底层数据结构不会改变它的大小

java - Hbase客户端连接失败