2013-09-25 146 views
3

我一直在努力将我的一款游戏移植到Linux上,并且似乎无法弄清楚我收到错误的原因。该游戏最初是用Visual Studio 2010编写的,我已经提取了所有需要的内容(头文件,cpp,纹理文件),并试图编译。G ++未定义参考std ::

使用g++ -c -o exampleFile.o exampleFile.cpp的文件编译工作正常,没有任何错误。但是在连接我与数百个错误的关于性病的功能,一个例子招呼:

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 
} 

不能确定是什么问题,但是这让我感到链接器无法达到性病的功能呢?预先感谢您的帮助。

编辑链接命令: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

+10

我敢打赌,你用'gcc'而不是'g ++'链接。你可能想在你的Makefile中有'LD = g ++'。 –

+0

你说得对,我使用'gcc'而不是'g ++'。感谢锐利的眼睛! – Tomassino

+0

发表回答,关闭,继续前进;;) –

回答

2

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

修改链接命令后,我收到...undefined reference to 'gluLookAt',通过添加-lGLU修复了这个问题。

21

正如迪特马尔·库尔在评论刚才指出, 你应该改变连接器的命令从gccg++

+2

dooooooooooooh! – trusktr