FAQ
Hm. After building from head, this actually seems to work fine, so I'm not
going to file a bug about it after all.

~
Doug.
On Wednesday, May 29, 2013 5:54:45 AM UTC+8, minux wrote:

please file an issue. golang.org/issue/new
the Go 1.1 support for external linking has broken this case (putting
static libraries directly
in #cgo LDFLAGS.)

but the bug is somewhat complicated to fix.

1. when using external linking, we don't need to link the static library
into _all.o as external
linker should take care of the linking issues (this issue causes your
problem).
2. but when using internal linking, we must link the static library into
_all.o as our linker
(cmd/6l) doesn't take LDFLAGS into account.

the complication is: at the time we link (-Wl,-r) _all.o, we don't yet
know whether we're using
internal linking or external linking.

On Tue, May 28, 2013 at 1:35 PM, Dougx <douglas...@gmail.com <javascript:>
wrote:
I've been trying get some basic python-go stuff working, but I'm having
trouble statically linking python to go.

When I try to compile:

package bridge

import "fmt"

// #cgo CFLAGS:
-I/Users/d/projects/go/go-static-linking/deps/python/Include
// #cgo LDFLAGS:
/Users/d/projects/go/go-static-linking/build/python/lib/libpython2.7.a
// #include <Python.h>
import "C"

func Run() {
fmt.Printf("Invoking c library...\n")
C.Py_Initialize()
fmt.Printf("Done\n")
}

I get:

# _/Users/d/projects/go/go-static-linking/demo
/var/folders/t_/210n3r_53z1b7hht1ypk92zn98842m/T/go-build502385430/bridge.a(_all.o)
sym#14579: duplicate definition of fastsearch
/var/folders/t_/210n3r_53z1b7hht1ypk92zn98842m/T/go-build502385430/bridge.a(_all.o)
sym#14604: duplicate definition of stringlib_parse_args_finds
/var/folders/t_/210n3r_53z1b7hht1ypk92zn98842m/T/go-build502385430/bridge.a(_all.o)
sym#14849: duplicate definition of half_richcompare
/var/folders/t_/210n3r_53z1b7hht1ypk92zn98842m/T/go-build502385430/bridge.a(_all.o)
sym#14874: duplicate definition of proxy_dealloc
/var/folders/t_/210n3r_53z1b7hht1ypk92zn98842m/T/go-build502385430/bridge.a(_all.o)
sym#14875: duplicate definition of proxy_compare
/var/folders/t_/210n3r_53z1b7hht1ypk92zn98842m/T/go-build502385430/bridge.a(_all.o)
sym#14876: duplicate definition of proxy_repr
/var/folders/t_/210n3r_53z1b7hht1ypk92zn98842m/T/go-build502385430/bridge.a(_all.o)
sym#14916: duplicate definition of proxy_contains
/var/folders/t_/210n3r_53z1b7hht1ypk92zn98842m/T/go-build502385430/bridge.a(_all.o)
sym#14917: duplicate definition of proxy_getitem
/var/folders/t_/210n3r_53z1b7hht1ypk92zn98842m/T/go-build502385430/bridge.a(_all.o)
sym#14919: duplicate definition of proxy_str
/var/folders/t_/210n3r_53z1b7hht1ypk92zn98842m/T/go-build502385430/bridge.a(_all.o)
sym#14926: duplicate definition of fastsearch
/var/folders/t_/210n3r_53z1b7hht1ypk92zn98842m/T/go-build502385430/bridge.a(_all.o)
sym#14930: duplicate definition of formatteriter_dealloc
/var/folders/t_/210n3r_53z1b7hht1ypk92zn98842m/T/go-build502385430/bridge.a(_all.o)
sym#14931: duplicate definition of fieldnameiter_dealloc
/var/folders/t_/210n3r_53z1b7hht1ypk92zn98842m/T/go-build502385430/bridge.a(_all.o)
sym#14982: duplicate definition of do_string_format
/var/folders/t_/210n3r_53z1b7hht1ypk92zn98842m/T/go-build502385430/bridge.a(_all.o)
sym#14984: duplicate definition of formatter_field_name_split
/var/folders/t_/210n3r_53z1b7hht1ypk92zn98842m/T/go-build502385430/bridge.a(_all.o)
sym#14985: duplicate definition of formatter_parser
/var/folders/t_/210n3r_53z1b7hht1ypk92zn98842m/T/go-build502385430/bridge.a(_all.o)
sym#14990: duplicate definition of formatteriter_next
/var/folders/t_/210n3r_53z1b7hht1ypk92zn98842m/T/go-build502385430/bridge.a(_all.o)
sym#14991: duplicate definition of MarkupIterator_next
/var/folders/t_/210n3r_53z1b7hht1ypk92zn98842m/T/go-build502385430/bridge.a(_all.o)
sym#14992: duplicate definition of FieldNameIterator_next
/var/folders/t_/210n3r_53z1b7hht1ypk92zn98842m/T/go-build502385430/bridge.a(_all.o)
sym#14993: duplicate definition of field_name_split
/var/folders/t_/210n3r_53z1b7hht1ypk92zn98842m/T/go-build502385430/bridge.a(_all.o)
sym#14996: duplicate definition of pad
/var/folders/t_/210n3r_53z1b7hht1ypk92zn98842m/T/go-build502385430/bridge.a(_all.o)
sym#14998: duplicate definition of SubString_new_object
too many errors

Any suggestions what I might be doing wrong?

By comparison, this code:

#include <stdio.h>
#include <Python.h>

int x(int y) {
printf("Hello World\n");

Py_SetProgramName("");
Py_Initialize();
PyRun_SimpleString("print(\"Hello Python\")");
Py_Finalize();

return y;
}

int main() {
x(0);
}

Works fine:

d:~/projects/go/go-static-linking/build$ cc junk.c
-I../deps/python/Include python/lib/libpython2.7.a
d:~/projects/go/go-static-linking/build$ ./a.out
Hello World
Hello Python

(so python is building fine)

Minimal test case (well, as minimal as anything that builds and embeds
python can be):
https://github.com/shadowmint/go-static-linking/tree/with-python

Cheers,
Doug.

--
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...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 3 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMay 28, '13 at 5:35a
activeMay 29, '13 at 7:08a
posts3
users2
websitegolang.org

2 users in discussion

Dougx: 2 posts Minux: 1 post

People

Translate

site design / logo © 2021 Grokbase