2013-08-30 5 views
1

J'utilise Fedora 18 (avec Gnome), je l'ai installé gcc et gcc-C++, quand je commande gcc -o slowka.o slowka.cpp j'ai vu les erreurs suivantes:étrange erreur lors de la compilation application

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 

Je ne sais pas quelle est la raison de cela? Mon 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; 
} 
+1

Utilisez 'g ++' à la place. –

+0

Utilisez 'g ++' au lieu de' gcc' ou ajoutez '-lstdC++' à la ligne de commande pour lier dans la bibliothèque d'exécution C++. –

Répondre

4

Normalement, vous devriez utiliser le compilateur C++ pour lier un programme C++:

g++ -o slowka.o slowka.cpp 

Cependant, si vous voulez un fichier objet, vous souhaitez spécifier -c:

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

ou peut-être:

gcc -c -o slowka.o slowka.cpp 

(Et le nom de sortie serait déduit automatiquement par le compilateur, donc le -o slowka.o est facultatif.)

Questions connexes