Search code examples
c++linkerg++linear-programminglpsolve

Problem when linking c++ program with lpsolve api


I'm facing some issues when linking my c++ program, here is what I do : g++ tp.cpp -llpsolve55 -lcolamd -ldl -o MyExe and the command-line return me this :

/usr/bin/ld: cannot find -llpsolve collect2: error: ld returned 1 exit status

But I've already installed lpsolve, it appear in Synapatic as installed and I even installed it via the terminal


Solution

  • If /usr/lib/lp_solve is not in the normal search path for libraries, you can add that path to your executeable when linking. Also note that libraries should typically come last:

    g++ -o MyExe tp.cpp -L /usr/lib/lp_solve  -Wl,-rpath,/usr/lib/lp_solve -llpsolve55 -lcolamd
    

    The -L argument adds the directory to the list of directories to look for libraries in when doing the linking.

    -Wl tells the compiler to pass on what follows to the linker.

    The linkers -rpath,<path> argument tells it to add <path> to MyExe so it can find the library when you later run the program.