2010-06-21 22 views
19

Sto cercando di compilare un gioco, ma ottenendo più di 100 errori come:C++ errori durante la compilazione

C:\Users\AppData\Local\Temp\cctQCagR.o: In function `load_image(std::string)': 
main.cpp:(.text+0x4bd4): undefined reference to `std::string::c_str() const' 
C:\Users\Bill\AppData\Local\Temp\cctQCagR.o: In function `createShip(float, float)': 
main.cpp:(.text+0x4da4): undefined reference to `std::allocator<char>::allocator()' 
main.cpp:(.text+0x4dbc): undefined reference to `std::basic_string<char, std::char_tra 
its<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> cons 
t&)' 
main.cpp:(.text+0x4de4): undefined reference to `std::basic_string<char, std::char_tra 
its<char>, std::allocator<char> >::~basic_string()' 
main.cpp:(.text+0x4e04): undefined reference to `std::basic_string<char, std::char_tra 
its<char>, std::allocator<char> >::~basic_string()' 
main.cpp:(.text+0x4e1c): undefined reference to `std::allocator<char>::~allocator()' 
main.cpp:(.text+0x4e28): undefined reference to `std::allocator<char>::allocator()' 
main.cpp:(.text+0x4e40): undefined reference to `std::basic_string<char, std::char_tra 
its<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> cons 
t&)' 
main.cpp:(.text+0x4e60): undefined reference to `std::allocator<char>::~allocator()' 
main.cpp:(.text+0x4e70): undefined reference to `__cxa_end_cleanup' 
main.cpp:(.text+0x4e98): undefined reference to `std::basic_string<char, std::char_tra 
its<char>, std::allocator<char> >::~basic_string()' 
main.cpp:(.text+0x4eb8): undefined reference to `std::basic_string<char, std::char_tra 
its<char>, std::allocator<char> >::~basic_string()' 
main.cpp:(.text+0x4ed0): undefined reference to `std::allocator<char>::~allocator()' 
main.cpp:(.text+0x4ef4): undefined reference to `std::allocator<char>::~allocator()' 
main.cpp:(.text+0x4f04): undefined reference to `__cxa_end_cleanup' 
C:\Users\Bill\AppData\Local\Temp\cctQCagR.o: In function `load_files()': 
main.cpp:(.text+0x5164): undefined reference to `std::allocator<char>::allocator()' 
main.cpp:(.text+0x517c): undefined reference to `std::basic_string<char, std::char_tra 
its<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> cons 
t&)' 
+1

Si sta collegando alla libreria standard C++, giusto? –

+0

È possibile incollare il comando che si sta utilizzando per compilare? – Anthony

+0

Utilizzo: arm-none-linux-gnueabi-gcc ............ per compilare –

risposta

55

credo che si sta cercando di compilare main.cpp con gcc invece di g ++.

#include <string> 
#include <stdio.h> 
int main() 
{ 
    std::string bla; 
    bla = "BLA BLA"; 
    printf("%s\n",bla.c_str()); 
    return 0; 
} 

Se si genera lo snippet di codice sopra con gcc si ottengono gli errori che si menzionano. Se si usa g ++, si costruisce bene, questo ha senso dato che g ++ si assicurerà tutte le cose che mette insieme quando costruisce C++.

+0

Qual è la considerazione di gcc per lasciarlo fuori? –

18

È necessario collegare il file binario con libstdC++. È necessario specificarlo esplicitamente nella riga di comando se si utilizza gcc. gcc -lstdc++ tmp.cpp
Se si utilizza g ++, libstdC++ verrà collegato per impostazione predefinita.
g++ tmp.cpp

Problemi correlati