-
-
Notifications
You must be signed in to change notification settings - Fork 784
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
Cannot create static library providing C++ module #5359
Comments
Please use |
如果没有 .cpp 只要纯 module 文件,得用 moduleonly 而不是 static |
That would not produce a static library for me. Is it impossible to build a static library that exports modules? |
see #4707 (comment) |
This comment doesn't make sense. Module units do get built into |
You can easily produce a huge static library by exporting large global variables that is not zero-initialized. For example, Visual studio would produce a 9KB+ static library containing only the following module unit.
|
@arthapaj |
and it work (but i get a 4KB static library :D) |
as for your first example, i think the module get culled as it import and export nothing, we should add a proper error but if ur static library only contains named module, u should use moduleonly targetkind to avoid flag compatibility issues with the consumer |
Size doesn't matter as long as it is reasonably larger than an empty library. It could be affected by other configurations. Latest xmake would compile it but failed to resolve dependencies when another target attempt to add the library as its dependency and imports the module.
The initial example serves as a minimal repro case which does not really need to define another symbol to make itself clear. I do appreciate a warning but an empty lib is prefered than an error.
That kind of problem is not exclusive to modules that any static library built out of old-fashion source/header can be troubled the same way. Since it has never been a legit reason to drop static library support for tranditional sources and switch, modules should be nothing different. |
u need to flag ur named module as public to get them accessible from other targets and not being culled target("testm")
set_kind("static")
set_languages("cxxlatest")
add_files("./test.cppm", {public = true})
target_end() by default we cull non-public unreferenced named module (a named module which is netheir imported inside the library or exposed to be consumed) to avoid building unused modules local objectfiles_sorted_set = hashset.from(objectfiles_sorted)
for _, objectfile in ipairs(objectfiles) do
if not objectfiles_sorted_set:has(objectfile) then
-- cull unreferenced non-public named module but add non-module files and implementation modules
local _, provide, cppfile = compiler_support.get_provided_module(modules[objectfile])
local fileconfig = target:fileconfig(cppfile)
local public = fileconfig and fileconfig.public
if not provide or public then
table.insert(result, objectfile)
end
end
end
return result
|
#5369 i also added a policy to disable project or target wise module culling add_rules("mode.release", "mode.debug")
set_languages("c++20")
-- project wise
-- set_policy("build.c++.modules.culling", false)
target("culling")
set_kind("static")
add_files("src/*.mpp")
-- target wise
set_policy("build.c++.modules.culling", false) target("culling")
set_kind("static")
add_files("src/*.mpp", {cull = false}) -- on files this should provide to the user the flexibility to choose what he want, but i don't think it's a good default so please use public visibility in first attempt |
Does it work now? try dev again. |
Xmake Version
2.9.3
Operating System Version and Architecture
Windows 11 23H2
Describe Bug
I attempted to compile the following code with xmake and MSVC:
test.cppm
export module t1;
xmake.lua
The command
xmake
failed with the following output:Expected Behavior
The code compiles and gives me
testm.lib
Project Configuration
testsxm.zip
Additional Information and Error Logs
When compiling with `_vD' xmake outputs:
The text was updated successfully, but these errors were encountered: