simonkrauter/NiGui

static compile success but execute error, please help

Opened this issue · 3 comments

# nim -V
Nim Compiler Version 2.0.2 [Linux: amd64]
Compiled at 2024-02-23
Copyright (c) 2006-2023 by Andreas Rumpf

active boot switches: -d:release
# nimble list --installed | grep -i 'nigui'
nigui  [(version: 0.2.8, checksum: 62a648324e3a145b34aa3384e9484cd07f88ce54)]
# nim c --passL="-static" example_02_controls.nim
Hint: used config file '/root/nim-2.0.2/config/nim.cfg' [Conf]
Hint: used config file '/root/nim-2.0.2/config/config.nims' [Conf]
.............................................................................................................................
Hint:  [Link]
/usr/bin/ld: /root/.cache/nim/example_02_controls_d/@mnim-2.0.2@slib@ssystem.nim.c.o: in function `nimLoadLibrary':
@mnim-2.0.2@slib@ssystem.nim.c:(.text+0xb8ae): 警告: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
Hint: mm: orc; threads: on; opt: none (DEBUG BUILD, `-d:release` generates faster code)
61077 lines; 0.811s; 109.23MiB peakmem; proj: /root/example_02_controls.nim; out: /root/example_02_controls [SuccessX]
# ./example_02_controls
Traceback (most recent call last)
/root/example_02_controls.nim(14) example_02_controls
/root/NiGui/src/nigui.nim(917) add
/root/NiGui/src/nigui/private/gtk3/platform_impl.nim(1283) add
/root/NiGui/src/nigui.nim(2081) add
/root/NiGui/src/nigui.nim(1133) triggerRelayout
/root/NiGui/src/nigui/private/gtk3/platform_impl.nim(965) triggerRelayout
/root/NiGui/src/nigui.nim(1819) triggerRelayout
/root/NiGui/src/nigui.nim(1599) triggerRelayout
/root/NiGui/src/nigui.nim relayout
/root/NiGui/src/nigui.nim(1839) relayout
/root/NiGui/src/nigui.nim(810) naturalWidth
/root/NiGui/src/nigui.nim(2236) naturalWidth
/root/NiGui/src/nigui.nim(814) wantedWidth
/root/NiGui/src/nigui.nim(1776) wantedWidth
/root/NiGui/src/nigui.nim(810) naturalWidth
/root/NiGui/src/nigui/private/gtk3/platform_impl.nim(1376) naturalWidth
/root/NiGui/src/nigui.nim(823) getTextLineWidth
/root/NiGui/src/nigui/private/gtk3/platform_impl.nim(1195) getTextLineWidth
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
段错误 (核心已转储)

When I build it with zig cc

# nim c -d:release --opt:size --cpu:amd64 --os:linux --cc:clang --clang.exe="zigcc" --clang.linkerexe="zigcc" --passC:"-target x86_64-linux-musl" --passL:"-target x86_64-linux-musl -s -static" example_02_controls.nim
Hint: used config file '/root/nim-2.0.2/config/nim.cfg' [Conf]
Hint: used config file '/root/nim-2.0.2/config/config.nims' [Conf]
.............................................................................................................................
CC: nim-2.0.2/lib/system/exceptions.nim
CC: nim-2.0.2/lib/std/private/digitsutils.nim
CC: nim-2.0.2/lib/std/assertions.nim
CC: nim-2.0.2/lib/system/dollars.nim
CC: nim-2.0.2/lib/system.nim
CC: nim-2.0.2/lib/pure/math.nim
CC: nim-2.0.2/lib/pure/unicode.nim
CC: nim-2.0.2/lib/pure/strutils.nim
CC: nim-2.0.2/lib/pure/pathnorm.nim
CC: nim-2.0.2/lib/std/private/oscommon.nim
CC: nim-2.0.2/lib/std/private/ospaths2.nim
CC: nim-2.0.2/lib/pure/times.nim
LLD Link... LLD Link... LLD Link... LLD Link... LLD Link... CC: nim-2.0.2/lib/std/envvars.nim
CC: nim-2.0.2/lib/std/cmdline.nim
CC: nim-2.0.2/lib/pure/os.nim
CC: NiGui/src/nigui/private/gtk3/gtk3.nim
CC: nim-2.0.2/lib/pure/collections/tables.nim
CC: NiGui/src/nigui.nim
CC: example_02_controls.nim
Hint:  [Link]
Hint: mm: orc; threads: on; opt: size; options: -d:release
61077 lines; 12.051s; 109.152MiB peakmem; proj: /root/example_02_controls.nim; out: /root/example_02_controls [SuccessX]
# ./example_02_controls
could not load: libgtk-3.so(|.0)
(compile with -d:nimDebugDlOpen for more information)
# file example_02_controls
example_02_controls: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
# which zigcc
/usr/bin/zigcc
# cat /usr/bin/zigcc
#!/bin/bash
zig cc $@
# zig version
0.11.0
# zig cc --version
clang version 16.0.6 (https://github.com/ziglang/zig-bootstrap 1dda86241204c4649f668d46b6a37feed707c7b4)
Target: x86_64-unknown-linux-musl
Thread model: posix
InstalledDir: /usr/bin

I get a "SIGSEGV: Illegal storage" access too (Linux amd64 as well).
I don't know about static compilation and I feel that this is not a problem of something specific in NiGui.
The compiler shows the warning:

Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

Maybe this is the issue?

I known. I will abandon static linking,I will build my program on lower version OS to be compatible with glibc version