Skip to main content

Undefined reference to Gurobi lib

Comments

14 comments

  • Official comment
    Simranjit Kaur
    Gurobi Staff Gurobi Staff
    This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?.
  • Gwyneth Butera
    Gurobi Staff Gurobi Staff

    Hi Carlos -

    Can you try compiling one of the C++ examples in the Gurobi examples directory? Also, check that your library paths have been updated to reflect where Gurobi is installed on your new system. - Gwyneth

    0
  • Carlos Quintero Pena
    Gurobi-versary
    Conversationalist
    First Question

    Gwyneth, thank you for your response,

    1. I included the following lines to my .basrhc file
      export GUROBI_HOME="/opt/gurobi902/linux64"
      export PATH="${PATH}:${GUROBI_HOME}/bin"
      export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${GUROBI_HOME}/lib"
      When I echo the variables they seem right:
      echo $GUROBI_HOME
      /opt/gurobi902/linux64
      echo $PATH
      /other/bin/folders:/opt/gurobi902/linux64/bin
      echo $LD_LIBRARY_PATH
      /other/lib/folders:/opt/gurobi902/linux64/lib
    2. I compiled the mip_1_c++ example (using the provided Makefile in /opt/gurobi902/linux64/examples/build) and there were no errors in compilation. However, when I try to execute it it, it shows the following:
      ./mip1_c++: error while loading shared libraries:
      libgurobi90.so: cannot open shared object file: No such file or directory

      I looked at the lib folder and I can see the library there with execution permit. This is the result of ls -al
      drwxr-xr-x 9 root root 4096 May 5 13:57 .
      drwxr-xr-x 10 root root 4096 May 4 19:15 ..
      -rw-r--r-- 1 root root 162203 May 4 19:15 gurobi-javadoc.jar
      -rw-r--r-- 1 root root 85866 May 4 19:15 gurobi.jar
      -rwxr-xr-x 1 root root 768 May 4 19:15 gurobi.py
      -rw-r--r-- 1 root root 144384 May 4 19:15 gurobi90.netstandard20.dll
      -rw-r--r-- 1 root root 445326 May 4 19:15 gurobi90.netstandard20.xml
      -rwxr-xr-x 1 root root 111556 May 4 19:15 libGurobiJni90.so
      -rwxr-xr-x 1 root root 41565688 May 4 19:15 libgurobi.so.9.0.2
      lrwxrwxrwx 1 root root 18 May 5 13:57 libgurobi90.so -> libgurobi.so.9.0.2
      -rwxr-xr-x 1 root root 37676160 May 4 19:15 libgurobi90_light.so
      lrwxrwxrwx 1 root root 18 May 4 21:57 libgurobi_c++.a -> libgurobi_g++5.2.a
      -rw-r--r-- 1 root root 628924 May 4 20:28 libgurobi_g++4.2.a
      -rw-r--r-- 1 root root 568620 May 4 19:15 libgurobi_g++5.2.a
      -rw-r--r-- 1 root root 628924 May 4 20:40 libgurobi_g++7.5.a
      drwxr-xr-x 3 root root 4096 May 4 19:15 python2.7_utf16
      drwxr-xr-x 3 root root 4096 May 4 19:15 python2.7_utf32
      drwxr-xr-x 3 root root 4096 May 4 19:15 python3.5_utf32
      drwxr-xr-x 3 root root 4096 May 4 19:15 python3.6_utf32
      drwxr-xr-x 12 root root 4096 May 4 19:15 python3.7
      drwxr-xr-x 3 root root 4096 May 4 19:15 python3.7_utf32
      drwxr-xr-x 3 root root 4096 May 4 19:15 python3.8_utf32
      -rwxr-xr-x 1 root root 1215 May 4 19:15 rootcert.pem
    3. In my CMake project, building fails at linking with "Undefined reference to..." errors

      Thanks
    0
  • Matthias Miltenberger
    Gurobi Staff Gurobi Staff

    Hi Carlos,

    Could you please share the output of

    ldd mip1_c++

    And could you please try running gurobi_cl to see if that works?

    Thanks,
    Matthias

    0
  • Carlos Quintero Pena
    Gurobi-versary
    Conversationalist
    First Question

    Mathias, in my last post I made a mistake: Like I said, I correctly exported the env variables to my (home user) .bashrc. However, since the examples folder was in /opt/gurobi902/linux64 I used "sudo su", which has a different .bashrc file and that's why it couldn't file libgurobi90.so when I ran mip1_c++.

    I copied the gurobi folder to my Desktop and now I can successfully build and run mip1_c++. Also, this is the output of ldd mip1_c++

    linux-vdso.so.1 (0x00007ffe1c9c6000)
    libgurobi90.so => /opt/gurobi902/linux64/lib/libgurobi90.so (0x00007f43584d4000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f435814b000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f4357f33000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4357b42000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f435793a000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f435771b000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f4357517000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4357179000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f435afe5000)
    This is the output of gurobi_cll

    Using license file /home/carlos/gurobi.lic
    Set parameter LogFile to value gurobi.log
    Academic license - for non-commercial use only

    Usage: gurobi_cl [--command]* [param=value]* filename
    Type 'gurobi_cl --help' for more information.

    For some reason my CMake project does not compile though. I am using this FindGurobi.cmake file

    find_path(GUROBI_INCLUDE_DIRS
    NAMES gurobi_c.h
    HINTS ${GUROBI_DIR} $ENV{GUROBI_HOME}
    PATH_SUFFIXES include)

    find_library(GUROBI_LIBRARY
    NAMES gurobi gurobi81 gurobi90
    HINTS ${GUROBI_DIR} $ENV{GUROBI_HOME}
    PATH_SUFFIXES lib)

    if(CXX)
    if(MSVC)
    # determine Visual Studio year
    if(MSVC_TOOLSET_VERSION EQUAL 142)
    set(MSVC_YEAR "2019")
    elseif(MSVC_TOOLSET_VERSION EQUAL 141)
    set(MSVC_YEAR "2017")
    elseif(MSVC_TOOLSET_VERSION EQUAL 140)
    set(MSVC_YEAR "2015")
    endif()

    if(MT)
    set(M_FLAG "mt")
    else()
    set(M_FLAG "md")
    endif()

    find_library(GUROBI_CXX_LIBRARY
    NAMES gurobi_c++${M_FLAG}${MSVC_YEAR}
    HINTS ${GUROBI_DIR} $ENV{GUROBI_HOME}
    PATH_SUFFIXES lib)
    find_library(GUROBI_CXX_DEBUG_LIBRARY
    NAMES gurobi_c++${M_FLAG}d${MSVC_YEAR}
    HINTS ${GUROBI_DIR} $ENV{GUROBI_HOME}
    PATH_SUFFIXES lib)
    else()
    find_library(GUROBI_CXX_LIBRARY
    NAMES gurobi_c++
    HINTS ${GUROBI_DIR} $ENV{GUROBI_HOME}
    PATH_SUFFIXES lib)
    set(GUROBI_CXX_DEBUG_LIBRARY ${GUROBI_CXX_LIBRARY})
    endif()

    endif()
    include(FindPackageHandleStandardArgs)

    find_package_handle_standard_args(GUROBI DEFAULT_MSG GUROBI_LIBRARY)



    Also, this is (part of) my CMakeLists.txt

    enable_language(CXX)
    find_package(GUROBI REQUIRED)
    include_directories(${GUROBI_INCLUDE_DIRS})

    add_executable(opt_plan_continuous opt_plan_continuous.cpp)
    target_link_libraries(opt_plan_continuous se2ez_plan se2ez_core optimized ${GUROBI_CXX_LIBRARY} ${GUROBI_LIBRARY})

    Like I said, I am using this exact same project in a different PC (with Gurobi 901) and it compiles and runs without problems. I also tried installing Gurobi 901 in the new PC (changing the env variables accordingly) and I get the same compilation problem.

    I hope you can help me

     

    0
  • Matthias Miltenberger
    Gurobi Staff Gurobi Staff

    Could you please share the CMake output?

    Thanks,
    Matthias

    0
  • Carlos Quintero Pena
    Gurobi-versary
    Conversationalist
    First Question

    Matthias, thank you for replying. This is the content of the CMakeOutput.log file. Hope this is the one you were referring to

    [deleted] 

    0
  • Matthias Miltenberger
    Gurobi Staff Gurobi Staff

    Could you please only show the error message that appears when you are trying to configure the CMake build? You said there was an error. I removed the long previous post.

    Did you use our own CMake files, by the way?

    0
  • Carlos Quintero Pena
    Gurobi-versary
    Conversationalist
    First Question

    Ok, sorry for that. The CMake configuration step seems to be fine, it is after that when I try to build the project that the error appears. Also, I am using my own CMakeLists file since I am writing a small part of a larger project

    Here I am showing part of the message from the configuration step.

    -- Found Threads: TRUE
    -- Found GUROBI: /opt/gurobi902/linux64/lib/libgurobi90.so

    -- The following REQUIRED packages have been found:

    * Eigen3, <http://eigen.tuxfamily.org>
    A linear algebra library used throughout OMPL.
    * Boost (required version >= 1.58), <http://boost.org>
    Used throughout OMPL for data serialization, graphs, etc.
    * orocos_kdl (required version >= 1.3)
    * Box2D
    * CGAL
    * Qt5Core
    * Qt5Widgets
    * Qt5Gui
    * Qt5 (required version >= 5.1.2)
    * Threads, <https://en.wikipedia.org/wiki/POSIX_Threads>
    Pthreads is sometimes needed, depending on OS / compiler.
    * GUROBI

    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/carlos/Documents/research/projects/xe2ez/build

    After that, I just build the project with make and these are the errors

    CMakeFiles/opt_plan_continuous.dir/opt_plan_continuous.cpp.o: In function getTrajectoryFromOptSolution(std::vector<std::shared_ptr<se2ez::State>, std::allocator<std::shared_ptr<se2ez::State> > >&, std::vector<GRBVar*, std::allocator<GRBVar*> >, std::shared_ptr<se2ez::Robot>&, std::vector<std::shared_ptr<se2ez::State>, std::allocator<std::shared_ptr<se2ez::State> > >&):
    opt_plan_continuous.cpp:(.text+0x227b): undefined reference to GRBVar::get(GRB_DoubleAttr) const'
    CMakeFiles/opt_plan_continuous.dir/opt_plan_continuous.cpp.o: In function main:
    opt_plan_continuous.cpp:(.text.startup+0x9f4): undefined reference to GRBEnv::GRBEnv(bool)'
    opt_plan_continuous.cpp:(.text.startup+0xa0a): undefined reference to GRBEnv::set(GRB_IntParam, int)'
    opt_plan_continuous.cpp:(.text.startup+0xa12): undefined reference to GRBEnv::start()'
    opt_plan_continuous.cpp:(.text.startup+0x1c91): undefined reference to GRBModel::GRBModel(GRBEnv const&)'
    opt_plan_continuous.cpp:(.text.startup+0x1d8e): undefined reference to GRBVar::GRBVar()'
    opt_plan_continuous.cpp:(.text.startup+0x1dba): undefined reference to GRBModel::addVars(double const*, double const*, double const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const*, int)'
    opt_plan_continuous.cpp:(.text.startup+0x1e99): undefined reference to GRBLinExpr::GRBLinExpr(double)'
    opt_plan_continuous.cpp:(.text.startup+0x1f62): undefined reference to operator*(double, GRBVar)'
    opt_plan_continuous.cpp:(.text.startup+0x1fa1): undefined reference to operator*(double, GRBVar)'
    opt_plan_continuous.cpp:(.text.startup+0x1fba): undefined reference to GRBLinExpr::operator+(GRBLinExpr const&)'
    opt_plan_continuous.cpp:(.text.startup+0x1fc9): undefined reference to GRBLinExpr::operator+=(GRBLinExpr const&)'
    opt_plan_continuous.cpp:(.text.startup+0x2006): undefined reference to GRBLinExpr::GRBLinExpr(double)'
    opt_plan_continuous.cpp:(.text.startup+0x201c): undefined reference to GRBLinExpr::operator+=(GRBLinExpr const&)'
    opt_plan_continuous.cpp:(.text.startup+0x2076): undefined reference to GRBLinExpr::GRBLinExpr(GRBVar, double)'
    opt_plan_continuous.cpp:(.text.startup+0x2088): undefined reference to GRBLinExpr::operator-=(GRBLinExpr const&)'
    opt_plan_continuous.cpp:(.text.startup+0x20cf): undefined reference to GRBModel::addConstr(GRBLinExpr const&, char, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
    opt_plan_continuous.cpp:(.text.startup+0x22b7): undefined reference to operator+(GRBVar, double)'
    opt_plan_continuous.cpp:(.text.startup+0x22fb): undefined reference to GRBModel::addConstr(GRBLinExpr const&, char, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
    opt_plan_continuous.cpp:(.text.startup+0x2360): undefined reference to GRBLinExpr::GRBLinExpr(double)'
    opt_plan_continuous.cpp:(.text.startup+0x239c): undefined reference to operator-(GRBVar)'
    opt_plan_continuous.cpp:(.text.startup+0x23bc): undefined reference to GRBLinExpr::operator-(GRBLinExpr const&)'
    opt_plan_continuous.cpp:(.text.startup+0x23d2): undefined reference to GRBLinExpr::operator=(GRBLinExpr const&)'
    opt_plan_continuous.cpp:(.text.startup+0x2441): undefined reference to GRBModel::addConstr(GRBLinExpr const&, char, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
    opt_plan_continuous.cpp:(.text.startup+0x24ad): undefined reference to GRBQuadExpr::GRBQuadExpr(double)'
    opt_plan_continuous.cpp:(.text.startup+0x25bf): undefined reference to operator*(double, GRBVar)'
    opt_plan_continuous.cpp:(.text.startup+0x25ce): undefined reference to GRBQuadExpr::GRBQuadExpr(GRBLinExpr)'
    opt_plan_continuous.cpp:(.text.startup+0x25e1): undefined reference to GRBQuadExpr::operator+=(GRBQuadExpr const&)'
    opt_plan_continuous.cpp:(.text.startup+0x268c): undefined reference to GRBLinExpr::GRBLinExpr(double)'
    opt_plan_continuous.cpp:(.text.startup+0x26ce): undefined reference to operator-(GRBVar, GRBVar)'
    opt_plan_continuous.cpp:(.text.startup+0x26e4): undefined reference to GRBLinExpr::operator+(GRBLinExpr const&)'
    opt_plan_continuous.cpp:(.text.startup+0x2716): undefined reference to operator*(GRBVar, GRBLinExpr const&)'
    opt_plan_continuous.cpp:(.text.startup+0x2729): undefined reference to GRBQuadExpr::operator+=(GRBQuadExpr const&)'
    opt_plan_continuous.cpp:(.text.startup+0x2fd4): undefined reference to GRBModel::setObjective(GRBQuadExpr, int)'
    opt_plan_continuous.cpp:(.text.startup+0x2fe4): undefined reference to GRBModel::optimize()'
    opt_plan_continuous.cpp:(.text.startup+0x3102): undefined reference to GRBLinExpr::GRBLinExpr(double)'
    opt_plan_continuous.cpp:(.text.startup+0x314f): undefined reference to GRBLinExpr::GRBLinExpr(GRBVar, double)'
    opt_plan_continuous.cpp:(.text.startup+0x319c): undefined reference to GRBLinExpr::GRBLinExpr(GRBVar, double)'
    opt_plan_continuous.cpp:(.text.startup+0x31de): undefined reference to operator*(double, GRBVar)'
    opt_plan_continuous.cpp:(.text.startup+0x31f8): undefined reference to GRBLinExpr::operator-(GRBLinExpr const&)'
    opt_plan_continuous.cpp:(.text.startup+0x3212): undefined reference to GRBLinExpr::operator-(GRBLinExpr const&)'
    opt_plan_continuous.cpp:(.text.startup+0x3228): undefined reference to GRBLinExpr::operator+(GRBLinExpr const&)'
    opt_plan_continuous.cpp:(.text.startup+0x3265): undefined reference to operator*(GRBVar, GRBLinExpr const&)'
    opt_plan_continuous.cpp:(.text.startup+0x3278): undefined reference to GRBQuadExpr::operator+=(GRBQuadExpr const&)'
    opt_plan_continuous.cpp:(.text.startup+0x3474): undefined reference to GRBLinExpr::GRBLinExpr(double)'
    opt_plan_continuous.cpp:(.text.startup+0x34d1): undefined reference to operator-(GRBVar, GRBVar)'
    opt_plan_continuous.cpp:(.text.startup+0x34e7): undefined reference to GRBLinExpr::operator+(GRBLinExpr const&)'
    opt_plan_continuous.cpp:(.text.startup+0x3524): undefined reference to operator*(GRBVar, GRBLinExpr const&)'
    opt_plan_continuous.cpp:(.text.startup+0x3537): undefined reference to GRBQuadExpr::operator+=(GRBQuadExpr const&)'
    opt_plan_continuous.cpp:(.text.startup+0x390a): undefined reference to GRBModel::get(GRB_DoubleAttr) const'
    opt_plan_continuous.cpp:(.text.startup+0x39d3): undefined reference to GRBModel::~GRBModel()'
    opt_plan_continuous.cpp:(.text.startup+0x3a9f): undefined reference to GRBModel::~GRBModel()'
    opt_plan_continuous.cpp:(.text.startup+0x3b0e): undefined reference to GRBEnv::~GRBEnv()'
    opt_plan_continuous.cpp:(.text.startup+0x3d54): undefined reference to GRBModel::~GRBModel()'
    opt_plan_continuous.cpp:(.text.startup+0x3e5f): undefined reference to GRBModel::~GRBModel()'
    opt_plan_continuous.cpp:(.text.startup+0x3ef4): undefined reference to GRBEnv::~GRBEnv()'
    opt_plan_continuous.cpp:(.text.startup+0x4301): undefined reference to GRBModel::~GRBModel()'
    collect2: error: ld returned 1 exit status
    script/opt_plan/CMakeFiles/opt_plan_continuous.dir/build.make:105: recipe for target 'script/opt_plan/opt_plan_continuous' failed
    CMakeFiles/Makefile2:1381: recipe for target 'script/opt_plan/CMakeFiles/opt_plan_continuous.dir/all' failed
    make[2]: *** [script/opt_plan/opt_plan_continuous] Error 1
    make[1]: *** [script/opt_plan/CMakeFiles/opt_plan_continuous.dir/all] Error 2
    make[1]: *** Waiting for unfinished jobs....
    [100%] Built target doc
    Makefile:151: recipe for target 'all' failed
    make: *** [all] Error 2
    *** Failure: Exit code 2 ***
    0
  • Matthias Miltenberger
    Gurobi Staff Gurobi Staff

    Can you please enable verbose messaging when building the project? Should be possible by specifying VERBOSE=True or -v.

    Cheers,
    Matthias

    0
  • Carlos Quintero Pena
    Gurobi-versary
    Conversationalist
    First Question

    Mathias,

    In addition to what I shared in the previous message I can see the following when enabling verbose

    [100%] Linking CXX executable opt_plan_continuous
    cd /home/carlos/Documents/research/projects/xe2ez/build/script/opt_plan && /usr/bin/cmake -E cmake_link_script CMakeFiles/opt_plan_continuous.dir/link.txt --verbose=1
    /usr/bin/c++ -O3 -O3 -DNDEBUG -rdynamic CMakeFiles/opt_plan_continuous.dir/opt_plan_continuous.cpp.o -o opt_plan_continuous -L/opt/gurobi902/linux64/lib -Wl,-rpath,/opt/gurobi902/linux64/lib:/home/carlos/Documents/research/projects/xe2ez/build/submodules/ompl/lib:/opt/ros/melodic/lib ../../src/plan/libse2ez_plan.a ../../src/core/libse2ez_core.a -lgurobi90 -lboost_filesystem -lboost_serialization -lboost_system -lboost_program_options ../../submodules/ompl/lib/libompl.so ../../submodules/yaml-cpp/libyaml-cpp.a /opt/ros/melodic/lib/liborocos-kdl.so.1.4.0 -lBox2D /usr/lib/x86_64-linux-gnu/libCGAL.so.13.0.1 -lpthread

    After this, I see the same "Undefined Reference" errors that I already shared in the previous message. I can see that -lgurobi90 shows up but I guess -lgurobi_c++ is missing?

    0
  • Matthias Miltenberger
    Gurobi Staff Gurobi Staff

    Indeed, I also suspect that the missing gurobi_c++ lib is the reason for the linker errors. You may want to check whether the CMake variable GUROBI_CXX_LIBRARY has the correct value.

    Cheers,
    Matthias

    0
  • Carlos Quintero Pena
    Gurobi-versary
    Conversationalist
    First Question

    Hi Mathias, I printed out the variable GUROBI_CXX_LIBRARY and it is empty, whereas GUROBI_LIBRARY shows the correct value. I am using the FindGUROBI.cmake file in https://support.gurobi.com/hc/en-us/articles/360039499751-CMake-C-C-compilation-of-Gurobi-projects. Is there a difference if I build in debug or release mode?

    What else could I do? I don't understand why GUROBI_LIBRARY is found and GUROBI_CXX_LIBRARY is not

    1
  • Carlos Quintero Pena
    Gurobi-versary
    Conversationalist
    First Question

    Mathias, for some reason when I do find_package(GUROBI REQUIRED), GUROBI_LIBRARY is found but GUROBI_CXX_LIBRARY is not. As a workaround I manually added it in the CMake file as follows:

    set(GUROBI_CXX_LIBRARY "$ENV{GUROBI_HOME}/lib/libgurobi_c++.a")

    Don't know why this was not an issue when I installed it in my other PC a few months ago. If you have any ideas on why this could happen, it would be awesome. For now, I'll keep this configuration

    Thank you

    0

Post is closed for comments.