Adding external library (Gurobi) to Eclipse C++

十年热恋 提交于 2020-02-06 04:33:12

问题


I would like to use Gurobi in a C++ project I have in Eclipse. I tried multiple manuals/tutorials (including THIS on how to do the same in Visual Studio) to add the hook up the Gurobi files with Eclipse/GCC, but I just couldn't make it work. I feel like I don't understand enough how these things should work in the first place.

In my Gurobi folder I have 3 folders, that in my opinion are important: include (with .h files), lib (with .lib files and NO .so or .a files) and src (with .cpp & .h files).

include: I added the path to this folder to C/C++ Build -> Settings -> GCC C++ Compiler -> Includes -> Include paths, I guess this is for the compiler to see the .h files. I also added it to C/C++ General -> Paths and Symbols -> Includes -> Include directories, I guess this is for the linker to see the .h files.

lib: I first added the folder path to C/C++ Build -> Settings -> MinGW C++ Linker -> Libraries -> Libraries (-l), however after searching online it seems to me this option only works for libraries with standard names and extensions. It also gave me the error ld.exe: cannot find -lc:/gurobi900/win64/lib/, so I deleted it and added the two .lib file paths separately to Miscellanous -> Other objects.

I got to the point where #include "gurobi_c++.h" works, however, already Eclipse underlines a line where I am defining a GRBEnv() object, that is declared in include/gurobi_c++.h, but defined in src/cpp/Env.cpp. Also if I try to compile, I get undefined reference errors. This means neither the Linker nor the Compiler can see the definition of GRBEnv().

Is there a way to tell the linker/compiler where the .cpp files are? Is it happening automatically, based on the path of the include folder? Am I supposed to link the .lib or the .cpp files?

I would greatly appreciate even if someone just pointed out mistakes in my understanding.

来源:https://stackoverflow.com/questions/59841525/adding-external-library-gurobi-to-eclipse-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!