Question

My gcc version is 4.7

This is my simple source code: I installed libstdc++6-dev, I think it should include 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;
}

my compile command is:

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

the error is:

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*)'

....

it seems the stl library still not work, but I installed libstdc++6-dev, why it still happened like this?

Was it helpful?

Solution

As chris stated gcc is not for C++. You can solve your problem using two different approaches

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

or

g++ -c hello.cpp -o hello.o
g++ -o hello hello.o 1>info.txt 2>error.txt
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top