简体   繁体   English

G ++ Undefined Reference std ::

[英]G++ Undefined Reference std::

I've been working on porting one of my games to Linux and can't seem to figure out the reasons for the errors I'm received. 我一直在努力将我的一个游戏移植到Linux上,似乎无法弄清楚我收到错误的原因。 The game was originally written in Visual Studio 2010 and I have extracted all of the needed content (headers, cpp, textures) and am trying to compile. 该游戏最初是在Visual Studio 2010中编写的,我已经提取了所有需要的内容(标题,cpp,纹理),并且我正在尝试编译。

Compilation of files using g++ -c -o exampleFile.o exampleFile.cpp works fine without any errors. 使用g++ -c -o exampleFile.o exampleFile.cpp编译文件工作正常,没有任何错误。 However upon linking I am greeted with hundreds of errors regarding std functions, an example: 但是在链接时,我遇到了关于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()'

Full output can be found on PasteBin 可以在PasteBin上找到完整输出

The Bmp.cpp file is a library function written by someone else, it can be found here The code eluded to above is: 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
}

Not really sure what the issue is, but it strikes me that the linker can't reach the std functions? 不确定问题是什么,但是链接器无法访问std函数让我感到震惊? Thanks in advance for any help. 在此先感谢您的帮助。

Edit Linking command: 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 编辑链接命令: 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++

As pointed out by Dietmar Kühl in the comments, I was using gcc to link, rather than g++ . 正如DietmarKühl在评论中指出的那样,我使用gcc来链接,而不是g++

Upon amending the linking command, I received ...undefined reference to 'gluLookAt' which was fixed by adding -lGLU . 在修改链接命令后,我收到了...undefined reference to 'gluLookAt'...undefined reference to 'gluLookAt'是通过添加-lGLU

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

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