2010-06-21 17 views
19

Estoy intentando compilar un juego, pero conseguir más de 100 errores como:C++ errores durante la compilación

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

¿Está vinculando en contra de su biblioteca estándar de C++, ¿verdad? –

+0

¿Puedes pegar el comando que estás utilizando para compilar? – Anthony

+0

Usando: arm-none-linux-gnueabi-gcc ............ para compilar –

Respuesta

55

creo que está tratando de recopilar main.cpp con gcc en lugar de g ++.

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

Si construye el fragmento de código anterior con gcc, obtendrá los errores que menciona. Si usa g ++, construye bien, esto tiene sentido ya que g ++ se asegurará de que todo el material apropiado se junte cuando compile C++.

+0

¿Cuál es la consideración de gcc para dejarlo fuera? –

18

Necesita vincular su binario con libstdC++. Debe especificarlo explícitamente en la línea de comando si usa gcc. gcc -lstdc++ tmp.cpp
Si usa g ++, libstdC++ se vinculará de forma predeterminada.
g++ tmp.cpp

Cuestiones relacionadas