CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS not implemented for MinGW
Description
CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS
does not work for MSYS2/Mingw-w64 when the linked library has at least one __declspec (dllexport)
. In this case, only methods marked with dllexport
will be exported. With MSVC and Clang it works correctly. The problem is reproducible both for third-party libraries and for those created in the project.
Minimal reproducible project
This project will only export exportedMethod
and compilation will fail. But will compile correctly if you remove __declspec(dllexport)
from exportedMethod
, because in this case all methods will be exported. It also works if you add __declspec(dllexport)
to anotherMethod
.
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(project LANGUAGES CXX)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
add_executable(${PROJECT_NAME} main.cpp)
add_library(Test SHARED test.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE Test)
test.h
#pragma once
class Test
{
public:
Test() = default;
__declspec(dllexport) void exportedMethod();
void anotherMethod();
};
test.cpp
#include "test.h"
#include <iostream>
void Test::exportedMethod()
{
}
void Test::anotherMethod()
{
}
main.cpp
#include "test.h"
int main()
{
Test test;
test.exportedMethod();
test.anotherMethod();
}
Environment
MSYS2/Mingw-w64: g++ (Rev6, Built by MSYS2 project) 10.2.0
Clang: 11.0.1
MSVC: 16.8.4