C++ C++;编译时出错

C++ C++;编译时出错,c++,gcc,C++,Gcc,我正在尝试编译一个游戏,但得到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

我正在尝试编译一个游戏,但得到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&)'
C:\Users\AppData\Local\Temp\cctQCagR.o:在函数“load\u image(std::string)”中:
main.cpp:(.text+0x4bd4):对“std::string::c_str()const”的未定义引用
C:\Users\Bill\AppData\Local\Temp\cctQCagR.o:在函数“createShip(float,float)”中:
main.cpp:(.text+0x4da4):对“std::allocator::allocator()”的未定义引用
main.cpp:(.text+0x4dbc):对'std::basic_string::basic_string(char const*,std::allocator cons.)的未定义引用
t&)'
main.cpp:(.text+0x4de4):对'std::basic_string::~basic_string()'的未定义引用
main.cpp:(.text+0x4e04):对“std::basic_string::~basic_string()”的未定义引用
main.cpp:(.text+0x4e1c):对“std::allocator::~allocator()”的未定义引用
main.cpp:(.text+0x4e28):对“std::allocator::allocator()”的未定义引用
main.cpp:(.text+0x4e40):对'std::basic_string::basic_string(char const*,std::allocator cons.)的未定义引用
t&)'
main.cpp:(.text+0x4e60):对“std::allocator::~allocator()”的未定义引用
main.cpp:(.text+0x4e70):对“\uuucxa\u end\u cleanup”的未定义引用
main.cpp:(.text+0x4e98):对'std::basic_string::~basic_string()'的未定义引用
main.cpp:(.text+0x4eb8):对“std::basic_string::~basic_string()”的未定义引用
main.cpp:(.text+0x4ed0):对“std::allocator::~allocator()”的未定义引用
main.cpp:(.text+0x4ef4):对“std::allocator::~allocator()”的未定义引用
main.cpp:(.text+0x4f04):对“\uuucxa\uend\ucleanup”的未定义引用
C:\Users\Bill\AppData\Local\Temp\cctQCagR.o:在函数“load_files()”中:
main.cpp:(.text+0x5164):对“std::allocator::allocator()”的未定义引用
main.cpp:(.text+0x517c):对'std::basic_string::basic_string(char const*,std::allocator cons.)的未定义引用
t&)'

我相信您正在尝试使用gcc而不是g++编译main.cpp

#include <string>
#include <stdio.h>
int main()
{
    std::string bla;
    bla = "BLA BLA";
    printf("%s\n",bla.c_str());
    return 0;
}
#包括
#包括
int main()
{
std::字符串bla;
bla=“bla-bla”;
printf(“%s\n”,bla.c_str());
返回0;
}
如果您使用gcc构建上述代码段,您将得到您提到的错误。
如果你使用G++来构建OK,这是有意义的,因为G++会确保在构建C++时把它放在一起的所有适当的东西。

< p>你需要把你的二进制文件链接到LIbSTDC++。如果使用gcc,则需要在命令行中显式指定:

gcc -lstdc++ tmp.cpp
如果使用g++,默认情况下将链接libstdc++:

g++ tmp.cpp

你正在链接你的C++标准库,对吗?你会收到链接错误。所有涉及的库是否都使用同一编译器的同一版本,使用相同的运行时设置?是否可以粘贴用于编译的命令?您需要为您的问题提供更多上下文。例如,Particle_Engine.h(发布代码)中包含什么,或者它是第三方标题?另外,您应该告诉我们编译时使用的整个命令。您不应该将问题完全更改为其他问题。接受原问题的适当答案,然后用新问题开始新问题。我进去了,回过头来回答你原来的问题,这样答案还是有意义的。GCC把它放在什么地方?@ XJGCC编译C,G++编译C++。你的代码可能是C++,所以它不适用于GCC。这似乎是一个更有效的答案。叮当声也是如此。