Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lpsolve build issues. #70

Closed
BenjaminSchlaich opened this issue Sep 9, 2024 · 6 comments
Closed

lpsolve build issues. #70

BenjaminSchlaich opened this issue Sep 9, 2024 · 6 comments

Comments

@BenjaminSchlaich
Copy link

Hello Svalorzen!
I have a similar issue to #68.
I installed lpsolve on Mac (Sonoma 14.4.1) using homebrew: brew install lp_solve. This worked out fine, but while building using the cmake script I get the following error:

CMake Error at /usr/local/Cellar/cmake/3.30.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:233 (message):
Could NOT find LpSolve (missing: LPSOLVE_LIBRARIES LPSOLVE_INCLUDE_PATH
LPSOLVE_LINKS)
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.30.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:603 (_FPHSA_FAILURE_MESSAGE)
cmake/Modules/FindLpSolve.cmake:91 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:143 (find_package)

I tried to solve the issue by specifying the variables as options to cmake immediately, after checking my installation of lpsolve using brew info lp_solve:
cmake -DLPSOLVE_INCLUDE_PATH=/usr/local/Cellar/lp_solve/5.5.2.11/include -DLPSOLVE_LIBRARIES=/usr/local/Cellar/lp_solve/5.5.2.11/lib/liblpsolve55.a ..

However, this still yielded a similar problem:

CMake Error at /usr/local/Cellar/cmake/3.30.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:233 (message):
Could NOT find LpSolve (missing: LPSOLVE_LIBRARIES LPSOLVE_LINKS)
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.30.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:603 (_FPHSA_FAILURE_MESSAGE)
cmake/Modules/FindLpSolve.cmake:91 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:143 (find_package)

I thought that using homebrew to install lpsolve would be the most reasonable approach, but is there maybe some specific problem with this way of installing?

I would be really thankful for some help, as this problem seems quite hard to figure out on my own now, and apparently some people have had similar issues with the lpsolve dependency before me.
Have a nice day! Cheers, Benjamin

@Svalorzen
Copy link
Owner

If you create a separate C++ project, can you manage to compile the following?

#include <lpsolve/lp_lib.h>
int main(int /*argc*/, char** /*argv*/) {
    int major, minor, release, build;

    lp_solve_version(&major, &minor, &release, &build);

    return 0;
}

If you can't, there might be an incompatibility between the compiler you are using and the one used to create the library that brew is installing. If you can, then we can try to figure out which flags to pass to CMake (since the test it performs in order to verify that lpsolve exists is exactly this one).

@BenjaminSchlaich
Copy link
Author

Hi, thanks for the quick response!
The code compiles fine, except that I had to change #include <lpsolve/lp_lib.h> to #include <lp_lib.h>. Apparently the structure of my lib folder is different. I compiled using
clang++ -o testlpsolve -L/usr/local/Cellar/lp_solve/5.5.2.11/lib/ -llpsolve55 testlpsolve.cpp

I also added one line of code to output the version info, just to check that it actually works, which it does.
So it seems to me that my installation of lp_solve is fine, but somehow I fail to inform the cmake script of that.
What would be your next step to try and fix this?
Thank you so much, best regards!

@Svalorzen
Copy link
Owner

Svalorzen commented Sep 10, 2024

I think that might be the culprit. Both my script and my code assume that the headers are reachable with <lpsolve/_someheader.h_>, so if your folder structure is different that will not work. What you could do is create either a softlink inside the lpsolve folder that point to itself called lpsolve, or create the same link somewhere else and pass that as the "true" directory of lpsolve to CMake. After that it should be able to find it.

You can alternatively (I think) modify the CMake script tasked to find lpsolve (this one), as well as change in the actual library all #include instances so they don't have the path prefix (I think it should only be this one but I haven't fully checked but it should be easy to figure out anyway).

@BenjaminSchlaich
Copy link
Author

Sorry, I kind of missed the obvious point of my own last answer! I actually fixed the problem, which was precisely the different structure of my "include" folder in homebrew's installation. Since, as you said, the code above is exactly the test which that cmake script uses, I now moved all my header files into a folder called "lpsolve", just to try if it works - and voila - the script builds perfectly.

I am not sure, however, what to make of this. This trick of manually adapting the structure of my installation directory is not a permanent fix, since whenever homebrew updates the installation of lpsolve, I suppose that my changes will be overwritten again. Do you have a proposal how I could elegantly fix this once and for all?
Thank you already for your time and have a nice day!
Benjamin.

@Svalorzen
Copy link
Owner

As I said, if you create a symbolic link that points to the header folder and pass the directory that link resides in as the lp_solve directory, it should work just as well. To clarify:

random_directory/
    lp_solve->       // symbolic link to brew folder
        lp_headers.h  // Headers

And then pass random_directory as the lp_solve directory. So it will look into random_directory/lp_solve/headers.h which will ultimately resolve to the actual headers correctly.

@BenjaminSchlaich
Copy link
Author

Nice idea with the symbolic link, i'll definitely do that!
It might me nice to add a litte note with that trick in the installation instructions for other people who run MacOS, since brew is probably the most common way to get the dependencies.
In any case thanks a bunch for the quick help! I'm looking forward to getting to know your library!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants