Skip to content

Commit b725603

Browse files
committed
Add macro to export main function replacing hack setting default visibility
1 parent 065cc26 commit b725603

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

application/global.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,22 @@
8484
#define CPP_UTILITIES_GENERIC_LIB_HIDDEN __attribute__((visibility("hidden")))
8585
#endif
8686

87+
/*!
88+
* \def CPP_UTILITIES_MAIN_EXPORT
89+
* \brief Exports the main() functions on platforms where this is needed.
90+
* \remarks Needed on Android with Qt where applications are shared libraries.
91+
* Otherwise loading the app will fail with the error "dlsym failed: undefined
92+
* symbol: main".
93+
* \sa See qtbase commit 29b17fa335388c9b93f70c29b2398cf2fee65785 (where this is solved
94+
with the sledgehammer method of setting the default visibility).
95+
*/
96+
97+
#ifdef PLATFORM_ANDROID
98+
#define CPP_UTILITIES_MAIN_EXPORT CPP_UTILITIES_GENERIC_LIB_EXPORT
99+
#else
100+
#define CPP_UTILITIES_MAIN_EXPORT
101+
#endif
102+
87103
/*!
88104
* \def CPP_UTILITIES_UNUSED
89105
* \brief Prevents warnings about unused variables.

cmake/modules/AppTarget.cmake

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,7 @@ set_target_properties(
7070
AUTOGEN_TARGET_DEPENDS "${AUTOGEN_DEPS}"
7171
QT_DEFAULT_PLUGINS "${META_QT_DEFAULT_PLUGINS}"
7272
EXPORT_COMPILE_COMMANDS "${ENABLE_EXPORT_COMPILE_COMMANDS}")
73-
if (NOT ANDROID)
74-
set_target_properties(${META_TARGET_NAME} PROPERTIES C_VISIBILITY_PRESET hidden CXX_VISIBILITY_PRESET hidden)
75-
# note: Android *.so files need CXX visibility set to default (see qtbase commit
76-
# 29b17fa335388c9b93f70c29b2398cf2fee65785). Otherwise loading the app will fail with the error "dlsym failed: undefined
77-
# symbol: main".
78-
endif ()
73+
set_target_properties(${META_TARGET_NAME} PROPERTIES C_VISIBILITY_PRESET hidden CXX_VISIBILITY_PRESET hidden)
7974
if (NOT META_CXX_STANDARD STREQUAL "any")
8075
set_target_properties(${META_TARGET_NAME} PROPERTIES CXX_STANDARD "${META_CXX_STANDARD}")
8176
endif ()

0 commit comments

Comments
 (0)