1

I'm using Fedora 18 (with Gnome), I have installed gcc and gcc-c++, when I used gcc -o slowka.o slowka.cpp command I saw following errors :

slowka.cpp:(.text+0x1b): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'
slowka.cpp:(.text+0x8d): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
slowka.cpp:(.text+0xa0): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/ccp7fTFJ.o: In function `__static_initialization_and_destruction_0(int, int)':
slowka.cpp:(.text+0xdb): undefined reference to `std::ios_base::Init::Init()'
slowka.cpp:(.text+0xea): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccp7fTFJ.o: In function `bool std::operator==<char, std::char_traits<char>, std::allocator<char> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*)':
slowka.cpp:(.text._ZSteqIcSt11char_traitsIcESaIcEEbRKSbIT_T0_T1_EPKS3_[_ZSteqIcSt11char_traitsIcESaIcEEbRKSbIT_T0_T1_EPKS3_]+0x1f): undefined reference to `std::string::compare(char const*) const'
/tmp/ccp7fTFJ.o:(.eh_frame+0x13): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status

I don't know what is the reason of it. My code :

#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main()
{
printf("Witaj w aplikacji dodającej słówka ! Czy chcesz włączyć aplikację w tryb permanentny (t/N) ?\n");
string x;
scanf("%s", &x);
if(x != "t" && x != "T")
{
printf("Wybrano tryb \"jednego słówka\" !\n");
return 0;
}
return 0;
}
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
TN888
  • 7,659
  • 9
  • 48
  • 84

1 Answers1

4

Normally, you'd use the C++ compiler to link a C++ program:

g++ -o slowka.o slowka.cpp

However, if you want an object file, you'd specify -c:

g++ -c -o slowka.o slowka.cpp

or perhaps:

gcc -c -o slowka.o slowka.cpp

(And the output name would inferred automatically by the compiler, so the -o slowka.o is optional.)

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278