.../usr/src/go/pkg/tool/linux_amd64/8g -o $WORK/mingwtest.a -trimpath $WORK -p mingwtest -complete -D _/opt/go/src/mingwtest -I $WORK -I /opt/go/pkg/windows_386 -pack ./main.gocd ./usr/src/go/pkg/tool/linux_amd64/8l -o $WORK/mingwtest/_obj/exe/a.out.exe -L $WORK -L /opt/go/pkg/windows_386 -extld=i686-w64-mingw32-gcc $WORK/mingwtest.a# mingwtestgithub.com/op/go-libspotify/spotify(.text): sp_error_message: not definedgithub.com/op/go-libspotify/spotify(.text): sp_album_add_ref: not defined...
I'm having a hard time getting a compile working. The application compiles fine, but fails on (what I think is) linking. Snipped output of go get -x . is:.../usr/src/go/pkg/tool/linux_amd64/8g -o $WORK/mingwtest.a -trimpath $WORK -p mingwtest -complete -D _/opt/go/src/mingwtest -I $WORK -I /opt/go/pkg/windows_386 -pack ./main.gocd ./usr/src/go/pkg/tool/linux_amd64/8l -o $WORK/mingwtest/_obj/exe/a.out.exe -L $WORK -L /opt/go/pkg/windows_386 -extld=i686-w64-mingw32-gcc $WORK/mingwtest.a# mingwtestgithub.com/op/go-libspotify/spotify(.text): sp_error_message: not definedgithub.com/op/go-libspotify/spotify(.text): sp_album_add_ref: not defined...This builds and runs fine when done natively for linux.
CGO_LDFLAGS="-g" "-O2" "-L/libspotify/lib" "-lspotify" /usr/src/go/pkg/tool/linux_amd64/cgo -objdir $WORK/github.com/op/go-libspotify/spotify/_obj/ -- -I/libspotify/include -I $WORK/github.com/op/go-libspotify/spotify/_obj/ error.go libspotify.go/usr/src/go/pkg/tool/linux_amd64/8c -F -V -w -trimpath $WORK -I $WORK/github.com/op/go-libspotify/spotify/_obj/ -I /usr/src/go/pkg/windows_386 -o $WORK/github.com/op/go-libspotify/spotify/_obj/_cgo_defun.8 -D GOOS_windows -D GOARCH_386 $WORK/github.com/op/go-libspotify/spotify/_obj/_cgo_defun.ci686-w64-mingw32-gcc -I . -m32 -mthreads -fmessage-length=0 -print-libgcc-file-namei686-w64-mingw32-gcc -I . -m32 -mthreads -fmessage-length=0 -I/libspotify/include -I $WORK/github.com/op/go-libspotify/spotify/_obj/ -g -O2 -o $WORK/github.com/op/go-libspotify/spotify/_obj/_cgo_main.o -c $WORK/github.com/op/go-libspotify/spotify/_obj/_cgo_main.ci686-w64-mingw32-gcc -I . -m32 -mthreads -fmessage-length=0 -I/libspotify/include -I $WORK/github.com/op/go-libspotify/spotify/_obj/ -g -O2 -o $WORK/github.com/op/go-libspotify/spotify/_obj/_cgo_export.o -c $WORK/github.com/op/go-libspotify/spotify/_obj/_cgo_export.ci686-w64-mingw32-gcc -I . -m32 -mthreads -fmessage-length=0 -I/libspotify/include -I $WORK/github.com/op/go-libspotify/spotify/_obj/ -g -O2 -o $WORK/github.com/op/go-libspotify/spotify/_obj/error.cgo2.o -c $WORK/github.com/op/go-libspotify/spotify/_obj/error.cgo2.ci686-w64-mingw32-gcc -I . -m32 -mthreads -fmessage-length=0 -I/libspotify/include -I $WORK/github.com/op/go-libspotify/spotify/_obj/ -g -O2 -o $WORK/github.com/op/go-libspotify/spotify/_obj/libspotify.cgo2.o -c $WORK/github.com/op/go-libspotify/spotify/_obj/libspotify.cgo2.ci686-w64-mingw32-gcc -I . -m32 -mthreads -fmessage-length=0 -I/libspotify/include -I $WORK/github.com/op/go-libspotify/spotify/_obj/ -g -O2 -o $WORK/github.com/op/go-libspotify/spotify/_obj/libspotify.o -c ./libspotify.ci686-w64-mingw32-gcc -I . -m32 -mthreads -fmessage-length=0 -o $WORK/github.com/op/go-libspotify/spotify/_obj/_cgo_.o $WORK/github.com/op/go-libspotify/spotify/_obj/_cgo_main.o $WORK/github.com/op/go-libspotify/spotify/_obj/_cgo_export.o $WORK/github.com/op/go-libspotify/spotify/_obj/error.cgo2.o $WORK/github.com/op/go-libspotify/spotify/_obj/libspotify.cgo2.o $WORK/github.com/op/go-libspotify/spotify/_obj/libspotify.o -g -O2 -L/libspotify/lib -lspotify/tmp/go-build055608681/github.com/op/go-libspotify/spotify/_obj/error.cgo2.o: In function `cgo_4738617973c1_Cfunc_sp_error_message':../github.com/op/go-libspotify/spotify/error.go:52: undefined reference to `sp_error_message@4'/tmp/go-build055608681/github.com/op/go-libspotify/spotify/_obj/libspotify.cgo2.o: In function `cgo_4738617973c1_Cfunc_sp_album_add_ref':../github.com/op/go-libspotify/spotify/libspotify.go:126: undefined reference to `sp_album_add_ref@4'/tmp/go-build055608681/github.com/op/go-libspotify/spotify/_obj/libspotify.cgo2.o: In function `cgo_4738617973c1_Cfunc_sp_album_artist':../github.com/op/go-libspotify/spotify/libspotify.go:139: undefined reference to `sp_album_artist@4'
#include <stdio.h>#include <libspotify/api.h>int main() {const char* error_message = sp_error_message(SP_ERROR_BAD_API_VERSION);printf("Success: %s\n", strcmp(error_message, "Invalid library version") == 0? "true" : "false");return 0;}
$ gcc -o test test.c -lspotify && ./testSuccess: true
$ i686-w64-mingw32-gcc -o test.exe test.c -lspotify/tmp/cceANomQ.o:test.c:(.text+0x1e): undefined reference to `sp_error_message@4'collect2: error: ld returned 1 exit status
i686-w64-mingw32-gcc -o test.exe test.c -llibspotify && wine test.exeSuccess: true
i686-w64-mingw32-gcc -I . -m32 -mthreads -fmessage-length=0 -o $WORK/mingwtest/_obj/_all.o $WORK/mingwtest/_obj/_cgo_export.o $WORK/mingwtest/_obj/main.cgo2.o -g -O2 -L/libspotify/lib -Wl,-r -nostdlib -Wl,--start-group -lmingwex -lmingw32 -Wl,--end-group /usr/lib/gcc/i686-w64-mingw32/4.9-win32/libgcc.a
panic: runtime error: invalid memory address or nil pointer dereference[signal 0xc0000005 code=0x0 addr=0x0 pc=0x40103b]goroutine 1 [running]:main._Cfunc_sp_error_message(0x1, 0x0)mingwtest/_obj/_cgo_gotypes.go:29 +0x3bmain.main()/opt/go/src/mingwtest/main.go:12 +0x29goroutine 17 [syscall, locked to thread]:runtime.goexit()/usr/src/go/src/runtime/asm_386.s:2287 +0x1
main(.text): sp_error_message: not definedmain(.text): undefined: sp_error_message
PS C:\Users\josh\mingwtest> go build -x -work .
WORK=C:\Users\josh\AppData\Local\Temp\go-build935999867
mkdir -p $WORK\_\C_\Users\josh\mingwtest\_obj\
cd C:\Users\josh\mingwtest
pkg-config --cflags libspotify
pkg-config --libs libspotify
CGO_LDFLAGS="-g" "-O2" "-L/libspotify/lib" "-lspotify" "C:\\Go\\pkg\\tool\\windows_386\\cgo.exe" -objdir "C:\\Users\\jos
h\\AppData\\Local\\Temp\\go-build935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\" -- -I/libspotify/include -I "C:\\User
s\\josh\\AppData\\Local\\Temp\\go-build935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\" main.go
"C:\\Go\\pkg\\tool\\windows_386\\8c.exe" -F -V -w -trimpath "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867" -
I "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\" -I "C:\\Go\\pkg\\win
dows_386" -o "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\_cgo_defun.
8" -D GOOS_windows -D GOARCH_386 "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867\\_\\C_\\Users\\josh\\mingwtes
t\\_obj\\_cgo_defun.c"
gcc -I "C:\\Users\\josh\\mingwtest" -m32 -mthreads -fmessage-length=0 -print-libgcc-file-name
gcc -I "C:\\Users\\josh\\mingwtest" -m32 -mthreads -fmessage-length=0 -I/libspotify/include -I "C:\\Users\\josh\\AppData
\\Local\\Temp\\go-build935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\" -g -O2 -o "C:\\Users\\josh\\AppData\\Local\\Tem
p\\go-build935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\_cgo_main.o" -c "C:\\Users\\josh\\AppData\\Local\\Temp\\go-bu
ild935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\_cgo_main.c"
gcc -I "C:\\Users\\josh\\mingwtest" -m32 -mthreads -fmessage-length=0 -I/libspotify/include -I "C:\\Users\\josh\\AppData
\\Local\\Temp\\go-build935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\" -g -O2 -o "C:\\Users\\josh\\AppData\\Local\\Tem
p\\go-build935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\_cgo_export.o" -c "C:\\Users\\josh\\AppData\\Local\\Temp\\go-
build935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\_cgo_export.c"
gcc -I "C:\\Users\\josh\\mingwtest" -m32 -mthreads -fmessage-length=0 -I/libspotify/include -I "C:\\Users\\josh\\AppData
\\Local\\Temp\\go-build935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\" -g -O2 -o "C:\\Users\\josh\\AppData\\Local\\Tem
p\\go-build935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\main.cgo2.o" -c "C:\\Users\\josh\\AppData\\Local\\Temp\\go-bu
ild935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\main.cgo2.c"
gcc -I "C:\\Users\\josh\\mingwtest" -m32 -mthreads -fmessage-length=0 -o "C:\\Users\\josh\\AppData\\Local\\Temp\\go-buil
d935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\_cgo_.o" "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867\\_\\
C_\\Users\\josh\\mingwtest\\_obj\\_cgo_main.o" "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867\\_\\C_\\Users\\
josh\\mingwtest\\_obj\\_cgo_export.o" "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867\\_\\C_\\Users\\josh\\min
gwtest\\_obj\\main.cgo2.o" -g -O2 -L/libspotify/lib -lspotify
"C:\\Go\\pkg\\tool\\windows_386\\cgo.exe" -objdir "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867\\_\\C_\\User
s\\josh\\mingwtest\\_obj\\" -dynimport "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867\\_\\C_\\Users\\josh\\mi
ngwtest\\_obj\\_cgo_.o" -dynout "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867\\_\\C_\\Users\\josh\\mingwtest
\\_obj\\_cgo_import.c"
"C:\\Go\\pkg\\tool\\windows_386\\8c.exe" -F -V -w -trimpath "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867" -
I "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\" -I "C:\\Go\\pkg\\win
dows_386" -o "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\_cgo_import
.8" -D GOOS_windows -D GOARCH_386 "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867\\_\\C_\\Users\\josh\\mingwte
st\\_obj\\_cgo_import.c"
gcc -I "C:\\Users\\josh\\mingwtest" -m32 -mthreads -fmessage-length=0 -o "C:\\Users\\josh\\AppData\\Local\\Temp\\go-buil
d935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\_all.o" "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867\\_\\C
_\\Users\\josh\\mingwtest\\_obj\\_cgo_export.o" "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867\\_\\C_\\Users\
\josh\\mingwtest\\_obj\\main.cgo2.o" -g -O2 -L/libspotify/lib -Wl,-r -nostdlib -Wl,--start-group -lmingwex -lmingw32 -Wl
,--end-group "C:/Program Files (x86)/mingw-w64/i686-4.9.2-posix-dwarf-rt_v3-rev1/mingw32/bin/../lib/gcc/i686-w64-mingw32
/4.9.2/libgcc.a"
"C:\\Go\\pkg\\tool\\windows_386\\8g.exe" -o "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867\\_\\C_\\Users\\jos
h\\mingwtest.a" -trimpath "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867" -p _/C_/Users/josh/mingwtest -D _/C
_/Users/josh/mingwtest -I "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867" -pack "C:\\Users\\josh\\AppData\\Lo
cal\\Temp\\go-build935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\_cgo_gotypes.go" "C:\\Users\\josh\\AppData\\Local\\Te
mp\\go-build935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\main.cgo1.go"
pack r "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867\\_\\C_\\Users\\josh\\mingwtest.a" "C:\\Users\\josh\\App
Data\\Local\\Temp\\go-build935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\_cgo_import.8" "C:\\Users\\josh\\AppData\\Loc
al\\Temp\\go-build935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\_cgo_defun.8" "C:\\Users\\josh\\AppData\\Local\\Temp\\
go-build935999867\\_\\C_\\Users\\josh\\mingwtest\\_obj\\_all.o" # internal
cd .
"C:\\Go\\pkg\\tool\\windows_386\\8l.exe" -o mingwtest.exe -L "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867"
-extld=gcc "C:\\Users\\josh\\AppData\\Local\\Temp\\go-build935999867\\_\\C_\\Users\\josh\\mingwtest.a"
# _/C_/Users/josh/mingwtest
main(.text): sp_error_message: not defined
main(.text): undefined: sp_error_message
$ wine dumpbin/dumpbin.exe /exports /symbols dll/libspotify.dll | fgrep error_message
47 2E 000E3110 _sp_error_message@4
$ nm dll/libspotify.lib | grep -b6 error_message
10333-
10334-libspotify.dll:
10350-00000000 I .idata$4
10370-00000000 I .idata$5
10390-00000000 I .idata$6
10410- U __IMPORT_DESCRIPTOR_libspotify
10452:00000000 I __imp__sp_error_message@4
10489:00000000 T _sp_error_message@4
10520-00000000 T .text
10537-
10538-libspotify.dll:
10554-00000000 I .idata$4
10574-00000000 I .idata$5
10594-00000000 I .idata
I've tried what you've suggested Dave, to no avail.I'm seeing a compile flag that's actually missing libspotify, which I'm wondering if it's a problem with the go build toolchain.What's interesting to me is in the build, this command is run:i686-w64-mingw32-gcc -I . -m32 -mthreads -fmessage-length=0 -o $WORK/mingwtest/_obj/_all.o $WORK/mingwtest/_obj/_cgo_export.o $WORK/mingwtest/_obj/main.cgo2.o -g -O2 -L/libspotify/lib -Wl,-r -nostdlib -Wl,--start-group -lmingwex -lmingw32 -Wl,--end-group /usr/lib/gcc/i686-w64-mingw32/4.9-win32/libgcc.aWhat you'll notice is that that the libspotify lib path is included (-L/libspotify/lib), but no -lspotify. I manually compiled using the output of "go build -n" (and had to compile a packer, based on go's internal packer in go/cmd/go/build.go packInternal). I added "-lspotify" to the above command, and the code compiles fine (this seems like bug #1)
This is windows, but yep the dll exports it:
$ wine dumpbin/dumpbin.exe /exports /symbols dll/libspotify.dll | fgrep error_message
47 2E 000E3110 _sp_error_message@4The libspotify.lib references it correctly as well:
CGO_LDFLAGS="-g" "-O2" "/libspotify/lib/libspotify.dll" /usr/src/go/pkg/tool/linux_amd64/cgo -objdir $WORK/mingwtest/_obj/ -- -I $WORK/mingwtest/_obj/ -I /libspotify/include main.go
/usr/src/go/pkg/tool/linux_amd64/8c -F -V -w -trimpath $WORK -I $WORK/mingwtest/_obj/ -I /usr/src/go/pkg/windows_386 -o $WORK/mingwtest/_obj/_cgo_defun.8 -D GOOS_windows -D GOARCH_386 $WORK/mingwtest/_obj/_cgo_defun.c
i686-w64-mingw32-gcc -I . -m32 -mthreads -fmessage-length=0 -print-libgcc-file-name
i686-w64-mingw32-gcc -I . -m32 -mthreads -fmessage-length=0 -I $WORK/mingwtest/_obj/ -g -O2 -I /libspotify/include -o $WORK/mingwtest/_obj/_cgo_main.o -c $WORK/mingwtest/_obj/_cgo_main.c
i686-w64-mingw32-gcc -I . -m32 -mthreads -fmessage-length=0 -I $WORK/mingwtest/_obj/ -g -O2 -I /libspotify/include -o $WORK/mingwtest/_obj/_cgo_export.o -c $WORK/mingwtest/_obj/_cgo_export.c
i686-w64-mingw32-gcc -I . -m32 -mthreads -fmessage-length=0 -I $WORK/mingwtest/_obj/ -g -O2 -I /libspotify/include -o $WORK/mingwtest/_obj/main.cgo2.o -c $WORK/mingwtest/_obj/main.cgo2.c
i686-w64-mingw32-gcc -I . -m32 -mthreads -fmessage-length=0 -o $WORK/mingwtest/_obj/_cgo_.o $WORK/mingwtest/_obj/_cgo_main.o $WORK/mingwtest/_obj/_cgo_export.o $WORK/mingwtest/_obj/main.cgo2.o -g -O2 /libspotify/lib/libspotify.dll
# mingwtest
/tmp/go-build953975252/mingwtest/_obj/main.cgo2.o: In function `cgo_de2ec629320b_Cfunc_sp_error_message':
./main.go:39: undefined reference to `sp_error_message@4'
$ i686-w64-mingw32-gcc -I/libspotify/include -m32 -o test.exe test.c /libspotify/lib/libspotify.dll
/tmp/cclqGZmV.o:test.c:(.text+0x1e): undefined reference to `sp_error_message@4'
collect2: error: ld returned 1 exit status
$ i686-w64-mingw32-gcc -I/libspotify/include -m32 -o test.exe test.c /libspotify/lib/libspotify.lib
$ wine test.exe
Success: true
...
pack r $WORK/mingwtest.a $WORK/mingwtest/_obj/_cgo_import.8 $WORK/mingwtest/_obj/_cgo_defun.8 $WORK/mingwtest/_obj/_all.o # internal
cd .
/usr/src/go/pkg/tool/linux_amd64/8l -o $WORK/mingwtest/_obj/exe/a.out.exe -L $WORK -extld=i686-w64-mingw32-gcc $WORK/mingwtest.a
# mingwtest
/tmp/go-build284869168/mingwtest.a(_all.o): malformed pe file: unexpected flags 0xe0500020 for PE section .text
main._cgo_231fbd32956b_Cfunc_sp_error_message: _cgo_231fbd32956b_Cfunc_sp_error_message: not defined
main._cgo_231fbd32956b_Cfunc_sp_error_message: undefined: _cgo_231fbd32956b_Cfunc_sp_error_message
$ nm $WORK/mingwtest.a
nm: __.PKGDEF: File format not recognized
nm: _go_.8: File format not recognized
nm: _cgo_import.8: File format not recognized
nm: _cgo_defun.8: File format not recognized
_all.o:
00000000 b .bss
00000000 b .bss
00000000 d .data
00000000 d .data
00000000 N .debug_abbrev
00000019 N .debug_abbrev
00000000 N .debug_aranges
00000018 N .debug_aranges
00000000 N .debug_frame
00000000 N .debug_info
0000015f N .debug_info
00000000 N .debug_line
0000001d N .debug_line
00000000 N .debug_loc
00000000 N .debug_str
00000000 i .idata$2
U .idata$4
00000004 i .idata$4
00000004 i .idata$5
00000004 i .idata$5
00000010 i .idata$6
00000000 i .idata$6
00000014 r .rdata$zzz
00000000 r .rdata$zzz
00000000 t .text
00000000 t .text
00000040 t .text
009c766f a @comp.id
009c766f a @comp.id
009c766f a @comp.id
00000000 I __IMPORT_DESCRIPTOR_libspotify
00000000 I __NULL_IMPORT_DESCRIPTOR
00000000 T __cgo_231fbd32956b_Cfunc_sp_error_message
U __cgo_topofstack
00000004 I __imp__sp_error_message@4
00000040 T _sp_error_message@4
00000000 I libspotify_NULL_THUNK_DATA
...
Hello,I'm having a hard time getting a compile working. The application compiles fine, but fails on (what I think is) linking. Snipped output of go get -x . is:...