3

I'm trying to cross compile (from Arch Linux to Windows) a go binary with the openal library statically linked.

I use MinGW to cross compile to Windows and to MinGW package I have install and intend to use to link the static libary is mingw-w64-openal.

My build command looks like this: CC='i686-w64-mingw32-gcc -fno-stack-protector -D_FORTIFY_SOURCE=0 -lssp' GOOS=windows CGO_ENABLED=1 GOARCH=386 go build --ldflags '--extldflags "-static"' -v -o bin/game.exe -tags='deploy' game.go

The .go files (linked below) that is using the library has the following cgo code to lookup the static library for MinGW to use: #cgo windows LDFLAGS: /usr/i686-w64-mingw32/lib/libOpenAL32.dll.a

I get no errors during compilation but when I try run the binary file on windows I get the typical The program can't start because OpenAL32.dll is missing error. I want a completely portable executable so redistributing the .dll with the executable won't do.

The go openal package that I've modified to compile to windows:

https://github.com/golang/mobile/blob/master/exp/audio/al/al_notandroid.go https://github.com/golang/mobile/blob/master/exp/audio/al/alc_notandroid.go

FanManPro
  • 1,076
  • 1
  • 13
  • 31
  • What does `ldd yourbinary.exe` say? – Ainar-G Aug 14 '17 at 12:22
  • @Ainar-G Ok so I've kept three executables when I did testing earlier. First is static with audio, second is dynamic with audio, third is no audio. When I run ldd on all three of them, it returns `not a dynamic executable` :/ – FanManPro Aug 14 '17 at 12:29
  • When I run it on my linux binary it returns quite a few including `libopenal.so.1` – FanManPro Aug 14 '17 at 12:32
  • Are you sure you're not mixing them up? If ldd says that the binary is static, but it fails to load, it sounds very strange. – Ainar-G Aug 14 '17 at 13:57
  • 1
    Probably related: https://stackoverflow.com/questions/30150217/sfml-not-linking-statically-to-openal32-links-statically-to-all-other-dependenc It looks like you just shouldn't statically link it. – HolyBlackCat Aug 22 '17 at 17:23
  • @HolyBlackCat 100% correct. I also spotted that one and decided to play it safe by building a dll and sending it with the executable. I'm leaving this question open to help anyone else trying the same thing. Thanks. – FanManPro Aug 23 '17 at 13:26

0 Answers0