Correction. When I'm using -buildmode pie it producing weired file static /
dynamic:

#  go install -ldflags "-extldflags -static" -buildmode pie
gitlab.com/axet/swap@swap-0.0.4

# file .go/bin/swap
.go/bin/swap: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV),
dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, Go
BuildID=IdU-e_SYkwhiX9RUPRZ1/FCjd89you8IzAl7nDax_/7ww2AvzWZX8UIdMsxhe8/o5djfvZtYWIn7ldfOiOl,
with debug_info, not stripped

# ldd .go/bin/swap
statically linked


-- AK


On Sat, Nov 19, 2022 at 6:03 PM Alexey Kuznetsov <kuznetsov.ale...@gmail.com>
wrote:

> 'file' command used to say "dynamically linked" if I'm not using '-linkmode
> external' flag. I tried many times, I didn't pay attention, now it's
> working...I guess the only question left with "loadinternal: cannot find
> runtime/cgo"
>
> -- AK
>
>
> On Sat, Nov 19, 2022 at 5:49 PM Ian Lance Taylor <i...@golang.org> wrote:
>
>> 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/CAO1Zr%2BoX-iiDaSS6AMUUocH0wXjw-8Wqi%3Ddk85q1peHinZaRYQ%40mail.gmail.com.

Reply via email to