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 Module Compilation Fails Due to Missing fmt Include Path in Xmake Build #5679

Open
lizh1999 opened this issue Sep 30, 2024 · 0 comments
Labels

Comments

@lizh1999
Copy link

Xmake Version

xmake v2.9.5+HEAD.d30de52e9

Operating System Version and Architecture

Windows 10 19045.2846

Describe Bug

When attempting to build a project using C++20 modules with the fmt library, xmake fails to find the header file fmt/core.h during the compilation of the mod.mpp module. The error logs indicate that the include path for the fmt library is not properly passed to the compiler, resulting in a fatal error: C1083: Cannot open include file: 'fmt/core.h': No such file or directory. This suggests that the include path for fmt is not being added to the compilation command for the module, even though fmt is correctly required in xmake.lua.

Expected Behavior

The project should compile successfully, and the program should output the formatted string Hello world! as expected.

Project Configuration

-- xmake.lua
add_rules("mode.debug", "mode.release")

add_rules("plugin.compile_commands.autoupdate")

add_requires("fmt")

set_languages("c++20")

target("mod", function () 
  set_kind("moduleonly")
  add_files("mod.mpp", { public = true })
  add_packages("fmt")
  set_policy("build.c++.modules", true)
end)

target("main", function () 
  set_kind("binary")
  add_files("main.cpp")
  add_deps("mod")
  set_policy("build.c++.modules", true)
end)
// main.cpp
#include <iostream>

import mod;

int main() {
  std::cout << mod::format("Hello {}", "world!") << std::endl;
  return 0;
}
// mod.mpp
module;

#include "fmt/core.h"

export module mod;

export namespace mod {
using fmt::format;
}

Additional Information and Error Logs

checking for cl.exe ... C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\cl.exe
checking for Microsoft Visual Studio (x64) version ... 2022        
checking for Microsoft C/C++ Compiler (x64) version ... 19.40.33812
checking for zig ... no
checking for zig ... no
checking for nim ... no
checking for nim ... no
checking for git ... ok
checking for gzip ... no
checking for 7z ... C:\xmake\winenv\bin\7z
git rev-parse HEAD
checking for cmake ... no
checking for cmake ... no
checking for cmake ... no
checking for xmake::fmt ... fmt 11.0.2
checking for cl.exe ... C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\cl.exe
checking for the c++ compiler (cxx) ... cl.exe
checking for link.exe ... C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\link.exe
checking for the linker (ld) ... link.exe
checking for C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\cl.exe ... ok
checking for flags (cl_scan_dependencies) ... ok
checking for flags (cl_ifc_output) ... ok
[  0%]: <main> generating.module.deps mod.mpp
checking for flags (-O2) ... ok
checking for flags (-std:c++20) ... ok
checking for flags (-DNDEBUG) ... ok
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\cl.exe -nologo -O2 -std:c++20 /EHsc -DNDEBUG -TP -scanDependencies build\.gens\main\windows\x64\release\rules\bmi\cache\modules\2e1fd567\mod.mpp.module.json mod.mpp -ifcOutput build\.gens\main\windows\x64\release\rules\bmi\cache\modules\2e1fd567 -Fobuild\.objs\main\windows\x64\release\mod.mpp.obj
mod.mpp
mod.mpp(3): fatal error C1083: 无法打开包括文件: “fmt/core.h”: No such file or directory
[  0%]: <main> generating.module.deps mod.mpp
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\cl.exe -nologo -O2 -std:c++20 /EHsc -DNDEBUG -TP -scanDependencies build\.gens\main\windows\x64\release\rules\bmi\cache\modules\2e1fd567\mod.mpp.module.json mod.mpp -ifcOutput build\.gens\main\windows\x64\release\rules\bmi\cache\modules\2e1fd567 -Fobuild\.objs\main\windows\x64\release\mod.mpp.obj
mod.mpp
mod.mpp(3): fatal error C1083: 无法打开包括文件: “fmt/core.h”: No such file or directory
error: execv(C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\cl.exe -nologo -O2 -std:c++20 /EHsc -DNDEBUG -TP -scanDependencies build\.gens\main\windows\x64\release\rules\bmi\cache\modules\2e1fd567\mod.mpp.module.json mod.mpp -ifcOutput build\.gens\main\windows\x64\release\rules\bmi\cache\modules\2e1fd567 -Fobuild\.objs\main\windows\x64\release\mod.mpp.obj) failed(2)
@lizh1999 lizh1999 added the bug label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant