sbinet / go-python

naive go bindings to the CPython2 C-API
Other
1.53k stars 138 forks source link

many undefined and error when compile #54

Open Ryan007 opened 7 years ago

Ryan007 commented 7 years ago
# github.com/sbinet/go-python
/usr/local/lib/libpython2.7.a(posixmodule.o): In function `posix_tmpnam':
/root/Python-2.7.13/./Modules/posixmodule.c:7614: warning: the use of `tmpnam_r' is dangerous, better use `mkstemp'
/usr/local/lib/libpython2.7.a(posixmodule.o): In function `posix_tempnam':
/root/Python-2.7.13/./Modules/posixmodule.c:7561: warning: the use of `tempnam' is dangerous, better use `mkstemp'
/usr/local/lib/libpython2.7.a(complexobject.o): In function `_Py_c_abs':
/root/Python-2.7.13/Objects/complexobject.c:214: undefined reference to `hypot'
/usr/local/lib/libpython2.7.a(complexobject.o): In function `_Py_c_pow':
/root/Python-2.7.13/Objects/complexobject.c:143: undefined reference to `hypot'
/root/Python-2.7.13/Objects/complexobject.c:144: undefined reference to `pow'
/root/Python-2.7.13/Objects/complexobject.c:145: undefined reference to `atan2'
/root/Python-2.7.13/Objects/complexobject.c:149: undefined reference to `sincos'
/root/Python-2.7.13/Objects/complexobject.c:148: undefined reference to `exp'
/root/Python-2.7.13/Objects/complexobject.c:149: undefined reference to `log'
/usr/local/lib/libpython2.7.a(complexobject.o): In function `complex_remainder':
/root/Python-2.7.13/Objects/complexobject.c:616: undefined reference to `floor'
/usr/local/lib/libpython2.7.a(complexobject.o): In function `complex_divmod':
/root/Python-2.7.13/Objects/complexobject.c:642: undefined reference to `floor'
/usr/local/lib/libpython2.7.a(floatobject.o): In function `float_is_integer':
/root/Python-2.7.13/Objects/floatobject.c:996: undefined reference to `floor'
/usr/local/lib/libpython2.7.a(floatobject.o): In function `float_as_integer_ratio':
/root/Python-2.7.13/Objects/floatobject.c:1748: undefined reference to `floor'
/usr/local/lib/libpython2.7.a(floatobject.o): In function `float_divmod':
/root/Python-2.7.13/Objects/floatobject.c:786: undefined reference to `floor'
/root/Python-2.7.13/Objects/floatobject.c:760: undefined reference to `fmod'
/usr/local/lib/libpython2.7.a(floatobject.o): In function `float_rem':
/root/Python-2.7.13/Objects/floatobject.c:728: undefined reference to `fmod'
/usr/local/lib/libpython2.7.a(floatobject.o): In function `_Py_double_round':
/root/Python-2.7.13/Objects/floatobject.c:1103: undefined reference to `round'
/root/Python-2.7.13/Objects/floatobject.c:1142: undefined reference to `floor'
/root/Python-2.7.13/Objects/floatobject.c:1156: undefined reference to `fmod'
/usr/local/lib/libpython2.7.a(floatobject.o): In function `float_pow':
/root/Python-2.7.13/Objects/floatobject.c:888: undefined reference to `floor'
/root/Python-2.7.13/Objects/floatobject.c:898: undefined reference to `fmod'
/root/Python-2.7.13/Objects/floatobject.c:863: undefined reference to `fmod'
/root/Python-2.7.13/Objects/floatobject.c:873: undefined reference to `fmod'
/root/Python-2.7.13/Objects/floatobject.c:922: undefined reference to `pow'
/usr/local/lib/libpython2.7.a(longobject.o): In function `PyLong_FromString':
/root/Python-2.7.13/Objects/longobject.c:1869: undefined reference to `log'
/usr/local/lib/libpython2.7.a(dynload_shlib.o): In function `_PyImport_GetDynLoadFunc':
/root/Python-2.7.13/Python/dynload_shlib.c:94: undefined reference to `dlsym'
/root/Python-2.7.13/Python/dynload_shlib.c:130: undefined reference to `dlopen'
/root/Python-2.7.13/Python/dynload_shlib.c:141: undefined reference to `dlsym'
/root/Python-2.7.13/Python/dynload_shlib.c:133: undefined reference to `dlerror'
/usr/local/lib/libpython2.7.a(signalmodule.o): In function `timeval_from_double':
/root/Python-2.7.13/./Modules/signalmodule.c:112: undefined reference to `floor'
/root/Python-2.7.13/./Modules/signalmodule.c:112: undefined reference to `floor'
/root/Python-2.7.13/./Modules/signalmodule.c:113: undefined reference to `fmod'
/root/Python-2.7.13/./Modules/signalmodule.c:113: undefined reference to `fmod'
/usr/local/lib/libpython2.7.a(posixmodule.o): In function `posix_forkpty':
posixmodule.c:(.text+0x273f): undefined reference to `forkpty'
/usr/local/lib/libpython2.7.a(posixmodule.o): In function `posix_openpty':
posixmodule.c:(.text+0x42f6): undefined reference to `openpty'
collect2: ld returned 1 exit status

