繁体   English   中英

G ++ Undefined Reference std ::

[英]G++ Undefined Reference std::

我一直在努力将我的一个游戏移植到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文件是由其他人编写的库函数,可以在这里找到。上面提到的代码是:

#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++

正如DietmarKühl在评论中指出的那样,我使用gcc来链接,而不是g++

在修改链接命令后,我收到了...undefined reference to 'gluLookAt'...undefined reference to 'gluLookAt'是通过添加-lGLU

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM