slint icon indicating copy to clipboard operation
slint copied to clipboard

CMake build links to stdc++ no matter what the config.toml is

Open mccakit opened this issue 2 months ago • 5 comments

Bug Description

When I build slint using cmake, my config.toml is ignored, and library links to whatever it wants, building from rust doesn't have this issue.

I think it would be useful, if we could just compile the library and the compiler from rust seperately. Maybe something like cargo-cbuild?

Currently this is a very big deal for me, because I can't use libc++ if I use slint. I would be forced to use the platform default stdlib, which I don't want.

Reproducible Code (if applicable)

set(SLINT_FEATURE_BACKEND_QT OFF)
set(SLINT_FEATURE_RENDERER_FEMTOVG OFF)
set(SLINT_FEATURE_RENDERER_FEMTOVG_WGPU OFF)
set(SLINT_FEATURE_TESTING OFF)
set(SLINT_FEATURE_ACCESSIBILITY OFF)
set(SLINT_FEATURE_RENDERER_SKIA_VULKAN ON)
add_subdirectory(slint)
----

[target.x86_64-unknown-linux-gnu]
rustflags = [
    "-C", "linker=clang",
    "-C", "link-arg=-fuse-ld=lld",
    "-C", "link-arg=-rtlib=compiler-rt",
    "-C", "link-arg=-nostdlib++",
    "-C", "link-arg=/home/mccakit/dev/libcxx/native/lib/libc++.a",
    "-C", "link-arg=/home/mccakit/dev/libcxx/native/lib/libc++abi.a",
    "-C", "link-arg=/home/mccakit/dev/libcxx/native/lib/libunwind.a"
]
[env]
CC="/home/mccakit/dev/llvm/bin/clang"
CXX="/home/mccakit/dev/llvm/bin/clang++"
AR="/home/mccakit/dev/llvm/bin/llvm-ar"
RANLIB="/home/mccakit/dev/llvm/bin/llvm-ranlib"
STRIP="/home/mccakit/dev/llvm/bin/llvm-strip"
WINDRES="/home/mccakit/dev/llvm/bin/llvm-windres"
DLLTOOL="/home/mccakit/dev/llvm/bin/llvm-dlltool"
CFLAGS_x86_64_unknown_linux_gnu="-std=gnu23 -O3 -DNDEBUG -fPIC"
CXXFLAGS_x86_64_unknown_linux_gnu="-std=c++26 -O3 -DNDEBUG -fPIC -nostdinc++ -nostdlib++ -isystem /home/mccakit/dev/libcxx/native/include/c++/v1"
LDFLAGS_x86_64_unknown_linux_gnu="-fuse-ld=lld -nostdlib++ -rtlib=compiler-rt /home/mccakit/dev/libcxx/native/lib/libunwind.a /home/mccakit/dev/libcxx/native/lib/libc++abi.a /home/mccakit/dev/libcxx/native/lib/libc++.a"


---
#include "hello.h"

int main()
{
    auto app = MyApp::create();
    app->run();
    return 0;
}

----

cpp crate depends on stdc++ and gcc_s and I link libc++ via cmake, causing a crash.

---

Cargo builds don't have this problem

Environment Details

  • Slint Version:
  • Platform/OS:
  • Programming Language:
  • Backend/Renderer:

Product Impact

No response

mccakit avatar Nov 12 '25 23:11 mccakit

Our rust binary shouldn't link to any C++ library (unless the Qt backend is active, but it seems you don't activate it)

ldd build/api/cpp/libslint_cpp.so
        linux-vdso.so.1 (0x00007f4824838000)
        libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f4820f8e000)
        libm.so.6 => /usr/lib/libm.so.6 (0x00007f4820e80000)
        libc.so.6 => /usr/lib/libc.so.6 (0x00007f4820c00000)
        /usr/lib64/ld-linux-x86-64.so.2 (0x00007f482483a000)

ogoffart avatar Nov 25 '25 14:11 ogoffart

Well, probably something about how cmake invokes cargo. Have you build the slint-cpp via rust directly or with cmake

mccakit avatar Nov 25 '25 19:11 mccakit

Via cmake

Edit: I mean, using the cmake on our recommended way, which uses corrosion to call cargo.

ogoffart avatar Nov 25 '25 19:11 ogoffart

Hmm, how about I give my toolchain file and post libc++ as a tarball here?

Perhaps then you could replicate it?

I assume your host is x64 Ubuntu though I can also give libc++ tarball for Debian-arm64 and Debian x64, all of them link to stdc++ when I build slint-cpp via cmake

mccakit avatar Nov 25 '25 19:11 mccakit

Could you post a verbose build log or extract at least the link line out of a build of yours?

libslint_cpp.so, as created by the linker rust calls, is not by default instructed to link against libstdc++. rustc only creates c libraries anyway, and our „C++“ library is the C .so that rustc creates (through native linker invocation) combined with C++ header files.

tronical avatar Nov 25 '25 21:11 tronical