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

Failure to install libsdl3 with clang/libc++ #6320

Open
RoqueDeicide opened this issue Feb 9, 2025 · 11 comments
Open

Failure to install libsdl3 with clang/libc++ #6320

RoqueDeicide opened this issue Feb 9, 2025 · 11 comments
Labels

Comments

@RoqueDeicide
Copy link

Xmake Version

2.9.8+HEAD.13fc39238

Operating System Version and Architecture

Windows 10 2022H2 x64

Describe Bug

Unable to install libsdl3 when using libc++ runtime library. Gonna have to use vcpkg::sdl3 in the mean time, since it works.

Expected Behavior

libsdl3 should install successfully.

Project Configuration

Here is my xmake.lua:

set_toolchains "clang"
set_runtimes "c++_static"		-- c++_shared has the same effect.
set_languages "c++latest"
add_requires "libsdl3"

target "libsdl3_issue"
    add_files "*.c++"
    add_packages "libsdl3"

    set_policy("build.c++.modules", true)

Here's my main.c++:

#include <SDL3/SDL.h>
	
import std;

int main (int, char *[])
{
    if (SDL_Init(SDL_INIT_EVENTS))
    {
        std::cout << "Hello SDL!\n";
        SDL_Quit();
    }
    return 0;
}

Additional Information and Error Logs

Here's the output of xmake:

checking for platform ... windows
checking for architecture ... x64
checking for Microsoft Visual Studio (x64) version ... 2022
checking for Microsoft C/C++ Compiler (x64) version ... 19.42.34436
note: install or modify (m) these packages (pass -y to skip confirm)?
in xmake-repo:
  -> libsdl3 3.2.2 [runtimes:"c++_static", toolchains:"clang", license:zlib]
please input: y (y/n/m)
y
  => install libsdl3 3.2.2 .. failed

LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
clang++: error: linker command failed with exit code 1120 (use -v to see invocation)
t.obj)' is imported by 'SDL3-static.lib(SDL_string.c.obj)' in function 'SDL_asprintf_REAL'
LINK : warning LNK4217: symbol 'atoi' defined in 'libucrt.lib(atox.obj)' is imported by 'SDL3-static.lib(SDL_string.c.obj)' in function 'SDL_atoi_REAL'
LINK : warning LNK4217: symbol '_ltoa' defined in 'libucrt.lib(xtoa.obj)' is imported by 'SDL3-static.lib(SDL_string.c.obj)' in function 'SDL_ltoa_REAL'
LINK : warning LNK4217: symbol '_ultoa' defined in 'libucrt.lib(xtoa.obj)' is imported by 'SDL3-static.lib(SDL_string.c.obj)' in function 'SDL_uitoa_REAL'
LINK : warning LNK4217: symbol '_i64toa' defined in 'libucrt.lib(xtoa.obj)' is imported by 'SDL3-static.lib(SDL_string.c.obj)' in function 'SDL_lltoa_REAL'
LINK : warning LNK4217: symbol '_ui64toa' defined in 'libucrt.lib(xtoa.obj)' is imported by 'SDL3-static.lib(SDL_string.c.obj)' in function 'SDL_ulltoa_REAL'
LINK : warning LNK4217: symbol 'wcsnlen' defined in 'libucrt.lib(strnlen.obj)' is imported by 'SDL3-static.lib(SDL_string.c.obj)' in function 'SDL_wcsnlen_REAL'
LINK : warning LNK4217: symbol 'wcsncmp' defined in 'libucrt.lib(wcsncmp.obj)' is imported by 'SDL3-static.lib(SDL_string.c.obj)' in function 'SDL_wcsncmp_REAL'
LINK : warning LNK4217: symbol 'strncmp' defined in 'libucrt.lib(strncmp.obj)' is imported by 'SDL3-static.lib(SDL_string.c.obj)' in function 'SDL_strncmp_REAL'
LINK : warning LNK4217: symbol 'strnlen' defined in 'libucrt.lib(strnlen.obj)' is imported by 'SDL3-static.lib(SDL_string.c.obj)' in function 'SDL_strndup_REAL'
LINK : warning LNK4217: symbol 'strpbrk' defined in 'libucrt.lib(strpbrk.obj)' is imported by 'SDL3-static.lib(SDL_string.c.obj)' in function 'SDL_strpbrk_REAL'
LINK : warning LNK4217: symbol '__acrt_iob_func' defined in 'libucrt.lib(_file.obj)' is imported by 'SDL3-static.lib(SDL_assert.c.obj)' in function 'SDL_PromptAssertion'
LINK : warning LNK4217: symbol 'fflush' defined in 'libucrt.lib(fflush.obj)' is imported by 'SDL3-static.lib(SDL_assert.c.obj)' in function 'SDL_PromptAssertion'
LINK : warning LNK4217: symbol '__stdio_common_vfprintf' defined in 'libucrt.lib(output.obj)' is imported by 'SDL3-static.lib(SDL_assert.c.obj)' in function '_vfprintf_l'
LINK : warning LNK4217: symbol 'calloc' defined in 'libucrt.lib(calloc.obj)' is imported by 'SDL3-static.lib(SDL_malloc.c.obj)' in function 'real_calloc'
if you want to get more verbose errors, please see:
  -> C:\Users\Deicide\AppData\Local\.xmake\cache\packages\2502\l\libsdl3\3.2.2\installdir.failed\logs\install.txt
error: install failed!
warning: add_cxflags("-stdlib=libc++ "-cxx-isystemC:\\Program Files\\LLVM\\include\\c++\\v1"") is ignored, please pass `{force = true}` or call `set_policy("check.auto_ignore_flags", false)` if you want to set it.
@SirLynix
Copy link
Member

SirLynix commented Feb 9, 2025

Could you post the verbose/diagnosis installation logs? (-vD)

@RoqueDeicide
Copy link
Author

Here you go.

install.log

@SnowinterCat
Copy link
Contributor

SnowinterCat commented Mar 8, 2025

I noticed that you are using the clang toolchain on Windows as well as the libc++ runtime, there should be some errors here.

When the host is Windows, the clang toolchain for the Windows platform is clang-cl and the runtime should be along the Windows platform runtime: MD, MDd, MT, MTd.
When the host is Windows or Linux, the clang toolchain for the mingw platform is LLVM-mingw, the platform should be set to mingw, and the runtimes should follow the Linux platform runtimes stdc++_shared, stdc++_static.
If the host is Linux, the clang toolchain for the linux platform is clang-gcc, the platform should be set to linux, and the runtime should follow the linux platform runtime stdc++_shared, stdc++_static.
If the host is a mac, the runtime of the clang toolchain for macos platform is c++_static, c++_shared.

Referring to your logs, I think you are using clang-cl. so you should change it to:

set_toolchains “clang-cl”
set_runtimes “MT” -- MD
set_languages “c++latest”
add_requires “libsdl3”

target “libsdl3_issue”
    add_files “*.c++”
    add_packages “libsdl3”

    set_policy(“build.c++.modules”, true)

Or write xmake.lua like this (Not specifying the compiler and runtime in the project) and configure the project like this:

set_languages “c++latest”
add_requires “libsdl3”

target “libsdl3_issue”
    add_files “*.c++”
    add_packages “libsdl3”

    set_policy(“build.c++.modules”, true)
xmake f -p windows -a x64 -m release -k shared --runtimes=MD --toolchain=clang-cl -cv

@RoqueDeicide
Copy link
Author

there should be some errors here.

No, there shouldn't be any errors, building and using libc++ on Windows isn't even considered experimental anymore, and I can still use SDL3 through vcpkg.

@SnowinterCat
Copy link
Contributor

SnowinterCat commented Mar 8, 2025

there should be some errors here.

No, there shouldn't be any errors, building and using libc++ on Windows isn't even considered experimental anymore, and I can still use SDL3 through vcpkg.

Also just because vcpkg uses libc++, and the c++_static runtime inside doesn't mean it should be done in xmake, it's just a way of naming it, call it whatever you want if you can. But there are rules in xmake, and according to the instructions here, c++_shared refers exclusively to the clang backend runtime on xmake.
But there are only two clang compiler on window:

  1. clang-cl, the front-end of clang, the back-end of msvc, its runtime is consistent with msvc
  2. LLVM-mingw,front-end of clang,back-end of mingw,its runtime is consistent with gcc.

@SnowinterCat
Copy link
Contributor

I've tried to compile libsdl3 with clang-cl and llvm-mingw. They're all working fine.
You can try it with code from my test repository: https://github.com/SnowinterCat/test
The configuration command is:

xmake f -p windows -a x64 -m release -k shared --runtimes=MD --3rd_kind=shared --toolchain=clang-cl -cv

Normally, only the fmt library gives an error because cmake can't find ninja, but libsdl3 compiles successfully.

@SnowinterCat
Copy link
Contributor

I observed this path in your error log: C:\\Program Files\LLVM\\include\c++\v1
Then it's safe to assume that you're using your own installation of clang-cl.
You should use clang-cl like I did above.

Tips: It's much easier to use the visual studio installation of clang-cl, but it's only version 19.1.1.

@Shiffted
Copy link
Contributor

Shiffted commented Mar 8, 2025

You do not need clang-cl to compile on Windows with clang, clang + libc++ should generally work. However, xmake-repo only supports msvc and clang-cl on Windows for packages build with cmake.

@RoqueDeicide
Copy link
Author

I did some investigating, and I was able to build and run above project by adding the following:

add_sysincludedirs "<path to installed libsdl3 package>\\include"
add_linkdirs "<path to installed libsdl3 package>\\lib"
add_syslinks("user32", "gdi32", "winmm", "imm32", "ole32", "oleaut32",
             "version", "uuid", "advapi32", "setupapi", "shell32")
add_links "SDL3-static"

This uses a libsdl3 package that was installed for a different project that was using "MT" runtime. I don't know, if this helps.

@RoqueDeicide
Copy link
Author

I've also attempted to use shared config of libsdl3 and I've got a different problem: when invoking a linker, one of command line arguments isn't enclosed in quotes, which causes it to break in 2 parts.

What the argument should be:

-L"C:\\Program Files\\LLVM\\lib"

Here is the one from the invocation:

-LC:\\Program Files\\LLVM\\lib

As you can see, it gets broken into "-LC:\\Program" and "Files\\LLVM\\lib".

The whole invocation:

C:\Windows\system32\cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_dll --msvc-ver=1943 --intdir=CMakeFiles\SDL3-shared.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x64\mt.exe --manifests  -- C:\PROGRA~1\MICROS~4\2022\COMMUN~1\VC\Tools\MSVC\1443~1.348\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\SDL3-shared.rsp  /out:SDL3.dll /implib:SDL3.lib /pdb:pdb\SDL3.pdb /dll /version:0.0 /machine:x64 /machine:x64 /INCREMENTAL:NO -stdlib=libc++ -LC:\\Program Files\\LLVM\\lib && cd ."

@RoqueDeicide
Copy link
Author

It looks like, I've found a workaround for this issue, until it's fixed:
Change add_requires "libsdl3" to add_requires("libsdl3", {configs = {runtimes = "MT"}}).

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

4 participants