Skip to content

Commit

Permalink
Fix compilation on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
metab0t committed Mar 27, 2024
1 parent 17c2c56 commit 95de5e5
Show file tree
Hide file tree
Showing 9 changed files with 6,249 additions and 41 deletions.
6 changes: 3 additions & 3 deletions include/pyoptinterface/dylib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DynamicLibrary
library, NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR));

#else
handle = dlopen(library.c_str(), RTLD_NOW);
handle = dlopen(library, RTLD_NOW);
#endif
return handle != nullptr;
}
Expand All @@ -49,10 +49,10 @@ class DynamicLibrary
#if defined(_MSC_VER)
FARPROC function_address = GetProcAddress(static_cast<HINSTANCE>(handle), name);
#else
const void *function_address = dlsym(handle, name);
void *function_address = dlsym(handle, name);
#endif

return static_cast<void *>(function_address);
return reinterpret_cast<void *>(function_address);
}

private:
Expand Down
6 changes: 5 additions & 1 deletion include/pyoptinterface/mosek_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

#include <memory>

#include "solvers/mosek/mosek.h"
#ifdef _MSC_VER
#include "solvers/mosek/mosek_win.h"
#else
#include "solvers/mosek/mosek_linux.h"
#endif

#include "pyoptinterface/core.hpp"
#include "pyoptinterface/container.hpp"
Expand Down
18 changes: 9 additions & 9 deletions lib/copt_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ bool load_library(const std::string &path)
return false;
}

#define B(f) \
{ \
auto ptr = static_cast<decltype(f)>(lib.get_symbol(#f)); \
if (ptr == nullptr) \
{ \
fmt::print("function {} is not loaded correctly", #f); \
return false; \
} \
f = ptr; \
#define B(f) \
{ \
auto ptr = reinterpret_cast<decltype(f)>(lib.get_symbol(#f)); \
if (ptr == nullptr) \
{ \
fmt::print("function {} is not loaded correctly", #f); \
return false; \
} \
f = ptr; \
}
B(COPT_GetRetcodeMsg);
B(COPT_CreateProb);
Expand Down
18 changes: 9 additions & 9 deletions lib/gurobi_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ bool load_library(const std::string &path)
return false;
}

#define B(f) \
{ \
auto ptr = static_cast<decltype(f)>(lib.get_symbol(#f)); \
if (ptr == nullptr) \
{ \
fmt::print("function {} is not loaded correctly", #f); \
return false; \
} \
f = ptr; \
#define B(f) \
{ \
auto ptr = reinterpret_cast<decltype(f)>(lib.get_symbol(#f)); \
if (ptr == nullptr) \
{ \
fmt::print("function {} is not loaded correctly", #f); \
return false; \
} \
f = ptr; \
}
B(GRBnewmodel);
B(GRBfreemodel);
Expand Down
18 changes: 9 additions & 9 deletions lib/highs_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ bool load_library(const std::string &path)
return false;
}

#define B(f) \
{ \
auto ptr = static_cast<decltype(f)>(lib.get_symbol(#f)); \
if (ptr == nullptr) \
{ \
fmt::print("function {} is not loaded correctly", #f); \
return false; \
} \
f = ptr; \
#define B(f) \
{ \
auto ptr = reinterpret_cast<decltype(f)>(lib.get_symbol(#f)); \
if (ptr == nullptr) \
{ \
fmt::print("function {} is not loaded correctly", #f); \
return false; \
} \
f = ptr; \
}

B(Highs_create);
Expand Down
18 changes: 9 additions & 9 deletions lib/mosek_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ bool load_library(const std::string &path)
return false;
}

#define B(f) \
{ \
auto ptr = static_cast<decltype(f)>(lib.get_symbol(#f)); \
if (ptr == nullptr) \
{ \
fmt::print("function {} is not loaded correctly", #f); \
return false; \
} \
f = ptr; \
#define B(f) \
{ \
auto ptr = reinterpret_cast<decltype(f)>(lib.get_symbol(#f)); \
if (ptr == nullptr) \
{ \
fmt::print("function {} is not loaded correctly", #f); \
return false; \
} \
f = ptr; \
}
B(MSK_getcodedesc);
B(MSK_makeemptytask);
Expand Down
6 changes: 5 additions & 1 deletion lib/mosek_model_ext_constants.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include <nanobind/nanobind.h>
#include "solvers/mosek/mosek.h"
#ifdef _MSC_VER
#include "solvers/mosek/mosek_win.h"
#else
#include "solvers/mosek/mosek_linux.h"
#endif

namespace nb = nanobind;

Expand Down
Loading

0 comments on commit 95de5e5

Please sign in to comment.