Skip to content
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

[C++20] [Modules] unresolved external symbol for export __declspec(dllexport) variables from DLL #87887

Open
huangqinjin opened this issue Apr 6, 2024 · 4 comments
Labels
clang:modules C++20 modules and Clang Header Modules platform:windows

Comments

@huangqinjin
Copy link
Contributor

Steps to Reproduce

hello.cppm

export module hello;

export __declspec(dllexport) int x = 0;

main.cpp

import hello;

int main()
{
    return x;
}

commands

clang++ -std=c++20 -fmodule-output -shared hello.cppm -o hello.dll
clang++ -std=c++20 -fprebuilt-module-path=. main.cpp -L. -lhello

error LNK2019: unresolved external symbol "int x" (?x@@3HA) referenced in function main
@EugeneZelenko EugeneZelenko added clang:modules C++20 modules and Clang Header Modules platform:windows and removed new issue labels Apr 6, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 6, 2024

@llvm/issue-subscribers-clang-modules

Author: None (huangqinjin)

### Steps to Reproduce

hello.cppm

export module hello;

export __declspec(dllexport) int x = 0;

main.cpp

import hello;

int main()
{
    return x;
}

commands

clang++ -std=c++20 -fmodule-output -shared hello.cppm -o hello.dll
clang++ -std=c++20 -fprebuilt-module-path=. main.cpp -L. -lhello

error LNK2019: unresolved external symbol "int x" (?x@@<!-- -->3HA) referenced in function main

@ChuanqiXu9
Copy link
Member

While I can't test this in windows, I am wondering if you can try:

__declspec(dllexport) export  int x = 0;

@huangqinjin
Copy link
Contributor Author

While I can't test this in windows, I am wondering if you can try:

__declspec(dllexport) export  int x = 0;

This results in compile error expected unqualified-id.

@ChuanqiXu9
Copy link
Member

Thanks for testing. It looks like it is something deeper.

huangqinjin added a commit to huangqinjin/cxxmodules that referenced this issue May 5, 2024
1. [GCC] initializer for module is hidden with -fvisibility=hidden
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105397

2. [Clang] initializer for module is not dllexported when targeting MinGW
mstorsjo/llvm-mingw#421

3. [Clang] not strong ownership model when targeting MSVC ABI
llvm/llvm-project#89781

4. [Clang] module variables are not dllimported
llvm/llvm-project#87887

5. [DLL] module functions are not dllimported causing indirect function call
https://stackoverflow.com/a/74444920
https://developercommunity.visualstudio.com/t/10202062
https://gitlab.kitware.com/cmake/cmake/-/issues/25539
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules platform:windows
Projects
None yet
Development

No branches or pull requests

4 participants