Skip to content

Commit dbd77fb

Browse files
committed
fix absl flags decldll on windows
1 parent b641768 commit dbd77fb

File tree

7 files changed

+23
-8
lines changed

7 files changed

+23
-8
lines changed

examples/cpp/nqueens.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ ABSL_FLAG(
3939
int, size, 0,
4040
"Size of the problem. If equal to 0, will test several increasing sizes.");
4141
ABSL_FLAG(bool, use_symmetry, false, "Use Symmetry Breaking methods");
42-
ABSL_DECLARE_FLAG(bool, cp_disable_solve);
4342

4443
static const int kNumSolutions[] = {
4544
1, 0, 0, 2, 10, 4, 40, 92, 352, 724, 2680, 14200, 73712, 365596, 2279184};

ortools/base/macros.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,23 @@
1616

1717
#include <cstdlib> // for size_t.
1818

19+
#include "absl/flags/declare.h"
1920
#include "ortools/base/base_export.h" // for OR_DLL
2021

2122
#define COMPILE_ASSERT(x, msg)
2223

24+
// The ABSL_DECLARE_DLL_FLAG(dll, type, name) macro expands to:
25+
// dll extern absl::Flag<type> FLAGS_name;
26+
#define ABSL_DECLARE_DLL_FLAG(dll, type, name) ABSL_DECLARE_DLL_FLAG_INTERNAL(dll, type, name)
27+
28+
// Internal implementation of ABSL_DECLARE_FLAG to allow macro expansion of its
29+
// arguments. Clients must use ABSL_DECLARE_FLAG instead.
30+
#define ABSL_DECLARE_DLL_FLAG_INTERNAL(dll, type, name) \
31+
dll extern absl::Flag<type> FLAGS_##name; \
32+
namespace absl /* block flags in namespaces */ {} \
33+
/* second redeclaration is to allow applying attributes */ \
34+
dll extern absl::Flag<type> FLAGS_##name
35+
2336
#ifdef NDEBUG
2437
const bool DEBUG_MODE = false;
2538
#else // NDEBUG

ortools/constraint_solver/constraint_solver.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@
104104
#include "ortools/util/tuple_set.h"
105105

106106
#if !defined(SWIG)
107-
ABSL_DECLARE_FLAG(int64_t, cp_random_seed);
107+
ABSL_DECLARE_DLL_FLAG(OR_DLL, int64_t, cp_random_seed);
108+
ABSL_DECLARE_DLL_FLAG(OR_DLL, bool, cp_disable_solve);
108109
#endif // !defined(SWIG)
109110

110111
class File;

ortools/graph/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ add_library(${NAME} OBJECT ${_SRCS})
2626
set_target_properties(${NAME} PROPERTIES
2727
POSITION_INDEPENDENT_CODE ON
2828
)
29+
if(MSVC AND BUILD_SHARED_LIBS)
30+
target_compile_definitions(${NAME} PUBLIC "OR_BUILD_DLL")
31+
target_compile_definitions(${NAME} PRIVATE "OR_EXPORT")
32+
endif()
2933
target_include_directories(${NAME} PRIVATE
3034
${PROJECT_SOURCE_DIR}
3135
${PROJECT_BINARY_DIR})

ortools/graph/linear_assignment.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@
214214
#include "ortools/util/zvector.h"
215215

216216
#ifndef SWIG
217-
ABSL_DECLARE_FLAG(int64_t, assignment_alpha);
218-
ABSL_DECLARE_FLAG(int, assignment_progress_logging_period);
219-
ABSL_DECLARE_FLAG(bool, assignment_stack_order);
217+
ABSL_DECLARE_DLL_FLAG(OR_DLL, int64_t, assignment_alpha);
218+
ABSL_DECLARE_DLL_FLAG(OR_DLL, int, assignment_progress_logging_period);
219+
ABSL_DECLARE_DLL_FLAG(OR_DLL, bool, assignment_stack_order);
220220
#endif
221221

222222
namespace operations_research {

ortools/graph/linear_assignment_test.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
#include "ortools/base/gmock.h"
3030
#include "ortools/graph/graph.h"
3131

32-
ABSL_DECLARE_FLAG(bool, assignment_stack_order);
33-
3432
namespace operations_research {
3533

3634
using ::testing::Eq;

ortools/util/time_limit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* Enables changing the behavior of the TimeLimit class to use -b usertime
3939
* instead of \b walltime. This is mainly useful for benchmarks.
4040
*/
41-
ABSL_DECLARE_FLAG(bool, time_limit_use_usertime);
41+
ABSL_DECLARE_DLL_FLAG(OR_DLL, bool, time_limit_use_usertime);
4242

4343
namespace operations_research {
4444

0 commit comments

Comments
 (0)