编译时出现C ++错误 [英] C++ errors while compiling

查看:128
本文介绍了编译时出现C ++错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译游戏,但遇到100多个错误,例如:

I am trying to compile a game, but getting 100+ errors like:

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

推荐答案

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

I believe you're trying to compile main.cpp with gcc instead of g++.

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

如果您使用gcc构建上述代码段,则会得到您提到的错误. 如果您使用g ++可以正常构建,这是有道理的,因为g ++将确保在构建C ++时将所有正确的东西放在一起.

If you build the above code snippet with gcc you get the errors you mention. If you use g++ it build ok, this makes sense since g++ will make sure all the proper stuff it put together when build C++.

这篇关于编译时出现C ++错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