Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot compile Gurobi examples in version 7.5.1

Tags:

c++

gurobi

I just updated Gurobi to version 7.5.1 on Linux (Ubuntu)--this is the newest version available.

Problem Any time I try to compile any code that uses Gurobi--for example, the examples included in /opt/gurobi751/linux64/examples, I just get a string of undefined reference errors (e.g. undefined reference to GRBModel::set(...)). I would consider the problem to be solved if I can go to the directory /opt/gurobi751/linux64/examples/build and run the command make run_diet_c++ and have it compile and run.

Attempted Fixes

(1) I have set $GUROBI_HOME in my .bashrc file--it points to the correct directory. $LD_LIBRARY_PATH and $PATH have been updated as well. They all point to the correct directories.

(2) I have a valid Gurobi license. If I write a .lp file and run it like gurobi_cl model.lp, it runs correctly. Running gurobi_cl --version gives the expected output (i.e. version 7.5.1).

(3) If I try to compile the C version (with make run_diet_c) everything works as expected.

More Information

I created the following test file in my home directory:

#include <stdio.h>
#include "gurobi_c++.h"

int main(int argc, char **argv)
{
    GRBVar x;
    std::cout << "Hello, world!" << std::endl;
    return 0;
}

I then compile using g++ with the following command:

g++ -Wall test.cpp -o executable -I/opt/gurobi751/linux64/include -L/opt/gurobi751/linux64/lib -lgurobi_c++ -lgurobi75

This compiles and runs without complaining. However, I tried this example:

#include <stdio.h>
#include "gurobi_c++.h"

int main(int argc, char **argv)
{
    GRBEnv* env = 0;
    try {
        env = new GRBEnv();
        GRBModel model = GRBModel(*env);
        model.addVar(0, 1.0, 1.0, GRB_CONTINUOUS, "TheVar");
        model.update();
        model.optimize();
    } catch (...) {
        std::cout << "Exception during optimization" << std::endl;
    }

    delete env;

    return 0;
}

and compiled it with the same command, and it failed. So it seems like the include statement is working fine, but somehow it's not linking to the library correctly?

Please let me know if more information is needed. Also, if it's not clear, I don't know very much about the compilation and linking process, which is probably hindering me here.

like image 534
David M. Avatar asked Oct 16 '17 22:10

David M.


1 Answers

You need to compile the libgurobi_c++ for your g++ version.

First, go to the folder

cd /opt/gurobi751/linux64/src/build/

make

Now, you need copy the compiled file to lib folder:

cp libgurobi_c++.a ../../lib/

You will compile and run.

like image 135
Grisotto Avatar answered Sep 27 '22 20:09

Grisotto