12/13/2025 at 1:05:46 AM
I ran into this issue when porting term.everything[0] from typescript to go. I had some c library dependencies that I did need to link, so I had to use cgo. My solution was to do the build process on alpine linux[1] and use static linking[2]. This way it statically links musl libc, which is much friendlier with static linking than glibc. Now, I have a static binary that runs in alpine, Debian, and even bare containers.Since I have made the change, I have not had anyone open any issues saying they had problems running it on their machines. (Unlike when I was using AppImages, which caused much more trouble than I expected)
[0] https://github.com/mmulet/term.everything look at distribute.sh and the makefile to see how I did it.
[1]in a podman or docker container
[2] -ldflags '-extldflags "-static"'
by mmulet
12/13/2025 at 3:40:55 AM
IMO this is the best approach, but it is worth noting that musl libc is not without its caveats. I'd say for most people it is best to tread carefully and make sure that differences between musl libc and glibc don't cause additional problems for the libraries you are linking to.There is a decent list of known functional differences on the musl libc wiki:
https://wiki.musl-libc.org/functional-differences-from-glibc...
Overall, though, the vast majority of software works perfectly or near perfectly on musl libc, and that makes this a very compelling option indeed, especially since statically linking glibc is not supported and basically does not work. (And obviously, if you're already using library packages that are packaged for Alpine Linux in the first place, they will likely already have been tested on musl libc, and possibly even patched for better compatibility.)
by jchw
12/13/2025 at 9:36:33 AM
That is a nice approach. I'll have to give that a try with rclone. I tried lots of things in the past but not using Alpine which is a great ideaAnother alternative is
https://github.com/ebitengine/purego
You can use this to dynamic load shared objects / DLLs so in the OP example they could disable systemd support if the systemd shared object did not load.
This technique is used in the cgofuse library ( https://github.com/winfsp/cgofuse ) rclone uses which means rclone can run even if you don't have libfuse/winfsp installed. However the rclone mount subcommand won't work.
The purego lib generalizes this idea. I haven't got round to trying this yet but it looks very promising.
by nickcw
12/13/2025 at 1:19:38 PM
I am using purego indirectly in two pet projects of mine. While it has its own issues it definitely solves the issue of cross-compilation.In this particular case it may be that they will need to write a wrapper to abstract differences between the systemd C API if it is not stable, but at least they still can compile a binary from macOS to Linux without issues.
The other issue as other said is to use journalctl and just parse the JSON format. Very likely that this would be way more stable, but not sure if it is performant enough.
by kokada
12/13/2025 at 10:20:47 AM
I use `-ldflags '-extldflags "-static"` as well.From the .go file, you just do `// #cgo LDFLAGS: -L. -lfoo`.
You definitely do not need Alpine Linux for this. I have done this on Arch Linux. I believe I did not even need musl libc for this, but I potentially could have used it.
I did not think I was doing something revolutionary!
In fact, let me show you a snippet of my build script:
# Build the Go project with the static library
if go build -o $PROG_NAME -ldflags '-extldflags "-static"'; then
echo "Go project built with static library linkage"
else
echo "Error: Failed to build the Go project with static library"
exit 1
fi
# Check if the executable is statically linked
if nm ./$PROG_NAME | grep -q "U "; then
echo "Error: The generated executable is dynamically linked"
exit 1
else
echo "Successfully built and verified static executable '$PROG_NAME'"
fi
And like I said, the .go file in question has this: // #cgo LDFLAGS: -L. -lfoo
It works perfectly, and should work on any Linux distribution.
by johnisgood
12/13/2025 at 3:34:36 PM
I use alpine for this [1] reason, but I will admit that this is a premature-optimization. I haven’t actually ran into the problem myself.——
Your code is great, I do basically the same thing (great minds think alike!). The only thing I want to add is that cgo supports pkg-config directly [2] via
// #cgo pkg-config: $lib
So you don’t have to pass in linker flags manually. It’s incredibly convenient.[1]https://stackoverflow.com/questions/57476533/why-is-statical...
[2]https://github.com/mmulet/term.everything/blob/def8c93a3db25...
by mmulet
12/13/2025 at 11:56:06 AM
> do the build process on alpine linux and […] statically link musl libcIIRC it used to be common to do builds on an old version of RHEL or CentOS and dynamically link an old version of glibc. Binaries would then work on newer systems because glibc is backwards compatible.
Does anyone still use that approach?
by pansa2
12/13/2025 at 2:39:00 PM
If you need glibc for any kind of reason, that approach is still used. But that won’t save you if no glibc is available. And since the folks here want to produce a musl build anyways for alpine, the easier approach is to just go for musl all the way.by Xylakant
12/13/2025 at 3:52:51 AM
Note that you don't have to compile on an Alpine system to achieve this. These instructions should work on most distros:by apitman
12/13/2025 at 10:02:59 AM
> and even bare containers.Strange, i thought the whole point of containers was to solve this problem.
by nly
12/15/2025 at 9:10:15 AM
The whole point of containers is to ship almost the whole OS with the application (It is a technical implementation of the "works on my machine" concept). If the OS you put in your container (by just pulling in a prebuilt image from somewhere) doesn't have the necessary things, then the application would fail to work just the same as if you ran it on the bare operating system with the the same missing libraries.by vrighter
12/13/2025 at 1:12:23 PM
Depends how much you care about the size and security footprint of your container images.by jdub
12/13/2025 at 11:50:04 AM
What troubles did you have with AppImages?by imcritic
12/13/2025 at 2:49:02 PM
List of troubles:[1]https://github.com/mmulet/term.everything/issues/28
[2]https://github.com/mmulet/term.everything/issues/18 (although this issue later gets sidetracked to a build issue)
by mmulet
12/13/2025 at 6:30:03 AM
Huh. Does term.everything just work, or are there some gotchas? This seems like it could be supremely useful!by tasuki
12/13/2025 at 2:56:37 PM
It works so far! No major gotchas that I know of yet. From the perspective of the apps, they are just talking to a normal Wayland compositor, so everything works as expected. Just try it for your workflow, and if you run into any problems just open an issue and I’ll fix it.by mmulet
12/13/2025 at 1:52:57 AM
I didn't see an explanation in the README that part of what the first GIF[1] shows is an effect created by video editing software (and not a screencapture that's just demonstrating the program actually running). "Screen images simulated" are the words usually chosen to start off the disclaimers in fine print shown at the bottom of the screen when similar effects appear in commercials. I think that it would make sense to adopt a similar explanation wrt the effect used for the GIF.1. <https://github.com/mmulet/term.everything/blob/main/resource...>
by cxr
12/13/2025 at 2:42:07 AM
Why would an open source project need to have any disclaimer? They are not selling anything.by plufz
12/13/2025 at 2:44:10 AM
Because lying is wrong even when open source projects do it.by nofriend
12/13/2025 at 2:54:31 AM
I think it is a big stretch calling this visual effect lying.I don’t know if it is a cultural American thing or just difference in interpretation but I had no difficulty understanding that this was a visual effect. But in my country ads don’t come with disclaimers. Do you feel like these disclaimers are truly helpful?
by plufz
12/13/2025 at 3:32:00 AM
I don't feel that the person I responded to is lying or being intentionally deceptive.by cxr
12/13/2025 at 3:31:34 AM
> “in commercials where such effects appear”Good thing this isn’t a commercial then.
by nebezb
12/13/2025 at 3:28:38 AM
[dead]by hmans