-
Notifications
You must be signed in to change notification settings - Fork 484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use ELF visibility to export only public symbols from the library #560
Comments
Very late but this is something I've had to personally work around on Windows when using the SOCI DLLs. Take for example use of the ODBC backend DLL. The ODBC backend docs show use of soci/include/soci/odbc/soci-odbc.h Line 612 in c5678e1
However, without # SOCI core library, propagating SOCI_DLL when using the shared target
add_library(myproj::soci_core INTERFACE IMPORTED)
target_link_libraries(myproj::soci_core INTERFACE SOCI::soci_core)
target_compile_definitions(myproj::soci_core INTERFACE SOCI_DLL)
# assume something similar for a myproj::soci_odbc target Linking against these targets now works seamlessly because the |
By the way, I think
This can be pretty easily achieved with something like the following (e.g. for the core library): # already called add_library(${SOCI_CORE_TARGET} SHARED ...)
# ensure SOCI_DLL is defined when using a shared library
target_compile_options(${SOCI_CORE_TARGET} PUBLIC SOCI_DLL)
# ensure when compiling that annotated symbols get exported
set_target_properties(${SOCI_CORE_TARGET} PROPERTIES DEFINE_SYMBOL SOCI_SOURCE) To this end, the #elif defined(SOCI_HAVE_VISIBILITY_SUPPORT)
// note: public visibility only applied when SOCI_DLL is defined. current build
// config will use -fvisibility=hidden or equivalent for unexported symbols
# ifdef SOCI_DLL
# define SOCI_DECL_EXPORT __attribute__ (( visibility("default") ))
# define SOCI_DECL_IMPORT __attribute__ (( visibility("default") ))
# endif
#endif I see in the |
Ended up making a feature branch in my SOCI fork that ensures that In the course of my work I was forced to also do the following:
The reason 4. is necessary is because since So far things seem to working well in terms of building the library. I was able to test MySQL, ODBC, SQLite3, Firebird, and PostgreSQL backend compilation on WSL Ubuntu (ODBC and SQLite3 only for native Windows). |
We should really define
SOCI_DLL
appropriately not only in Win32 builds, but also when ELF visibility is supported for all the usual reasons (more efficient shared library loading; consistency between platforms).As usual, I don't know how to handle this at CMake level, but if anyone can take care of this, I could do the required (trivial) changes to the sources.
The text was updated successfully, but these errors were encountered: