1

I am new to CPP, to GUROBI and specially to CMAKE. I am working on a project and I am trying to compile a C++ program, that needs to link to the GUROBI external libraries libgurobi81.so and libgurobi_c++.a as explained in the GUROBI site here and here. The structure of my cmake and my project is something like this:

-folder1
--src
---cmake
--gurobi
---lib
----libgurobi81.so
----libgurobi_c++.a

My code compiles correctly, but it only fails when linking with the libraries. I tried to make CMAKE to find the libraries:

find_library(C_GUROBI_LIB NAMES libgurobi81.so gurobi81 gurobi81_light                                                  
    PATHS   ${LD_LIBRARY_PATH}
            /path/to/folder1/gurobi/lib/
        )
find_library(CPP_GUROBI_LIB NAMES gurobi_c++
    PATHS   ${LD_LIBRARY_PATH}
            /path/to/folder1/folder1/gurobi/lib/
    )

and then to print it:

message("C_GUROBI_LIB points to " ${C_GUROBI_LIB})
message("CPP_GUROBI_LIB points to " ${CPP_GUROBI_LIB})

However, even if the library is in that folder CMAKE do not find it and shows nothing:

C_GUROBI_LIB points to 
CPP_GUROBI_LIB points to 
Ignasi
  • 77
  • 1
  • 9
  • Did you try using absolute instead of relative paths? – Joshua Ryan Feb 23 '19 at 14:06
  • Thanks for your answer. In my question I wrote: ../folder1/gurobi/lib/ and it may seem that it was relative. But in fact I meant that there were some other folders. I am using an absolute path in both cases: /var/tmp/folder1/ ... I even tried to use: SET (CMAKE_INCLUDE_PATH "/var/tmp/folder1/gurobi810/linux64/lib/") include_directories(/var/tmp/folder1/gurobi810/linux64/lib/) LINK_DIRECTORIES(/var/tmp/folder1/gurobi810/linux64/lib/) But to no avail... – Ignasi Feb 23 '19 at 14:09
  • 1
    Result variable of the `find_library` cannot be an *empty string*: it should be either **absolute path** or `*-NOTFOUND` string. Try to clear build directory and repeat the configuration step (running `cmake`). – Tsyvarev Feb 23 '19 at 15:44
  • You're right!...turns out it was a typo. However, it finds only the second library: CPP_GUROBI_LIB, that is, the location of libgurobi_c++.a. However, even if the libgurobi81.so is in the same folder, it is not finding it... – Ignasi Feb 23 '19 at 15:50

1 Answers1

1

I found a possible solution, adapted from here:

set(CMAKE_FIND_LIBRARY_SUFFIXES ".so" ".a")

I had some other issues, for example the library was compiled for 64 bits, and also that CMAKE did not allow to add Shared files. So I got to change some parameters, but even with that, CMAKE did not found the file.

Ignasi
  • 77
  • 1
  • 9