Option -Wl,--whole-archive seems not work

220 views
Skip to first unread message

Thierry Fournier

unread,
Oct 17, 2020, 3:26:08 PM10/17/20
to golang-nuts
Hi,

I need to build go with an archive file which requires to be linked with the option "-Wl,--whole-archive" on linux or "-Wl,-all_load" on macos.

My go file contains this code:

/*

#cgo darwin LDFLAGS: -L.. -Wl,-all_load -lmy_lib
 
#cgo linux LDFLAGS: -L.. -Wl,--whole-archive -lmy_lib 

*/
import "C"

When I try to compile on Linux or Mac, this doesn't work. I read these errors:

Mac:

go build _/Users/thierryfournier/git/my-lib/my_lib: invalid flag in #cgo LDFLAGS: -Wl,-all_load 

Linux:

go build _/home/thierry/my_lib/my_lib: invalid flag in #cgo LDFLAGS: -Wl,--whole-archive 

I test the local link on both OS, and the option exists and works for c.

So, i don’t found any way to embed the whole library.

  • I don’t find a way to understand how the linker is called
  • I don’t find documentation about supported flag.

If anyone has a solution or a clue, it will be welcome

Thanks,
Thierry


Ian Lance Taylor

unread,
Oct 17, 2020, 6:57:02 PM10/17/20
to Thierry Fournier, golang-nuts
Add these flags to the CGO_LDFLAGS_ALLOW environment variable.

You may want to file an issue to get them added to the list of permitted flags.

Ian

thierry thierry

unread,
Oct 19, 2020, 5:44:02 AM10/19/20
to Ian Lance Taylor, golang-nuts
Thanks. It works perfectly !
Reply all
Reply to author
Forward
0 new messages