Hello.

I'm trying to build a shared library using `-buildmode=shared` and make a 
binary link to this shared library.

The packages are:

github.com/misha-ridge/splitlib/a (-> c)
github.com/misha-ridge/splitlib/b (-> c)
github.com/misha-ridge/splitlib/c
github.com/misha-ridge/splitlib (-> a, b, c)

I'd like to package `a` and `c` into the shared library, and put `b` and 
`splitlib` into the binary.

I've tried the following:

$ go install -buildmode=shared std
$ go install -buildmode=shared -linkshared  -gcflags='-N -l' ./a

This produced `libgithub.com-misha-ridge-splitlib-a.so` in the current 
directory

Then

$ go build -o main -linkshared  -gcflags='-N -l' .

This produced `main` in the current directory that only links to a shared 
libstd, but not to
the freshly built lib...splitlib-a.so:

$ ldd main
linux-vdso.so.1 (0x00007ffea3bfe000)
libstd.so => /usr/local/go/pkg/linux_amd64_dynlink/libstd.so 
(0x00007f7ea27f6000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7ea2631000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7ea262c000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 
(0x00007f7ea260b000)
/lib64/ld-linux-x86-64.so.2 (0x00007f7ea4f23000)
$

The shared library does not contain symbols from splitlib/a or splitlib/b:

$ go tool nm libgithub.com-misha-ridge-splitlib-a.so  | grep splitlib
  104cd0 D go.link.abihash.libgithub.com-misha-ridge-splitlib-a.so

Only the final binary does:

$ go tool nm main  | grep splitlib
    2180 T github.com/misha-ridge/splitlib/a.SetC
    2190 T github.com/misha-ridge/splitlib/b.SetC
    2170 T github.com/misha-ridge/splitlib/c.Get
    5210 D github.com/misha-ridge/splitlib/c.i
    2180 t local.github.com/misha-ridge/splitlib/a.SetC
    2190 t local.github.com/misha-ridge/splitlib/b.SetC
    2170 t local.github.com/misha-ridge/splitlib/c.Get

Am I missing some step?

The repository with reproducer is at https://github.com/misha-ridge/splitlib

-- 
Best,
Misha.

-- 
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/466454be-a0fe-432d-9f4c-498cd23609d3%40googlegroups.com.

Reply via email to