Static link standard library?

瀏覽次數:766 次
跳到第一則未讀訊息

supsm17

未讀,
2022年4月5日 下午2:51:172022/4/5
收件者:fltk.general
I want to static link the standard library (glibc) for my application so it could be run on older machines. I'm using cmake to build fltk and my project. Without fltk it compiles fine, but with fltk it gives the following error:  /usr/bin/ld: attempted static link of dynamic object `/usr/lib/x86_64-linux-gnu/libdl.so'. I'm adding the -static flag with target_link_libraries in cmake. How would I do this for fltk, if possible?

Greg Ercolano

未讀,
2022年4月5日 下午2:55:232022/4/5
收件者:fltkg...@googlegroups.com

On 4/5/22 10:50, supsm17 wrote:

I want to static link the standard library (glibc) for my application so it could be run on older machines. I'm using cmake to build fltk and my project. Without fltk it compiles fine, but with fltk it gives the following error:  /usr/bin/ld: attempted static link of dynamic object `/usr/lib/x86_64-linux-gnu/libdl.so'. I'm adding the -static flag with target_link_libraries in cmake. How would I do this for fltk, if possible?

    I don't know myself, but perhaps just look for a ".a" version of libdl and link to that?

    On my system it's: /usr/lib/x86_64-linux-gnu/libdl.a

    Not sure if it's an 'option' to have this file.
    Looks like it's part of the "libc6-dev" package on Ubuntu 20.x:

$ dpkg -S /usr/lib/x86_64-linux-gnu/libdl.a
libc6-dev:amd64: /usr/lib/x86_64-linux-gnu/libdl.a


Ian MacArthur

未讀,
2022年4月5日 下午3:31:532022/4/5
收件者:Fltk General
On 5 Apr 2022, at 18:50, supsm17 wrote:
>
> I want to static link the standard library (glibc) for my application so it could be run on older machines. I'm using cmake to build fltk and my project. Without fltk it compiles fine, but with fltk it gives the following error: /usr/bin/ld: attempted static link of dynamic object `/usr/lib/x86_64-linux-gnu/libdl.so’.


I’m far from convinced that’s a good idea - on Linux systems it’s generally a better idea to use the system libs, so they match the runtime and the loader, rather than try to force our code to use the same everywhere...

The glibc ABI hasn’t changed much (if at all) in a very long time so code compatibility should not be an issue.

Unless you mean *really* old systems from the pre-glibc days? They will not work with your static linked libc anyway...



supsm17

未讀,
2022年4月6日 凌晨3:10:422022/4/6
收件者:fltk.general
A cross-compiled binary from x64 to aarch64 doesn't seem to work on my raspberry pi as the glibc version is too old. I'm worried a similar thing may happen to other devices. If there's another way to get around this I'm more than happy to do it instead.

Ian MacArthur

未讀,
2022年4月6日 凌晨3:42:232022/4/6
收件者:fltk.general
On Wednesday, 6 April 2022 at 08:10:42 UTC+1 sups... wrote:
A cross-compiled binary from x64 to aarch64 doesn't seem to work on my raspberry pi as the glibc version is too old. I'm worried a similar thing may happen to other devices. If there's another way to get around this I'm more than happy to do it instead.


Um... I don't understand that: if you are cross compiling from one architecture to another, then the various libs and versions thereof on the host, have no bearing at all, since the cross-compilation environment for the target must provide the full compilation context for the target (tools, headers, libraries).
So if your cross-compile environment is correctly set up to match your target, it doesn't matter what your host is. (Your x64 glibc is no use whatsoever on an ARM target.)

Oh - there's a thing; what OS are you running on the R.Pi?
The "stock" R.Pi runtime is not aarch64, they use a legacy 32-bit ABI for backwards compatibility (IIRC something between V6 and V7, so that even new code will run on the early boards) even though the SOC they use has been ARM64 capable for a while. But if you are running stock Raspbian/PiOS then aarch64 is the wrong target arch.

Though of course there is a Raspbian/PiOS 64-bit branch now and others (Ubuntu) also have 64-bit ports...

FWIW, in my testing, the 64-bit port is not a win at present - there are no Pi boards with enough RAM for it to matter, and there's no discernible performance gain in my testing either...

supsm17

未讀,
2022年4月9日 下午4:20:032022/4/9
收件者:fltk.general
I'm using gcc-10-aarch64-linux-gnu to cross compile for arm. When I specify the -static flag (without fltk), it works as expected, but of course there's no gui. Without the -static flag it produces the glibc error.

I am running the 64-bit version of raspbian mostly because more applications support it, but regardless it works with my cross-compilation setup when static linking standard libraries.

回覆所有人
回覆作者
轉寄
0 則新訊息