On Sat, Nov 19, 2022, 6:46 AM Alexey Kuznetsov <kuznetsov.ale...@gmail.com>
wrote:

>
> I'm trying to build statically linked binary and it works with 'build'
> command but failed with 'install' command. Here is an example:
>
> go build -ldflags "-linkmode external -extldflags -static" -a swap.go
>
> # file swap
> swap: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically
> linked, BuildID[sha1]=396a1f51971f4e0d44bfb489a84792efc1782e03, for
> GNU/Linux 3.2.0, with debug_info, not stripped
>
> # ldd swap
>     not a dynamic executable
>
> But following failed:
>
> #  go install -ldflags "-linkmode external -extldflags -static"
> gitlab.com/axet/swap@swap-0.0.4
> # gitlab.com/axet/swap
> loadinternal: cannot find runtime/cgo
>
> Following compiles but not as static:
>
> # go install -ldflags "-extldflags -static"
> gitlab.com/axet/swap@swap-0.0.4
>
> # file ~/.go/bin/swap
> /home/axet/.go/bin/swap: ELF 64-bit LSB executable, x86-64, version 1
> (SYSV), statically linked, Go
> BuildID=8DAAfOPcNpPhyRmJINiQ/RJu44gsWAPnCPTRsFMPn/vAto5mmPDQDM4aX1HuBe/7MY6v2L5JqkYe2MJN8uw,
> with debug_info, not stripped
>
> # ldd ~/.go/bin/swap
>     not a dynamic executable
>

They both look static to me.  What is the difference?

Ian

>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVTkVByZ84VThX9qy9W8syMaWnS4QhnUZC4-OMCTwvadw%40mail.gmail.com.

Reply via email to