Compile embeded python code on/for windows anyhow

Hi!
I have a python code embeded in go (refer: Use python in GO code - #6 by gucio321)
But I have a quit important problem - I need to ship my application to windows and I am unable to build it on/for this platform.

on windows

I am geting “Python.h” - file not found error even though I added pkg-config and python configuration.

on linux

I was trying to cross-compile with the following script:

#!/bin/bash
#
ecoh "build for windows"
LD_LIBRARY_PATH="/usr/x86_64-w64-mingw32/sys-root/mingw/lib" PKG_CONFIG_PATH="/usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig/" GOOS=windows GOARCH=amd64 \
        CGO_ENABLED=1 \
        CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ \
        go build \
        -ldflags "-s -w -extldflags=-static" \
        -o main.go .

anyway, I’m getting the following linker error:

/usr/local/go/pkg/tool/linux_amd64/link: running x86_64-w64-mingw32-g++ failed: exit status 1
/usr/lib/gcc/x86_64-w64-mingw32/12.2.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lpython3.10: No such file or directory
/usr/lib/gcc/x86_64-w64-mingw32/12.2.1/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/i686-w64-mingw32/sys-root/mingw/lib/libimm32.a when searching for -limm32
/usr/lib/gcc/x86_64-w64-mingw32/12.2.1/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/i686-w64-mingw32/sys-root/mingw/lib/libimm32.a when searching for -limm32
/usr/lib/gcc/x86_64-w64-mingw32/12.2.1/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lpython3.10: No such file or directory
/usr/lib/gcc/x86_64-w64-mingw32/12.2.1/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/i686-w64-mingw32/sys-root/mingw/lib/libgdi32.a when searching for -lgdi32
/usr/lib/gcc/x86_64-w64-mingw32/12.2.1/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/i686-w64-mingw32/sys-root/mingw/lib/libgdi32.a when searching for -lgdi32
/usr/lib/gcc/x86_64-w64-mingw32/12.2.1/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/i686-w64-mingw32/sys-root/mingw/lib/libopengl32.a when searching for -lopengl32
/usr/lib/gcc/x86_64-w64-mingw32/12.2.1/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/i686-w64-mingw32/sys-root/mingw/lib/libopengl32.a when searching for -lopengl32
/usr/lib/gcc/x86_64-w64-mingw32/12.2.1/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/i686-w64-mingw32/sys-root/mingw/lib/libopengl32.a when searching for -lopengl32
/usr/lib/gcc/x86_64-w64-mingw32/12.2.1/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/i686-w64-mingw32/sys-root/mingw/lib/libopengl32.a when searching for -lopengl32
/usr/lib/gcc/x86_64-w64-mingw32/12.2.1/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/i686-w64-mingw32/sys-root/mingw/lib/libopengl32.a when searching for -lopengl32
/usr/lib/gcc/x86_64-w64-mingw32/12.2.1/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /usr/i686-w64-mingw32/sys-root/mingw/lib/libopengl32.a when searching for -lopengl32
collect2: error: ld returned 1 exit status

idk which error would be easier to fix :smile:

Did you also compile Python for Windows?

I have mingw32-python package installed, i suppose it provides windows compilation of python, however I’m not sure if this compilation is used tbh

Maybe your ldflags needs a -L flag to specify the directory to python310.dll? Also, I think it’s python310.dll for windows, but libpython3.10.so for everything else (based on the contents of my C:\Program Files\Python310 folder on my computer).

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.