2013-09-25 71 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