![](/img/trans.png)
[英]undefined reference with std::atomic<const memberfunctionpointer*>::store() in g++ 4.4
[英]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.