[英]MTRand produces an error on compilation
我在定义的类中使用MTRand(来自http://www.bedaux.net/mtrand/的Mersenne Twister随机数生成器)。 当我尝试编译时,遇到了无法解码的意外错误。 我是C ++的新手程序员,所以任何帮助都会大有帮助...
这是我的代码的相关部分:
#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无法弄清楚如何初始化种子...但是MTRand类中存在默认的种子,所以我看不出问题出在哪里。
除了使用正确的文件路径在代码中包含mtrand.h
标头之外,您还应该将mtrand.cpp
添加到项目中,以便它与程序的其他.cpp文件一起编译。
如果您使用的库没有提供任何预编译的二进制文件,例如.lib,.dll或.a文件,那么可以,您必须自己编译该库的源代码(工作量不大吗?),以便使链接器开心。 但是,如果库确实与此类预编译的二进制文件一起存在,那么您应该告诉链接程序它需要链接到哪些文件,以便能够找到库头文件中的声明实际上是如何实现的,因为链接程序不知道其他方法。 实际如何链接预编译的二进制文件取决于您的开发环境。 当然,在两种情况下都应包含头文件,以告诉编译器MTRand_int32
和其他新标识符的含义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.