On Fri, Aug 14, 2020 at 8:29 AM <[email protected]> wrote:
>
> i'm trying to create an object file by using "go build" for GOOS=linux 
> GOARCH=386.
> My current go environment has GOOS=linux GOARCH=amd64.
>
> i know that go build directly builds and links the files, but i want to link 
> files using an external linker file, so i need only the object file to be 
> created.
>
> i have tried to look up ways to do so, but i could not find any solution to 
> this.
>
> The files i'm trying to compile can be .go files that have a main function or 
> just a non-main-package.

There is no way to do this for a non-main package.  I'm not sure how
that makes sense.  There wouldn't be any way for you to use such an
object.

For a main package, one trick to get you started is to use to use go
build -ldflags="-linkmode=external -extld=/bin/echo".  That will show
you how the external linker is invoked, including the objects that are
passed to it.  If you also use the go build -work option, it will save
the temporary directory, and you can grab the objects.  Then in
principle you can copy those objects to the target system and run the
linker command there.

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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXTmtoC_yiO9JAhG2Bk8T7GU6M0EUzEwsKZjwFC7BKz5w%40mail.gmail.com.

Reply via email to