Skip to content

Commit

Permalink
fix absl flags decldll on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizux committed Jan 31, 2025
1 parent b641768 commit dbd77fb
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 8 deletions.
1 change: 0 additions & 1 deletion examples/cpp/nqueens.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ ABSL_FLAG(
int, size, 0,
"Size of the problem. If equal to 0, will test several increasing sizes.");
ABSL_FLAG(bool, use_symmetry, false, "Use Symmetry Breaking methods");
ABSL_DECLARE_FLAG(bool, cp_disable_solve);

static const int kNumSolutions[] = {
1, 0, 0, 2, 10, 4, 40, 92, 352, 724, 2680, 14200, 73712, 365596, 2279184};
Expand Down
13 changes: 13 additions & 0 deletions ortools/base/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,23 @@

#include <cstdlib> // for size_t.

#include "absl/flags/declare.h"
#include "ortools/base/base_export.h" // for OR_DLL

#define COMPILE_ASSERT(x, msg)

// The ABSL_DECLARE_DLL_FLAG(dll, type, name) macro expands to:
// dll extern absl::Flag<type> FLAGS_name;
#define ABSL_DECLARE_DLL_FLAG(dll, type, name) ABSL_DECLARE_DLL_FLAG_INTERNAL(dll, type, name)

// Internal implementation of ABSL_DECLARE_FLAG to allow macro expansion of its
// arguments. Clients must use ABSL_DECLARE_FLAG instead.
#define ABSL_DECLARE_DLL_FLAG_INTERNAL(dll, type, name) \
dll extern absl::Flag<type> FLAGS_##name; \
namespace absl /* block flags in namespaces */ {} \
/* second redeclaration is to allow applying attributes */ \
dll extern absl::Flag<type> FLAGS_##name

#ifdef NDEBUG
const bool DEBUG_MODE = false;
#else // NDEBUG
Expand Down
3 changes: 2 additions & 1 deletion ortools/constraint_solver/constraint_solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
#include "ortools/util/tuple_set.h"

#if !defined(SWIG)
ABSL_DECLARE_FLAG(int64_t, cp_random_seed);
ABSL_DECLARE_DLL_FLAG(OR_DLL, int64_t, cp_random_seed);
ABSL_DECLARE_DLL_FLAG(OR_DLL, bool, cp_disable_solve);
#endif // !defined(SWIG)

class File;
Expand Down
4 changes: 4 additions & 0 deletions ortools/graph/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ add_library(${NAME} OBJECT ${_SRCS})
set_target_properties(${NAME} PROPERTIES
POSITION_INDEPENDENT_CODE ON
)
if(MSVC AND BUILD_SHARED_LIBS)
target_compile_definitions(${NAME} PUBLIC "OR_BUILD_DLL")
target_compile_definitions(${NAME} PRIVATE "OR_EXPORT")
endif()
target_include_directories(${NAME} PRIVATE
${PROJECT_SOURCE_DIR}
${PROJECT_BINARY_DIR})
Expand Down
6 changes: 3 additions & 3 deletions ortools/graph/linear_assignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@
#include "ortools/util/zvector.h"

#ifndef SWIG
ABSL_DECLARE_FLAG(int64_t, assignment_alpha);
ABSL_DECLARE_FLAG(int, assignment_progress_logging_period);
ABSL_DECLARE_FLAG(bool, assignment_stack_order);
ABSL_DECLARE_DLL_FLAG(OR_DLL, int64_t, assignment_alpha);
ABSL_DECLARE_DLL_FLAG(OR_DLL, int, assignment_progress_logging_period);
ABSL_DECLARE_DLL_FLAG(OR_DLL, bool, assignment_stack_order);
#endif

namespace operations_research {
Expand Down
2 changes: 0 additions & 2 deletions ortools/graph/linear_assignment_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
#include "ortools/base/gmock.h"
#include "ortools/graph/graph.h"

ABSL_DECLARE_FLAG(bool, assignment_stack_order);

namespace operations_research {

using ::testing::Eq;
Expand Down
2 changes: 1 addition & 1 deletion ortools/util/time_limit.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* Enables changing the behavior of the TimeLimit class to use -b usertime
* instead of \b walltime. This is mainly useful for benchmarks.
*/
ABSL_DECLARE_FLAG(bool, time_limit_use_usertime);
ABSL_DECLARE_DLL_FLAG(OR_DLL, bool, time_limit_use_usertime);

namespace operations_research {

Expand Down

0 comments on commit dbd77fb

Please sign in to comment.