2010-06-21 3 views
19

Я пытаюсь собрать игру, но получает 100+ ошибок как:C++ ошибки при компиляции

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

Вы связываетесь со своей стандартной библиотекой C++, правильно? –

+0

Можете ли вы вставить команду, которую вы используете для компиляции? – Anthony

+0

Использование: arm-none-linux-gnueabi-gcc ............ для компиляции –

ответ

55

Я считаю, что вы пытаетесь скомпилировать main.cpp с GCC вместо г ++.

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

Если вы построите приведенный выше фрагмент кода с помощью gcc, вы получите упоминаемые вами ошибки. Если вы используете g ++, он строит ok, это имеет смысл, так как g ++ будет уверен в том, что все необходимые материалы собраны при сборке C++.

+0

Что такое gcc, чтобы оставить его? –

18

Вам нужно связать свой двоичный файл с libstdC++. Вы должны явно указать его в командной строке, если используете gcc. gcc -lstdc++ tmp.cpp
Если вы используете g ++, libstdC++ будет связан по умолчанию.
g++ tmp.cpp

Смежные вопросы