[Linux, C++] Kompilacja kodu z fstream kończy się błędami

Witam. Próbuję skompilować kod, w którym wykorzystuję bibliotekę fstream. Próba kompilacji kończy się jednak następującymi błędami:

kijek@blaszak:~/Pulpit/f$ gcc -o f main.cpp

/tmp/ccGLdRMp.o: In function `main':

main.cpp:(.text+0x24): undefined reference to `std::basic_fstream >::basic_fstream()'

main.cpp:(.text+0x30): undefined reference to `std::basic_string, std::allocator >::basic_string()'

main.cpp:(.text+0x4c): undefined reference to `std::basic_fstream >::open(char const*, std::_Ios_Openmode)'

main.cpp:(.text+0x62): undefined reference to `std::basic_istream >& std::getline, std::allocator >(std::basic_istream >&, std::basic_string, std::allocator >&)'

main.cpp:(.text+0x71): undefined reference to `std::cout'

main.cpp:(.text+0x76): undefined reference to `std::basic_ostream >& std::operator<< , std::allocator >(std::basic_ostream >&, std::basic_string, std::allocator > const&)'

main.cpp:(.text+0x7e): undefined reference to `std::basic_ostream >& std::endl >(std::basic_ostream >&)'

main.cpp:(.text+0x86): undefined reference to `std::basic_ostream >::operator<<(std::basic_ostream >& (*)(std::basic_ostream >&))'

main.cpp:(.text+0x97): undefined reference to `std::basic_ios >::eof() const'

main.cpp:(.text+0xaf): undefined reference to `std::basic_string, std::allocator >::~basic_string()'

main.cpp:(.text+0xbb): undefined reference to `std::basic_fstream >::~basic_fstream()'

main.cpp:(.text+0xdd): undefined reference to `std::basic_string, std::allocator >::~basic_string()'

main.cpp:(.text+0xed): undefined reference to `std::basic_fstream >::~basic_fstream()'

/tmp/ccGLdRMp.o: In function `__static_initialization_and_destruction_0(int, int)':

main.cpp:(.text+0x128): undefined reference to `std::ios_base::Init::Init()'

main.cpp:(.text+0x12d): undefined reference to `std::ios_base::Init::~Init()'

/tmp/ccGLdRMp.o:(.eh_frame+0x13): undefined reference to `__gxx_personality_v0'

collect2: ld returned 1 exit status

Tutaj przykładowy kod:

#include 

#include 

#include 


using namespace std;


int main()

{

	fstream Plik;

	string Zawartosc;


	Plik.open("plik", ios::in);


	while(!Plik.eof())

	{

		getline(Plik, Zawartosc);

		cout << Zawartosc << endl;

	}


	return 0;

}

Wydaje mi się, że kod jest w porządku, ponieważ pod Windowsem w Code::Blocks kompilacja przebiegła sprawnie. Tak więc jak pozbyć się tych błędów?

To C++, a więc kompiluj g++.

Ale idiotyczny błąd :smiley: Nawet nie wiem, czemu użyłem gcc ale to już bez znaczenia. Ważne jest to, że działa. Dzięki :slight_smile: