我在我定義的類中使用MTRand(來自http://www.bedaux.net/mtrand/的Mersenne Twister隨機數發生器)。當我嘗試編譯時,我得到一個我無法解碼的意外錯誤。我是一個新手的C++程序員,所以任何幫助將很長的路要走......MTRand在彙編時產生錯誤
這裏是我的代碼的相關部分:
#include<iostream>
#include<vector>
#include<deque>
#include<cmath>
#include "./mtrand/mtrand.h"
using namespace std;
class mp{
long double store;
deque< vector<long double> > stack;
long double boundary;
long double dt;
long double time;
MTRand_open random;
long int random_seed;
public:
void initialize(long int, long double, long double);
long double get_state(); // return the state at position int
void update();
friend long double A(mp*);
friend long double D(mp*);
long double normal();
vector <long double> viewCurrent();
};
然後有一個功能,而如果調用,設置了隨機數發生器的種子
void mp::initialize(long int rand_seed_input, long double bdry_in, long double dt_in){
time = 0;
dt = dt_in;
random_seed = rand_seed_input;
random.seed(random_seed);
boundary = bdry_in;
}
我只是想測試一下,如果這編譯,所以我創建一個具有精確任何一個主要功能:
int main(){
return 0;
}
在編譯的時候,我得到一個錯誤
Undefined symbols:
"MTRand_int32::seed(unsigned long)", referenced from:
mp::initialize(int, long, long double, long double)in ccJylsHh.o
"MTRand_int32::p", referenced from:
MTRand_int32::rand_int32() in ccJylsHh.o
MTRand_int32::rand_int32() in ccJylsHh.o
MTRand_int32::rand_int32() in ccJylsHh.o
"MTRand_int32::state", referenced from:
MTRand_int32::rand_int32() in ccJylsHh.o
"MTRand_int32::gen_state()", referenced from:
MTRand_int32::rand_int32() in ccJylsHh.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
我不知道這是什麼錯誤意味着,它應該如何去除。
從我所知道的是,MTRand無法弄清楚如何初始化種子......但是在類MTR中有一個默認的播種,所以我看不出是什麼問題。
你鏈接了圖書館嗎? – Mysticial 2012-07-22 20:13:45
我不確定鏈接庫的含義。 對於編譯,我只需鍵入'g ++ nameOfFile.cpp'並獲取發佈的錯誤。 我也嘗試用'/ Users/path/to/mtrand/mtrand.h'類型的絕對路徑替換mtrand的相對路徑名,並使用'g ++ nameOfFile.cpp'重新編譯,而且我仍然得到相同的錯誤。 我嘗試編譯與mtrand一起提供的測試代碼,並得到完全相同的錯誤,但我無法在我的目錄中的文件夾中找到任何.o文件。我非常困惑! – 2012-07-22 20:29:55