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

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 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