1

I'm trying to generate random numbers in my C++ program. It works on my laptop which runs windows. However, when I attempt to compile my program on another computer I get the following error messages:

error: ‘mt19937_64’ was not declared in this scope
error: expected ‘;’ before ‘randomGenerator’

corresponding the the following piece of code:

double** Euler::startSimulation(void) {

    mt19937_64 randomGenerator (mySeed);

/* More unshown code below... */

}

I am compiling my code from command line using g++ with the -std=c++0x flag. How do I fix this problem so my code can compile and run properly on both computers.

6
  • 2
    Are both computers 64 bit? Commented Aug 18, 2013 at 20:20
  • yes, both computers are 64 bit however, on my laptop I'm using Microsoft Visual Studio 2012 whereas I'm compiling at command line on my other machine, which runs linux
    – covertbob
    Commented Aug 18, 2013 at 20:22
  • What is your GCC version? (gcc - v) Better use 'std=C++11', not '-std=c++0x'. -and- Try to add -m64 flag to GCC. -or- Check if std::mt19937 version works. -and- Try to resolve namespace explicitly: std::mt19937_64 instead of 'mt19937_64'.
    – Drop
    Commented Aug 18, 2013 at 20:27
  • 1
    std::mt19937 works perfectly, but the other suggestions do not. When I type gcc -v I get: Target: x86_64-redhat-linux, gcc version 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)
    – covertbob
    Commented Aug 18, 2013 at 20:32
  • 1
    GCC 4.4 is a bit old. Not sure if it has implemented all C++11 features properly (but I don't know it exactly). Consider upgrade (sudo yum install gcc-4.8.1 glibc* libstd*). AFAIK, 4.8.1 is a first version which completely C++11 (and lastest stable for this moment). And +1 for using RedHat =)
    – Drop
    Commented Aug 18, 2013 at 20:37

1 Answer 1

2

mt19937(_64) are both calssified in namespace std.

To make them available, you need to tell the compiler, where to look for them. Use either std::mt19937_64 RdmGeneratorObject(seed); ore give using namespace std; directive accordingly before opening the function declaration or main.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.