when i run make install, it failed is that my python version wrong, please help me?

base info: centos6.2 x64 python-2.7.13 go version go1.7.4 linux/amd64

sbinet commented 7 years ago

how did you install python?

AFAIK, centos-6 had python-2.6.

here is what I did in a docker container:

#> docker run -it --rm centos:6 bash
$> yum update -y
$> yum install -y centos-release-SCL
$> yum install -y python27 python27-python-devel
$> yum install -y gcc git
$> export PKG_CONFIG_PATH=/opt/rh/python27/root/usr/lib64/pkgconfig:$PKG_CONFIG_PATH

$> cd /
$> curl -O -L https://storage.googleapis.com/golang/go1.7.4.linux-amd64.tar.gz
$> mkdir /goroot
$> cd /goroot
$> tar -zxf ../go1.7.4.linux-amd64.tar.gz
$> export GOROOT=`pwd`/go
$> export PATH=$GOROOT/bin:$PATH

$> cd /
$> mkdir /gopath
$> cd /gopath
$> export GOPATH=`pwd`
$> go get -d github.com/sbinet/go-python
$> cd $GOPATH/src/github.com/sbinet/go-python
$> make install
go get  -compiler="gc" .

$> echo $?
0
Ryan007 commented 7 years ago

FIRST OF ALL THANK YOU

install by source code and complied, it works fine.

sbinet commented 7 years ago

ok. so, what is the output of:

$> pkg-config --cflags --libs python-2.7
-I/usr/include/python2.7 -lpython2.7

?

sbinet commented 7 years ago

(the linker error would seem to indicate that you are missing -lm and -ldl)

leefreeopen commented 4 years ago

$> export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/x86_64-linux-gnu/pkgconfig

PKG_CONFIG_PATH should set to cgo. pkgconfig will give proper link options to build math lib.

I spent 2 days figuring out why ubuntu failed to make go-python.

in VSCode you can build and run by editing launch.json

"version": "0.2.0",
"configurations": [
    {
        "name": "Launch",
        "type": "go",
        "request": "launch",
        "mode": "auto",
        "program": "${fileDirname}",
        "env": {
            "PKG_CONFIG_PATH":"$PKG_CONFIG_PATH:/usr/lib/x86_64-linux-gnu/pkgconfig"
        },
        "args": []
    }
]

}

$> whereis pkgconfig pkgconfig: /usr/lib/x86_64-linux-gnu/pkgconfig /usr/lib/pkgconfig /usr/local/lib/pkgconfig /usr/share/pkgconfig

and find out python3.pc in located pkgconfig folders usr/lib/x86_64-linux-gnu/pkgconfig$> ls expat.pc geoclue-2.0.pc libssl.pc ncursesw.pc python-3.7m.pc sqlite3.pc uuid.pc xorg-wacom.pc fontconfig.pc grilo-plugins-0.3.pc libxcrypt.pc openssl.pc python-3.7.pc tcl8.6.pc x11.pc xrender.pc form.pc ice.pc menu.pc panel.pc python-3.8-embed.pc tcl.pc xau.pc xscrnsaver.pc formw.pc libcrypto.pc menuw.pc panelw.pc python-3.8.pc tic.pc xcb.pc xt.pc freetype2.pc libcrypt.pc ncurses++.pc pthread-stubs.pc python3-embed.pc tinfo.pc xdmcp.pc zlib.pc gcalc-2.pc libpng16.pc ncurses.pc python-2.7.pc python3.pc

leefreeopen commented 4 years ago

in cgoflags_unix.go file

// +build !windows

package python

// #cgo pkg-config: python-2.7 // #include "go-python.h" import "C"

cgo pkg-config: python-2.7 --> pkg-config should know to find python-2.7.pc file path

sudo apt-get update -y sudo apt-get install -y pkg-config

if don't install pkg-config , install pkg-config.