Подтвердить что ты не робот

Ошибки С++ при компиляции

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

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&)'
4b9b3361

Ответ 1

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

#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++ будет уверен, что все правильные вещи, которые он собирает вместе, когда строят С++.

Ответ 2

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