-1

I wrote some modules which use libraries from vcpkg. The problem is when i try to compile SHARED library, it exports all functions from those libraries, why is that? I can add, that when i try to compile .exe instead of .dll problem doesn't exist

I use MinGW GCC compiler

Main CMakeLists.txt:

cmake_minimum_required(VERSION 3.24)
project(RewrittenModule)

set(CMAKE_VERBOSE_MAKEFILE on)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "-fno-ident -s -O3 -fno-ident -fno-use-linker-plugin -fdata-sections -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -fstack-protector -fuse-ld=lld -fno-math-errno -march=native -Wl,--gc-sections -Wl,--strip-all")

find_package(fmt CONFIG REQUIRED)
find_package(Protobuf CONFIG REQUIRED)

#import crypto and proto sub projects
add_subdirectory(utils)
add_subdirectory(crypto)
add_subdirectory(proto)
add_subdirectory(web)
add_subdirectory(windows_utils)

add_subdirectory(cmake_configs/windows_x64)

cmake_configs/windows_x64 CMakeLists.txt

add_library(Core SHARED ../../main.cpp ../../credentials.h)

set_target_properties(Core PROPERTIES PREFIX "")
set_target_properties(Core PROPERTIES OUTPUT_NAME "native")

target_link_libraries(Core PRIVATE utils)
target_link_libraries(Core PRIVATE fmt::fmt)

target_link_libraries(Core PRIVATE crypto)
target_link_libraries(Core PRIVATE proto)
target_link_libraries(Core PRIVATE web)
target_link_libraries(Core PRIVATE windows_utils)

Example module (proto) CMakeLists.txt

add_library(proto STATIC proto.cpp proto.h proto_messages/AuthResponse.pb.cc ....)

target_link_libraries(proto PRIVATE protobuf::libprotobuf)
target_link_libraries(proto PRIVATE crypto)
target_link_libraries(proto PRIVATE web)

List of exports is huge, it includes exports from OpenSSL Crypto, protobuf, curl.. enter image description here

Kaspek
  • 159
  • 1
  • 11
  • I see you have `-fvisibility=hidden -fvisibility-inlines-hidden`. Note that you can do that in [a cross platform way in CMake](/q/17080869). – starball Feb 03 '23 at 03:14
  • This sounds like it could be useful to you: [Hide symbols from a 3rd party .a file that is linked into a .so file](/q/61598075) – starball Feb 03 '23 at 03:17
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/251586/discussion-between-user-and-kaspek). – starball Feb 03 '23 at 03:32

1 Answers1

-1

After i added one exported function, it worked

extern "C"
__declspec(dllexport) void Test() {

}
Kaspek
  • 159
  • 1
  • 11