加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – G Undefined Reference std ::

发布时间:2020-12-16 06:47:07 所属栏目:百科 来源:网络整理
导读:我一直在努力将我的一个游戏移植到 Linux上,似乎无法弄清楚我收到错误的原因.该游戏最初是在Visual Studio 2010中编写的,我已经提取了所有需要的内容(标题,cpp,纹理),并且我正在尝试编译. 使用g -c -o exampleFile.o exampleFile.cpp编译文件工作正常,没有任
我一直在努力将我的一个游戏移植到 Linux上,似乎无法弄清楚我收到错误的原因.该游戏最初是在Visual Studio 2010中编写的,我已经提取了所有需要的内容(标题,cpp,纹理),并且我正在尝试编译.

使用g -c -o exampleFile.o exampleFile.cpp编译文件工作正常,没有任何错误.但是在链接时,我遇到了关于std函数的数百个错误,例如:

Bmp.o: In function `Image::Bmp::Bmp()':
Bmp.cpp:(.text+0x58): undefined reference to `std::allocator<char>::allocator()'
Bmp.cpp:(.text+0x74): undefined reference to `std::basic_string<char,std::char_traits<char>,std::allocator<char> >::basic_string(char const*,std::allocator<char> const&)'
Bmp.cpp:(.text+0x80): undefined reference to `std::allocator<char>::~allocator()'
Bmp.cpp:(.text+0x91): undefined reference to `std::allocator<char>::~allocator()'

完整输出可在PasteBin找到

Bmp.cpp文件是由其他人编写的库函数,可以找到它here上面提到的代码是:

#include <fstream>
#include <iostream>
#include <cstring>
#include "Bmp.h"
using std::ifstream;
using std::ofstream;
using std::ios;
using std::cout;
using std::endl;
using namespace Image;

///////////////////////////////////////////////////////////////////////////////
// default constructor
///////////////////////////////////////////////////////////////////////////////
Bmp::Bmp() : width(0),height(0),bitCount(0),dataSize(0),data(0),dataRGB(0),errorMessage("No error.")
{
}

Bmp::Bmp(const Bmp &rhs)
{
    // copy member variables from right-hand-side object
    width = rhs.getWidth();
    height = rhs.getHeight();
    bitCount = rhs.getBitCount();
    dataSize = rhs.getDataSize();
    errorMessage = rhs.getError();

    if(rhs.getData())       // allocate memory only if the pointer is not NULL
    {
        data = new unsigned char[dataSize];
        memcpy(data,rhs.getData(),dataSize); // deep copy
    }
    else
        data = 0;           // array is not allocated yet,set to 0

    if(rhs.getDataRGB())    // allocate memory only if the pointer is not NULL
    {
        dataRGB = new unsigned char[dataSize];
        memcpy(dataRGB,rhs.getDataRGB(),dataSize); // deep copy
    }
    else
        dataRGB = 0;        // array is not allocated yet,set to 0
}

不确定问题是什么,但是链接器无法访问std函数让我感到震惊?在此先感谢您的帮助.

编辑链接命令:gcc -o LDTux Bmp.o character.o chickenList.o chicken.o farmList.o farm.o fieldList.o field.o generall_utils.o landscape.o object.o SZ_NumberList.o SZ_Sprite.o worm.o wormList.o wormSpawn.o wormSpawnList.o GameWorld.o HelloOpenGL.o -lGL -lglut -lm

解决方法

正如DietmarKühl先前在评论中指出的那样,你应该将链接器命令从gcc更改为g.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读