xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
9.49k stars 762 forks source link

g++ module .o: No such file or directory #5261

Open paulross80 opened 6 days ago

paulross80 commented 6 days ago

Xmake Version

xmake v2.9.2+20240525

Operating System Version and Architecture

Fedora 40 KDE x86_64

Describe Bug

If I just compile everything together, without making static library, it works fine. As soon as I put the C++20 module file into a static library target, I get the error

Expected Behavior

To compile?

Project Configuration

add_rules("mode.release", "mode.debug")
set_languages("c++23")

-- Without the static library target, no errors occur
target("x-lib")
    set_kind("static")
    add_files("cpp/Math/**.mpp")

target("x-app")
    set_kind("binary")
    add_files("cpp/*.cpp")
    add_deps("x-lib")

cpp/main.cpp

import Vector;

int main()
{
    // Testing my module!
    x::Vector2f v1{ 2.5f, 3.1f };
    v1.print();
}

cpp/Math/Vector.mpp

module;
#include <cmath>
#include <print>

export module Vector;

export namespace x
{

template <typename T>
struct Vector2D
{
    T x{}, y{};

    void print() const
    {
        std::println("Vector2: [{}, {}]", x, y);
    }
};

using Vector2f = Vector2D<float>;
using Vector2i = Vector2D<int>;

} // x

Additional Information and Error Logs

$ xmake clean
$ xmake 
[  0%]: <x-app> generating.module.deps cpp/main.cpp
[  0%]: <x-lib> generating.module.deps cpp/Math/Vector.mpp
[ 30%]: archiving.debug libx-lib.a
error: /usr/bin/ar: build/.objs/x-lib/linux/x86_64/debug/cpp/Math/Vector.mpp.o: No such file or directory
$ xmake -vD
[ 30%]: archiving.debug libx-lib.a
/usr/bin/ar -cr build/linux/x86_64/debug/libx-lib.a build/.objs/x-lib/linux/x86_64/debug/cpp/Math/Vector.mpp.o
error: @programdir/core/main.lua:329: @programdir/actions/build/main.lua:148: @programdir/modules/async/runjobs.lua:322: @programdir/actions/build/kinds/static.lua:53: @programdir/core/sandbox/modules/os.lua:273: /usr/bin/ar: build/.objs/x-lib/linux/x86_64/debug/cpp/Math/Vector.mpp.o: No such file or directory

stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:973]:
    [@programdir/core/sandbox/modules/os.lua:273]: in function 'runv'
    [@programdir/modules/core/tools/ar.lua:60]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]:
    [@programdir/core/tool/linker.lua:221]: in function 'link'
    [@programdir/actions/build/kinds/static.lua:53]: in function 'callback'
    [@programdir/modules/core/project/depend.lua:217]: in function 'on_changed'
    [@programdir/actions/build/kinds/static.lua:41]: in function '_do_link_target'
    [@programdir/actions/build/kinds/static.lua:84]:
    [@programdir/actions/build/kinds/static.lua:111]: in function '_link_target'
    [@programdir/actions/build/kinds/static.lua:139]: in function 'jobfunc'
    [@programdir/modules/async/runjobs.lua:238]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]: in function 'trycall'
    [@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
    [@programdir/modules/async/runjobs.lua:220]: in function 'cotask'
    [@programdir/core/base/scheduler.lua:406]:

stack traceback:
        [C]: in function 'error'
        @programdir/core/base/os.lua:973: in function 'os.raiselevel'
        (...tail calls...)
        @programdir/core/main.lua:329: in upvalue 'cotask'
        @programdir/core/base/scheduler.lua:406: in function <@programdir/core/base/scheduler.lua:399>
waruqi commented 6 days ago

try use moduleonly instead of static

add_rules("mode.release", "mode.debug")
set_languages("c++23")

-- Without the static library target, no errors occur
target("x-lib")
    set_kind("moduleonly")
    add_files("cpp/Math/**.mpp")

target("x-app")
    set_kind("binary")
    add_files("cpp/*.cpp")
    add_deps("x-lib")
paulross80 commented 5 days ago

Ok, for this minimal example project, it works. But for a bigger project that adds dependencies (libsdl, opengl, etc), everything compiles, but I got a lot of linker errors

$ xmake                                                                                                                      
generating config/x_config.hpp.in ... ok
generating config/app1_config.hpp.in ... ok
[  0%]: <app1> generating.module.deps cpp/apps/App1/app1.cpp
[  0%]: <app1> generating.module.deps cpp/x_lib/Math/Vector.mpp
[  0%]: <papa> generating.module.deps cpp/x_lib/Math/Vector.mpp
[  0%]: <app2> generating.module.deps cpp/apps/App2/app2.cpp
[  0%]: <app2> generating.module.deps cpp/x_lib/Math/Vector.mpp
[ 15%]: cache compiling.debug cpp/third_party/glad/glad.c
[ 20%]: archiving.debug libglad.a
[ 55%]: <app1> compiling.module.debug Vector
[ 60%]: <app2> compiling.module.debug Vector
[ 70%]: compiling.debug cpp/apps/App1/app1.cpp
[ 80%]: compiling.debug cpp/apps/App2/app2.cpp
[ 85%]: linking.debug app1_linux_x86_64-debug
error: /usr/bin/ld: /tmp/ccWpcfNw.ltrans0.ltrans.o: in function `std::vformat(std::basic_string_view<char, std::char_traits<char> >, std::basic_format_args<std::basic_format_context<std::__format::_Sink_iter<char>, char> >)':
/usr/include/c++/14/format:2773:(.text+0xb9a): undefined reference to `std::span<char, 18446744073709551615ul>::span<256ul>(char (&) [256ul]) [clone .localalias]'
/usr/bin/ld: /tmp/ccWpcfNw.ltrans0.ltrans.o: in function `std::vprint_nonunicode(_IO_FILE*, std::basic_string_view<char, std::char_traits<char> >, std::basic_format_args<std::basic_format_context<std::__format::_Sink_iter<char>, char> >)':
/usr/include/c++/14/format:2773:(.text+0xdbd): undefined reference to `std::span<char, 18446744073709551615ul>::span<256ul>(char (&) [256ul]) [clone .localalias]

And a lot of undefined references to SDL undefined reference to `SDL_Init' ... etc

The target in the project:

target("glad")
    -- Static library
    set_kind("static")
    -- Add source files
    add_files("cpp/third_party/glad/glad.c")
    -- Add path to headers
    add_includedirs("cpp/third_party/glad", { public = true })

target("x")
    -- Static library
    set_kind("moduleonly") -- try use moduleonly instead of static
    set_suffixname("-static_$(plat)_$(arch)-$(mode)")
    add_files("cpp/papa_lib/**.mpp") -- "cpp/papa_lib/**.cpp", <- removed 1st param here

    set_version("0.0.1", { build = "%Y%m%d%H%M" })
    set_configdir("$(buildir)/config")
    add_configfiles("config/x_config.hpp.in")

    -- Link against the required libraries
    add_packages("libsdl")
    --add_packages("libsdl_mixer")
    add_packages("opengl")
    -- Add compiled glad library as a dependency
    add_deps("glad")
    --add_packages("openal-soft")
    --add_packages("zlib")

    -- Platform specific things
    -- if is_plat("linux", "macosx") then
        -- add_links("pthread", "m", "dl")
    -- end

    -- Add public include directories
    -- So the engine and apps can find engine headers
    add_includedirs("$(projectdir)/cpp", { public = true })
    -- So the engine and apps can also find the config headers
    add_includedirs("$(buildir)", { public = true })

Can C++20 modules be used to make a static library? I hope so Running xmake -vD adds this output:

error: @programdir/core/main.lua:329: @programdir/actions/build/main.lua:148: @programdir/modules/async/runjobs.lua:322: @programdir/actions/build/kinds/binary.lua:53: @programdir/core/sandbox/modules/os.lua:378: execv(/usr/lib64/ccache/g++ -o build/linux/x86_64/debug/app1_linux_x86_64-debug build/.objs/app1/linux/x86_64/debug/cpp/apps/App1/app1.cpp.o build/.objs/app1/linux/x86_64/debug/cpp/x_lib/Math/Vector.mpp.o -m64 -Lbuild/linux/x86_64/debug -lglad -flto -O0) failed(1)
stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:973]:
    [@programdir/core/sandbox/modules/os.lua:378]: in function 'execv'
    [@programdir/modules/core/tools/gcc.lua:580]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]:
    [@programdir/core/tool/linker.lua:221]: in function 'link'
    [@programdir/actions/build/kinds/binary.lua:53]: in function 'callback'
    [@programdir/modules/core/project/depend.lua:217]: in function 'on_changed'
    [@programdir/actions/build/kinds/binary.lua:41]: in function '_do_link_target'
    [@programdir/actions/build/kinds/binary.lua:83]:
    [@programdir/actions/build/kinds/binary.lua:110]: in function '_link_target'
    [@programdir/actions/build/kinds/binary.lua:138]: in function 'jobfunc'
    [@programdir/modules/async/runjobs.lua:238]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]: in function 'trycall'
    [@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
    [@programdir/modules/async/runjobs.lua:220]: in function 'cotask'
    [@programdir/core/base/scheduler.lua:406]:

stack traceback:
        [C]: in function 'error'
        @programdir/core/base/os.lua:973: in function 'os.raiselevel'
        (...tail calls...)
        @programdir/core/main.lua:329: in upvalue 'cotask'
        @programdir/core/base/scheduler.lua:406: in function <@programdir/core/base/scheduler.lua:399>
waruqi commented 5 days ago

Can C++20 modules be used to make a static library? I hope so

when only module files exsit, please use moduleonly. when both module/cpp or only cpp files exsit, please use static.

https://github.com/xmake-io/xmake/blob/master/tests/projects/c%2B%2B/static_library/xmake.lua

And I did not find add_requires in your xmake.lua

paulross80 commented 4 days ago

I've tried to make a minimal version of my project file, here it is the complete code

xmake.lua

set_project("something")
-- set_policy("build.optimization.lto", true) -- disabled now

-- Global settings
set_languages("c++23")
set_warnings("allextra")
set_exceptions("cxx")
set_encodings("utf-8")

-- Build modes
add_rules("mode.debug", "mode.release")

if is_mode("debug") then
    set_symbols("debug")
    set_optimize("none")
end

if is_mode("release") then
    set_symbols("hidden")
    set_strip("all")
    set_optimize("faster")
end

-- Install/fetch the required libraries
add_requires("libsdl")
add_requires("opengl")

-- glad target
target("glad")
    set_kind("static")
    add_files("cpp/third_party/glad/glad.c")
    add_includedirs("cpp/third_party/glad", { public = true })

-- target for my engine as a library
target("my_lib")
    set_kind("moduleonly")
    set_suffixname("-static_$(plat)_$(arch)-$(mode)")
    add_files("cpp/my_lib/**.mpp")
    set_version("0.0.1", { build = "%Y%m%d%H%M" })
    -- Link against the required libraries
    add_packages("libsdl")
    add_packages("opengl")
    add_deps("glad")
    -- Add public include directories
    -- So the engine and apps can find engine headers
    add_includedirs("$(projectdir)/cpp", { public = true })

-- Apps
target("app1")
    set_kind("binary")
    set_suffixname("_$(plat)_$(arch)-$(mode)")
    add_files("cpp/apps/App1/**.cpp")
    add_deps("my_lib")
    set_rundir("$(projectdir)/data/App1")
    set_version("0.1.2", { build = "%Y%m%d%H%M" })

target("app2")
    set_kind("binary")
    set_suffixname("_$(plat)_$(arch)-$(mode)")
    add_files("cpp/apps/App2/**.cpp")
    add_deps("my_lib")
    set_rundir("$(projectdir)/data/App2")
    set_version("0.2.5", { build = "%Y%m%d%H%M" })

Output is

$ xmake
[  0%]: <app1> generating.module.deps cpp/apps/App1/app1.cpp
[  0%]: <app1> generating.module.deps cpp/my_lib/Math/Vector.mpp
[  0%]: <my_lib> generating.module.deps cpp/my_lib/Math/Vector.mpp
[  0%]: <app2> generating.module.deps cpp/apps/App2/app2.cpp
[  0%]: <app2> generating.module.deps cpp/my_lib/Math/Vector.mpp
[ 15%]: cache compiling.debug cpp/third_party/glad/glad.c
[ 20%]: archiving.debug libglad.a
[ 55%]: <app1> compiling.module.debug Vector
[ 60%]: <app2> compiling.module.debug Vector
[ 70%]: compiling.debug cpp/apps/App1/app1.cpp
[ 80%]: compiling.debug cpp/apps/App2/app2.cpp
[ 85%]: linking.debug app1_linux_x86_64-debug
error: /usr/bin/ld: /tmp/ccSfvoo2.ltrans0.ltrans.o: in function `std::vformat(std::basic_string_view<char, std::char_traits<char> >, std::basic_format_args<std::basic_format_context<std::__format::_Sink_iter<char>, char> >)':

And a lot more of link errors Using -vD parameter:

$ xmake -vD
error: @programdir/core/main.lua:329: @programdir/actions/build/main.lua:148: @programdir/modules/async/runjobs.lua:322: @programdir/actions/build/kinds/binary.lua:53: @programdir/core/sandbox/modules/os.lua:378: execv(/usr/lib64/ccache/g++ -o build/linux/x86_64/debug/app1_linux_x86_64-debug build/.objs/app1/linux/x86_64/debug/cpp/apps/App1/app1.cpp.o build/.objs/app1/linux/x86_64/debug/cpp/my_lib/Math/Vector.mpp.o -m64 -Lbuild/linux/x86_64/debug -lglad -flto -O0) failed(1)
stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:973]:
    [@programdir/core/sandbox/modules/os.lua:378]: in function 'execv'
    [@programdir/modules/core/tools/gcc.lua:580]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]:
    [@programdir/core/tool/linker.lua:221]: in function 'link'
    [@programdir/actions/build/kinds/binary.lua:53]: in function 'callback'
    [@programdir/modules/core/project/depend.lua:217]: in function 'on_changed'
    [@programdir/actions/build/kinds/binary.lua:41]: in function '_do_link_target'
    [@programdir/actions/build/kinds/binary.lua:83]:
    [@programdir/actions/build/kinds/binary.lua:110]: in function '_link_target'
    [@programdir/actions/build/kinds/binary.lua:138]: in function 'jobfunc'
    [@programdir/modules/async/runjobs.lua:238]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]: in function 'trycall'
    [@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
    [@programdir/modules/async/runjobs.lua:220]: in function 'cotask'
    [@programdir/core/base/scheduler.lua:406]:

stack traceback:
        [C]: in function 'error'
        @programdir/core/base/os.lua:973: in function 'base/os.raiselevel'
        (...tail calls...)
        @programdir/core/main.lua:329: in upvalue 'cotask'
        @programdir/core/base/scheduler.lua:406: in function <@programdir/core/base/scheduler.lua:399>

cpp/apps/App1/app1.cpp

#include <iostream>
using std::cout;
using std::endl;
#include <print>

#include <SDL2/SDL.h>
#include <glad/glad.h>

// Import my Vector module ?
import Vector;

int main()
{
    std::println(" - system RAM: {} GB", SDL_GetSystemRAM() / 1'000);

    // Testing my module!
    my_lib::Vector2f v1{ 2.5f, 3.1f };
    v1.print();

    // Initialize SDL
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
    {
        //cout << "Error: " << SDL_GetError() << endl;
        std::println("Error: {}", SDL_GetError());
        return 1;
    }

    // Create a window
    SDL_Window* window = SDL_CreateWindow("App1",
                         SDL_WINDOWPOS_UNDEFINED,
                         SDL_WINDOWPOS_UNDEFINED,
                         1280, 720,
                         SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);
    if (!window)
    {
        SDL_Quit();
        std::println("Error creating window: {}", SDL_GetError());
        return 1;
    }

    // Create OpenGL context
    auto context = SDL_GL_CreateContext(window);

    // Initialize the GLAD library
    // https://github.com/Dav1dde/glad
    auto glad_version = gladLoadGLLoader(SDL_GL_GetProcAddress);

    if (glad_version == 0)
    {
        SDL_GL_DeleteContext(context);
        SDL_DestroyWindow(window);
        SDL_Quit();
        cout << "Error initializing GLAD library!" << endl;
        return 1;
    }

    cout << " - glad library initialized" << endl;
    cout << " - Vendor: " << glGetString(GL_VENDOR) << endl;
    cout << " - Renderer: " << glGetString(GL_RENDERER) << endl;
    cout << " - Version: " << glGetString(GL_VERSION) << endl;

    // Loop
    bool close = false;

    while (!close)
    {
        SDL_Event event;

        while (SDL_PollEvent (&event))
        {
            if (event.type == SDL_QUIT)
                close = true;
        }

        // draw
        glClear(GL_COLOR_BUFFER_BIT);
        SDL_GL_SwapWindow(window);
    }

    // Destroy
    SDL_GL_DeleteContext(context);
    SDL_DestroyWindow(window);

    // Close SDL
    SDL_Quit();
    return 0;
}

cpp/apps/App2/app2.cpp

#include <iostream>
using std::cout;
using std::endl;

// Import my Vector module ?
import Vector;

int main()
{
    // Testing my module!
    my_lib::Vector2f v1{ 1.0f, -0.5f };
    v1.print();

    return 0;
}

cpp/my_lib/Math/Vector.mpp

module;
#include <cmath>
#include <print>

export module Vector;

export namespace my_lib
{

template <typename T>
struct Vector2D
{
    T x{}, y{};

    void print() const
    {
        std::println("Vector2: [{}, {}]", x, y);
    }
};

// Shortcuts to the most used ones
using Vector2f = Vector2D<float>;
using Vector2i = Vector2D<int>;

} 

Directory tree

.
├── build
│   └── linux
│       └── x86_64
│           ├── debug
│           │   └── libglad.a
├── cpp
│   ├── apps
│   │   ├── App1
│   │   │   └── app1.cpp
│   │   └── App2
│   │       └── app2.cpp
│   ├── my_lib
│   │   └── Math
│   │       └── Vector.mpp
│   └── third_party
│       └── glad
│           ├── glad
│           │   └── glad.h
│           ├── glad.c
│           └── KHR
│               └── khrplatform.h
└── xmake.lua
waruqi commented 4 days ago

please provide a whole project. and try disable lto.

paulross80 commented 4 days ago

All the files should be listed in my previous post. And I have disabled LTO

$ xmake
[ 15%]: cache compiling.debug cpp/third_party/glad/glad.c
[ 20%]: archiving.debug libglad.a
[ 55%]: <app1> compiling.module.debug Vector
[ 60%]: <app2> compiling.module.debug Vector
[ 70%]: compiling.debug cpp/apps/App1/app1.cpp
[ 80%]: compiling.debug cpp/apps/App2/app2.cpp
[ 85%]: linking.debug app2_linux_x86_64-debug
[ 95%]: linking.debug app1_linux_x86_64-debug

Now the only thing the linker does not find is SDL functions

$ xmake -vD
error: @programdir/core/main.lua:329: @programdir/actions/build/main.lua:148: @programdir/modules/async/runjobs.lua:322: @programdir/actions/build/kinds/binary.lua:53: @programdir/core/sandbox/modules/os.lua:378: execv(/usr/lib64/ccache/g++ -o build/linux/x86_64/debug/app1_linux_x86_64-debug build/.objs/app1/linux/x86_64/debug/cpp/apps/App1/app1.cpp.o build/.objs/app1/linux/x86_64/debug/cpp/my_lib/Math/Vector.mpp.o -m64 -Lbuild/linux/x86_64/debug -lglad) failed(1)
stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:973]:
    [@programdir/core/sandbox/modules/os.lua:378]: in function 'execv'
    [@programdir/modules/core/tools/gcc.lua:580]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]:
    [@programdir/core/tool/linker.lua:221]: in function 'link'
    [@programdir/actions/build/kinds/binary.lua:53]: in function 'callback'
    [@programdir/modules/core/project/depend.lua:217]: in function 'on_changed'
    [@programdir/actions/build/kinds/binary.lua:41]: in function '_do_link_target'
    [@programdir/actions/build/kinds/binary.lua:83]:
    [@programdir/actions/build/kinds/binary.lua:110]: in function '_link_target'
    [@programdir/actions/build/kinds/binary.lua:138]: in function 'jobfunc'
    [@programdir/modules/async/runjobs.lua:238]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:275]: in function 'trycall'
    [@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
    [@programdir/modules/async/runjobs.lua:220]: in function 'cotask'
    [@programdir/core/base/scheduler.lua:406]:

stack traceback:
        [C]: in function 'error'
        @programdir/core/base/os.lua:973: in function 'os.raiselevel'
        (...tail calls...)
        @programdir/core/main.lua:329: in upvalue 'cotask'
        @programdir/core/base/scheduler.lua:406: in function <@programdir/core/base/scheduler.lua:399>
waruqi commented 3 days ago

I need full projects and I don't have time to create them one by one.

paulross80 commented 1 day ago

Sorry. What do you mean by full project? a zip file? a public repo?

SirLynix commented 1 day ago

I think either would be fine, the idea is to be able to reproduce the bug in less than two minutes

waruqi commented 1 day ago

Sorry. What do you mean by full project? a zip file? a public repo?

a zip file with your all project files, you can upload it as issue attachment

paulross80 commented 17 hours ago

I see, thank you. Here is the project template_module_not_found.zip

waruqi commented 14 hours ago

It works for me on my fedora/gcc.

$ xmake -rv
checking for flags (gcc_deps_format) ... ok
checking for flags (gcc_deps_file) ... ok
checking for flags (gcc_deps_output) ... ok
[  0%]: <app1> generating.module.deps cpp/apps/App1/app1.cpp
checking for flags (-fvisibility-inlines-hidden) ... ok
checking for flags (-O2) ... ok
checking for flags (-std=c++23) ... ok
checking for flags (-D_GLIBCXX_USE_CXX11_ABI=0) ... ok
checking for flags (-DNDEBUG) ... ok
/usr/bin/gcc -m64 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -O2 -std=c++23 -I/mnt/template_module_not_found/cpp -Icpp/third_party/glad -fexceptions -finput-charset=UTF-8 -fexec-charset=UTF-8 -isystem /home/ruki/.xmake/packages/l/libsdl/2.30.4/4d6ee6e79e2743728490251a70ca0e42/include -isystem /home/ruki/.xmake/packages/l/libsdl/2.30.4/4d6ee6e79e2743728490251a70ca0e42/include/SDL2 -fmodules-ts -D_GLIBCXX_USE_CXX11_ABI=0 -DNDEBUG -E -x c++ cpp/apps/App1/app1.cpp -MT build/.gens/app1/linux/x86_64/release/rules/bmi/cache/modules/32ea7a34/app1.cpp.json -MD -MF build/.gens/app1/linux/x86_64/release/rules/bmi/cache/modules/32ea7a34/app1.cpp.d -fdeps-format=p1689r5 -fdeps-file=build/.gens/app1/linux/x86_64/release/rules/bmi/cache/modules/32ea7a34/app1.cpp.json -fdeps-target=build/.objs/app1/linux/x86_64/release/cpp/apps/App1/app1.cpp.o -o build/.gens/app1/linux/x86_64/release/rules/bmi/cache/modules/32ea7a34/app1.cpp.i
[  0%]: <app1> generating.module.deps cpp/my_lib/Math/Vector.mpp
/usr/bin/gcc -m64 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -O2 -std=c++23 -I/mnt/template_module_not_found/cpp -Icpp/third_party/glad -fexceptions -finput-charset=UTF-8 -fexec-charset=UTF-8 -isystem /home/ruki/.xmake/packages/l/libsdl/2.30.4/4d6ee6e79e2743728490251a70ca0e42/include -isystem /home/ruki/.xmake/packages/l/libsdl/2.30.4/4d6ee6e79e2743728490251a70ca0e42/include/SDL2 -fmodules-ts -D_GLIBCXX_USE_CXX11_ABI=0 -DNDEBUG -E -x c++ cpp/my_lib/Math/Vector.mpp -MT build/.gens/app1/linux/x86_64/release/rules/bmi/cache/modules/69159ac3/Vector.mpp.json -MD -MF build/.gens/app1/linux/x86_64/release/rules/bmi/cache/modules/69159ac3/Vector.mpp.d -fdeps-format=p1689r5 -fdeps-file=build/.gens/app1/linux/x86_64/release/rules/bmi/cache/modules/69159ac3/Vector.mpp.json -fdeps-target=build/.objs/app1/linux/x86_64/release/cpp/my_lib/Math/Vector.mpp.o -o build/.gens/app1/linux/x86_64/release/rules/bmi/cache/modules/69159ac3/Vector.mpp.i
checking for flags (gcc_module_mapper) ... ok
[  0%]: <my_lib> generating.module.deps cpp/my_lib/Math/Vector.mpp
/usr/bin/gcc -m64 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -O2 -std=c++23 -I/mnt/template_module_not_found/cpp -Icpp/third_party/glad -fexceptions -finput-charset=UTF-8 -fexec-charset=UTF-8 -isystem /home/ruki/.xmake/packages/l/libsdl/2.30.4/4d6ee6e79e2743728490251a70ca0e42/include -isystem /home/ruki/.xmake/packages/l/libsdl/2.30.4/4d6ee6e79e2743728490251a70ca0e42/include/SDL2 -fmodules-ts -D_GLIBCXX_USE_CXX11_ABI=0 -DNDEBUG -E -x c++ cpp/my_lib/Math/Vector.mpp -MT build/.gens/my_lib/linux/x86_64/release/rules/bmi/cache/modules/62063509/Vector.mpp.json -MD -MF build/.gens/my_lib/linux/x86_64/release/rules/bmi/cache/modules/62063509/Vector.mpp.d -fdeps-format=p1689r5 -fdeps-file=build/.gens/my_lib/linux/x86_64/release/rules/bmi/cache/modules/62063509/Vector.mpp.json -fdeps-target=build/.objs/my_lib/linux/x86_64/release/cpp/my_lib/Math/Vector.mpp.o -o build/.gens/my_lib/linux/x86_64/release/rules/bmi/cache/modules/62063509/Vector.mpp.i
[  0%]: <app2> generating.module.deps cpp/apps/App2/app2.cpp
/usr/bin/gcc -m64 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -O2 -std=c++23 -I/mnt/template_module_not_found/cpp -Icpp/third_party/glad -fexceptions -finput-charset=UTF-8 -fexec-charset=UTF-8 -isystem /home/ruki/.xmake/packages/l/libsdl/2.30.4/4d6ee6e79e2743728490251a70ca0e42/include -isystem /home/ruki/.xmake/packages/l/libsdl/2.30.4/4d6ee6e79e2743728490251a70ca0e42/include/SDL2 -fmodules-ts -D_GLIBCXX_USE_CXX11_ABI=0 -DNDEBUG -E -x c++ cpp/apps/App2/app2.cpp -MT build/.gens/app2/linux/x86_64/release/rules/bmi/cache/modules/a2e5a9c2/app2.cpp.json -MD -MF build/.gens/app2/linux/x86_64/release/rules/bmi/cache/modules/a2e5a9c2/app2.cpp.d -fdeps-format=p1689r5 -fdeps-file=build/.gens/app2/linux/x86_64/release/rules/bmi/cache/modules/a2e5a9c2/app2.cpp.json -fdeps-target=build/.objs/app2/linux/x86_64/release/cpp/apps/App2/app2.cpp.o -o build/.gens/app2/linux/x86_64/release/rules/bmi/cache/modules/a2e5a9c2/app2.cpp.i
[  0%]: <app2> generating.module.deps cpp/my_lib/Math/Vector.mpp
/usr/bin/gcc -m64 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -O2 -std=c++23 -I/mnt/template_module_not_found/cpp -Icpp/third_party/glad -fexceptions -finput-charset=UTF-8 -fexec-charset=UTF-8 -isystem /home/ruki/.xmake/packages/l/libsdl/2.30.4/4d6ee6e79e2743728490251a70ca0e42/include -isystem /home/ruki/.xmake/packages/l/libsdl/2.30.4/4d6ee6e79e2743728490251a70ca0e42/include/SDL2 -fmodules-ts -D_GLIBCXX_USE_CXX11_ABI=0 -DNDEBUG -E -x c++ cpp/my_lib/Math/Vector.mpp -MT build/.gens/app2/linux/x86_64/release/rules/bmi/cache/modules/b8076ef4/Vector.mpp.json -MD -MF build/.gens/app2/linux/x86_64/release/rules/bmi/cache/modules/b8076ef4/Vector.mpp.d -fdeps-format=p1689r5 -fdeps-file=build/.gens/app2/linux/x86_64/release/rules/bmi/cache/modules/b8076ef4/Vector.mpp.json -fdeps-target=build/.objs/app2/linux/x86_64/release/cpp/my_lib/Math/Vector.mpp.o -o build/.gens/app2/linux/x86_64/release/rules/bmi/cache/modules/b8076ef4/Vector.mpp.i
checking for the c compiler (cc) ... gcc
checking for flags (-O2) ... ok
checking for flags (-DNDEBUG) ... ok
[ 15%]: cache compiling.release cpp/third_party/glad/glad.c
/usr/bin/gcc -c -m64 -fvisibility=hidden -Wall -Wextra -O2 -Icpp/third_party/glad -fexceptions -finput-charset=UTF-8 -fexec-charset=UTF-8 -DNDEBUG -o build/.objs/glad/linux/x86_64/release/cpp/third_party/glad/glad.c.o cpp/third_party/glad/glad.c
checking for flags (-MMD -MF) ... ok
checking for ar ... /usr/bin/ar
checking for the static library archiver (ar) ... ar
[ 20%]: archiving.release libglad.a
/usr/bin/ar -cr build/linux/x86_64/release/libglad.a build/.objs/glad/linux/x86_64/release/cpp/third_party/glad/glad.c.o
checking for the c++ compiler (cxx) ... gcc
[ 55%]: <app1> compiling.module.release Vector
/usr/bin/gcc -c -m64 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -O2 -std=c++23 -I/mnt/template_module_not_found/cpp -Icpp/third_party/glad -fexceptions -finput-charset=UTF-8 -fexec-charset=UTF-8 -isystem /home/ruki/.xmake/packages/l/libsdl/2.30.4/4d6ee6e79e2743728490251a70ca0e42/include -isystem /home/ruki/.xmake/packages/l/libsdl/2.30.4/4d6ee6e79e2743728490251a70ca0e42/include/SDL2 -fmodules-ts -D_GLIBCXX_USE_CXX11_ABI=0 -DNDEBUG -fmodule-mapper=/tmp/.xmake995/240702/app1/cpp/my_lib/Math/Vector.mpp -x c++ -o build/.objs/app1/linux/x86_64/release/cpp/my_lib/Math/Vector.mpp.o cpp/my_lib/Math/Vector.mpp
[ 60%]: <app2> compiling.module.release Vector
/usr/bin/gcc -c -m64 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -O2 -std=c++23 -I/mnt/template_module_not_found/cpp -Icpp/third_party/glad -fexceptions -finput-charset=UTF-8 -fexec-charset=UTF-8 -isystem /home/ruki/.xmake/packages/l/libsdl/2.30.4/4d6ee6e79e2743728490251a70ca0e42/include -isystem /home/ruki/.xmake/packages/l/libsdl/2.30.4/4d6ee6e79e2743728490251a70ca0e42/include/SDL2 -fmodules-ts -D_GLIBCXX_USE_CXX11_ABI=0 -DNDEBUG -fmodule-mapper=/tmp/.xmake995/240702/app2/cpp/my_lib/Math/Vector.mpp -x c++ -o build/.objs/app2/linux/x86_64/release/cpp/my_lib/Math/Vector.mpp.o cpp/my_lib/Math/Vector.mpp
checking for flags (-fdiagnostics-color=always) ... ok
[ 70%]: compiling.release cpp/apps/App1/app1.cpp
/usr/bin/gcc -c -m64 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -O2 -std=c++23 -I/mnt/template_module_not_found/cpp -Icpp/third_party/glad -fexceptions -finput-charset=UTF-8 -fexec-charset=UTF-8 -isystem /home/ruki/.xmake/packages/l/libsdl/2.30.4/4d6ee6e79e2743728490251a70ca0e42/include -isystem /home/ruki/.xmake/packages/l/libsdl/2.30.4/4d6ee6e79e2743728490251a70ca0e42/include/SDL2 -fmodules-ts -D_GLIBCXX_USE_CXX11_ABI=0 -DNDEBUG -fmodule-mapper=/tmp/.xmake995/240702/app1/cpp/apps/App1/app1.cpp -o build/.objs/app1/linux/x86_64/release/cpp/apps/App1/app1.cpp.o cpp/apps/App1/app1.cpp
checking for flags (-MMD -MF) ... ok
[ 80%]: compiling.release cpp/apps/App2/app2.cpp
/usr/bin/gcc -c -m64 -fvisibility=hidden -fvisibility-inlines-hidden -Wall -Wextra -O2 -std=c++23 -I/mnt/template_module_not_found/cpp -Icpp/third_party/glad -fexceptions -finput-charset=UTF-8 -fexec-charset=UTF-8 -isystem /home/ruki/.xmake/packages/l/libsdl/2.30.4/4d6ee6e79e2743728490251a70ca0e42/include -isystem /home/ruki/.xmake/packages/l/libsdl/2.30.4/4d6ee6e79e2743728490251a70ca0e42/include/SDL2 -fmodules-ts -D_GLIBCXX_USE_CXX11_ABI=0 -DNDEBUG -fmodule-mapper=/tmp/.xmake995/240702/app2/cpp/apps/App2/app2.cpp -o build/.objs/app2/linux/x86_64/release/cpp/apps/App2/app2.cpp.o cpp/apps/App2/app2.cpp
checking for the linker (ld) ... g++
[ 85%]: linking.release app2_linux_x86_64-release
/usr/bin/g++ -o build/linux/x86_64/release/app2_linux_x86_64-release build/.objs/app2/linux/x86_64/release/cpp/apps/App2/app2.cpp.o build/.objs/app2/linux/x86_64/release/cpp/my_lib/Math/Vector.mpp.o -m64 -L/home/ruki/.xmake/packages/l/libsdl/2.30.4/4d6ee6e79e2743728490251a70ca0e42/lib -Lbuild/linux/x86_64/release -s -lSDL2main -lSDL2 -lglad -lpthread -ldl
[ 95%]: linking.release app1_linux_x86_64-release
/usr/bin/g++ -o build/linux/x86_64/release/app1_linux_x86_64-release build/.objs/app1/linux/x86_64/release/cpp/apps/App1/app1.cpp.o build/.objs/app1/linux/x86_64/release/cpp/my_lib/Math/Vector.mpp.o -m64 -L/home/ruki/.xmake/packages/l/libsdl/2.30.4/4d6ee6e79e2743728490251a70ca0e42/lib -Lbuild/linux/x86_64/release -s -lSDL2main -lSDL2 -lglad -lpthread -ldl
[100%]: build ok, spent 24.113s
waruqi commented 14 hours ago

try

add_packages("libsdl", {public = true})

and

add_requires("libsdl", {system = false})