Skip to content

Commit b6638ea

Browse files
committed
Fixing visibility issues with so_dll_test
1 parent 5919b2b commit b6638ea

File tree

7 files changed

+32
-54
lines changed

7 files changed

+32
-54
lines changed

meson.build

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ if option_enable_unit_tests
230230
if target_machine.system() == 'windows'
231231
dep_so_dll = declare_dependency(compile_args: ['-DBOOST_LEAF_CFG_WIN32=2'])
232232
endif
233-
so_dll_test_lib1 = shared_library('so_dll_test_lib1', 'test/so_dll_lib1.cpp', dependencies: [leaf, dep_so_dll])
234-
so_dll_test_lib2 = shared_library('so_dll_test_lib2', 'test/so_dll_lib2.cpp', dependencies: [leaf, dep_so_dll])
233+
so_dll_test_lib1 = shared_library('so_dll_test_lib1', 'test/so_dll_lib1.cpp', dependencies: [leaf, dep_so_dll], gnu_symbol_visibility: 'hidden')
234+
so_dll_test_lib2 = shared_library('so_dll_test_lib2', 'test/so_dll_lib2.cpp', dependencies: [leaf, dep_so_dll], gnu_symbol_visibility: 'hidden')
235235
test('so_dll_test', executable('so_dll_test', 'test/so_dll_test.cpp', dependencies: [leaf, dep_so_dll], link_with: [so_dll_test_lib1, so_dll_test_lib2]))
236236

237237
endif

test/so_dll_lib1.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,21 @@ namespace boost
2828
}
2929
#endif
3030

31-
#include "so_dll_test_lib1.hpp"
31+
#define BOOST_LEAF_SO_DLL_TEST_BUILDING_LIB1
32+
33+
#include "so_dll_lib1.hpp"
3234

3335
namespace leaf = boost::leaf;
3436

35-
leaf::result<void> BOOST_LEAF_SO_DLL_TEST_LIB1_API hidden_result1()
37+
BOOST_LEAF_SO_DLL_TEST_LIB1_API leaf::result<void> hidden_result1()
3638
{
3739
auto load = leaf::on_error( my_info<1>{1}, my_info<3>{3} );
3840
return leaf::new_error( my_info<2>{2} );
3941
}
4042

4143
#ifndef BOOST_LEAF_NO_EXCEPTIONS
4244

43-
void BOOST_LEAF_SO_DLL_TEST_LIB1_API hidden_throw1()
45+
BOOST_LEAF_SO_DLL_TEST_LIB1_API void hidden_throw1()
4446
{
4547
auto load = leaf::on_error( my_info<1>{1}, my_info<3>{3} );
4648
leaf::throw_exception( my_info<2>{2} );

test/so_dll_test_lib1.hpp renamed to test/so_dll_lib1.hpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,24 @@
77

88
#include "so_dll_test.hpp"
99

10-
#ifdef BOOST_LEAF_SO_DLL_TEST_BUILDING_EXE
11-
# if defined(_WIN32)
12-
# define BOOST_LEAF_SO_DLL_TEST_LIB1_API __declspec(dllimport)
13-
# else
14-
# define BOOST_LEAF_SO_DLL_TEST_LIB1_API
15-
# endif
16-
#else
17-
# if defined(_WIN32)
10+
#ifdef _WIN32
11+
# ifdef BOOST_LEAF_SO_DLL_TEST_BUILDING_LIB1
1812
# define BOOST_LEAF_SO_DLL_TEST_LIB1_API __declspec(dllexport)
19-
# elif defined(__GNUC__)
20-
# define BOOST_LEAF_SO_DLL_TEST_LIB1_API __attribute__((visibility("default")))
2113
# else
22-
# define BOOST_LEAF_SO_DLL_TEST_LIB1_API
14+
# define BOOST_LEAF_SO_DLL_TEST_LIB1_API __declspec(dllimport)
2315
# endif
16+
#else
17+
# define BOOST_LEAF_SO_DLL_TEST_LIB1_API BOOST_LEAF_SYMBOL_VISIBLE
2418
#endif
2519

2620
namespace boost { namespace leaf {
2721
template <class T> class result;
2822
} }
2923

30-
boost::leaf::result<void> BOOST_LEAF_SO_DLL_TEST_LIB1_API hidden_result1();
24+
BOOST_LEAF_SO_DLL_TEST_LIB1_API boost::leaf::result<void> hidden_result1();
3125

3226
#ifndef BOOST_LEAF_NO_EXCEPTIONS
33-
void BOOST_LEAF_SO_DLL_TEST_LIB1_API hidden_throw1();
27+
BOOST_LEAF_SO_DLL_TEST_LIB1_API void hidden_throw1();
3428
#endif
3529

3630
#endif

test/so_dll_lib2.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,21 @@ namespace boost
2828
}
2929
#endif
3030

31-
#include "so_dll_test_lib2.hpp"
31+
#define BOOST_LEAF_SO_DLL_TEST_BUILDING_LIB2
32+
33+
#include "so_dll_lib2.hpp"
3234

3335
namespace leaf = boost::leaf;
3436

35-
leaf::result<void> BOOST_LEAF_SO_DLL_TEST_LIB2_API hidden_result2()
37+
BOOST_LEAF_SO_DLL_TEST_LIB2_API leaf::result<void> hidden_result2()
3638
{
3739
auto load = leaf::on_error( my_info<1>{1}, my_info<3>{3} );
3840
return leaf::new_error( my_info<2>{2} );
3941
}
4042

4143
#ifndef BOOST_LEAF_NO_EXCEPTIONS
4244

43-
void BOOST_LEAF_SO_DLL_TEST_LIB2_API hidden_throw2()
45+
BOOST_LEAF_SO_DLL_TEST_LIB2_API void hidden_throw2()
4446
{
4547
auto load = leaf::on_error( my_info<1>{1}, my_info<3>{3} );
4648
leaf::throw_exception( my_info<2>{2} );

test/so_dll_test_lib2.hpp renamed to test/so_dll_lib2.hpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,24 @@
77

88
#include "so_dll_test.hpp"
99

10-
#ifdef BOOST_LEAF_SO_DLL_TEST_BUILDING_EXE
11-
# if defined(_WIN32)
12-
# define BOOST_LEAF_SO_DLL_TEST_LIB2_API __declspec(dllimport)
13-
# else
14-
# define BOOST_LEAF_SO_DLL_TEST_LIB2_API
15-
# endif
16-
#else
17-
# if defined(_WIN32)
10+
#ifdef _WIN32
11+
# ifdef BOOST_LEAF_SO_DLL_TEST_BUILDING_LIB2
1812
# define BOOST_LEAF_SO_DLL_TEST_LIB2_API __declspec(dllexport)
19-
# elif defined(__GNUC__)
20-
# define BOOST_LEAF_SO_DLL_TEST_LIB2_API __attribute__((visibility("default")))
2113
# else
22-
# define BOOST_LEAF_SO_DLL_TEST_LIB2_API
14+
# define BOOST_LEAF_SO_DLL_TEST_LIB2_API __declspec(dllimport)
2315
# endif
16+
#else
17+
# define BOOST_LEAF_SO_DLL_TEST_LIB2_API BOOST_LEAF_SYMBOL_VISIBLE
2418
#endif
2519

2620
namespace boost { namespace leaf {
2721
template <class T> class result;
2822
} }
2923

30-
boost::leaf::result<void> BOOST_LEAF_SO_DLL_TEST_LIB2_API hidden_result2();
24+
BOOST_LEAF_SO_DLL_TEST_LIB2_API boost::leaf::result<void> hidden_result2();
3125

3226
#ifndef BOOST_LEAF_NO_EXCEPTIONS
33-
void BOOST_LEAF_SO_DLL_TEST_LIB2_API hidden_throw2();
27+
BOOST_LEAF_SO_DLL_TEST_LIB2_API void hidden_throw2();
3428
#endif
3529

3630
#endif

test/so_dll_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
# include <boost/leaf/result.hpp>
1212
#endif
1313

14-
#include "so_dll_test_lib1.hpp"
15-
#include "so_dll_test_lib2.hpp"
14+
#include "so_dll_lib1.hpp"
15+
#include "so_dll_lib2.hpp"
1616

1717
#if BOOST_LEAF_CFG_STD_STRING
1818
# include <sstream>

test/so_dll_test.hpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,16 @@
55
// Distributed under the Boost Software License, Version 1.0. (See accompanying
66
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
77

8-
#include <iosfwd>
8+
#include <boost/leaf/config.hpp>
99

1010
#if defined(_WIN32) && BOOST_LEAF_CFG_WIN32 < 2
1111
# error This test requires BOOST_LEAF_CFG_WIN32 >= 2
1212
#endif
1313

14-
#ifdef BOOST_LEAF_SO_DLL_TEST_BUILDING_EXE
15-
# if defined(_WIN32)
16-
# define BOOST_LEAF_SO_DLL_TEST_API __declspec(dllexport)
17-
# elif defined(__GNUC__)
18-
# define BOOST_LEAF_SO_DLL_TEST_API __attribute__((visibility("default")))
19-
# else
20-
# define BOOST_LEAF_SO_DLL_TEST_API
21-
# endif
22-
#else
23-
# if defined(_WIN32)
24-
# define BOOST_LEAF_SO_DLL_TEST_API __declspec(dllimport)
25-
# else
26-
# define BOOST_LEAF_SO_DLL_TEST_API
27-
# endif
28-
#endif
29-
14+
// Note, under BOOST_LEAF_CFG_WIN32==2 (using Win32 TLS) we do not need
15+
// import/export for error types. We still need default visibility on POSIX.
3016
template <int Tag>
31-
struct BOOST_LEAF_SO_DLL_TEST_API my_info
17+
struct BOOST_LEAF_SYMBOL_VISIBLE my_info
3218
{
3319
int value;
3420

0 commit comments

Comments
 (0)