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
Related
I am working on a smallish Go application that uses Cgo. I'm working on it on a Linux VM, and Linux is the main target environment. However, I have a need to also create a Windows executable. Normally, cross-compiling Go is trivial, but Cgo adds some complications. I've noticed at least two issues, but I'll only ask about the first problem here.
My application only has a single source file that requires Cgo, and the only difference between the Windows and Linux build is the lib path.
This is what I have so far for the beginning of the Cgo header. After this are some include file references:
/*
#cgo CFLAGS: -g -Wall -I${SRCDIR}/../include/v6.21.0
#cgo linux LDFLAGS: -L${SRCDIR}/../lib/linux/v6.21.0 -lvibesimple -lcurl -lssl -lvibecrypto -lvibeictk -lvibeserver
#cgo windows LDFLAGS: -L${SRCDIR}/../lib/windows/v6.21.0 -lvibesimple -lcurl -lssl -lvibecrypto -lvibeictk -lvibeserver
When I build this on Linux, or with GOOS=linux, it works fine.
When I build this for Windows, I get this:
$ GOOS=windows go build -o target/dist/windows-amd64
package voltagems
imports voltagems/app
imports voltagems/handlers
imports voltagems/voltagefuncs: build constraints exclude all Go files in /home/<uid>/git/voltagego/voltagefuncs
I know that I can create files ending in "_linux.go" or "_windows.go", but that would be painful. That would mean duplicating the entire source file, and having to maintain both copies.
I do cross-compile in my PC, and I want to build a static link binary. In order to run it on the target board without adding any shared library.
When compile a single file, I know I can use "-static" to build a binary without any shared library.
e.g.
$ aarch64-linux-gnu-gcc -o hello hello.c -static
$ file hello
hello: ELF 64-bit LSB executable, ARM aarch64, version 1 (GNU/Linux), statically linked,
But when I use autoconf in the open source project, I can't build the binary static.
I have tried the following command, but failed:
$ ./configure --host=aarch64-linux-gnu --enable-static --disable-shared LDFLAGS="-static"
Is there any one know how to build a static binary with autoconf?
I am trying to statically compile a go application using Qt and run it on a computer without Go or Qt installed.
At the top of my main.go I have:
// #cgo LDFLAGS: -static -L/Users/$USER/Qt/5.7.0_static_osx/lib -lgb
//go:generate genqrc ui
I have static compiled my application using:
go generate && go build -a -installsuffix cgo
The go generate compiles the .qml files into the binary while as I understand it go build -a -installsuffix cgo statically compiles all the .go and .a files from Qt.
I am using go version go1.8 darwin/amd64 and I have 5.7.0_static_osx Qt in my /Users/$USER/Qt folder and in the /lib folder I have all the .a files
I am using OSX 10.11.6 (El Capitan)
Now the issue is when I move it to another mac I get the error:
/Users/$USER/Downloads/PACKAGED.app/Contents/Resources
AppSettings.plist
MainMenu.nib
appIcon.icns
PACKAGEDAPP
script
dyld: Library not loaded: /usr/local/opt/qt5/lib/QtWidgets.framework/Versions/5/QtWidgets
Referenced from: /Users/$USER/Downloads/PACKAGED.app/Contents/Resources/./encryptoclient
Reason: Incompatible library version: encryptoclient requires version 5.7.0 or later, but QtWidgets provides version 5.4.0
/Users/$USER/Downloads/PACKAGED.app/Contents/Resources/script: line 5: 9987 Trace/BPT trap: 5 ./encryptoclient
Which makes me think that Qt wasn't statically compiled, is this so? And if so, what do I need to do to compile properly?
P.S (FYI) Its in a .app because I have wrapped it in a Platypus app to make moving and running on other computer an easy 'double-click' off the USB stick
I'm making a project that requires libpcap library, I downloaded the library from official website (libpcap-1.7.2.tar.gz) and I want to compile and the project on Unix server, but I am not allowed to install the library there (school server) and I cannot run the gcc as root.
What command shall I use? Or is it even possible? I can't find any info. (.. my aim is to run the binary on another linux OS (with root permissions) without the need of installing the lib.)
I already tried:
gcc -Wall test.c -lpcap -Ilib/libpcap-1.7.2
but getting an error:
lib/libpcap-1.7.2/pcap.h:43:23: fatal error: pcap/pcap.h: No such file or directory
#include <pcap/pcap.h>
^
I'm working on Linux PC x86_64.
I've set up a cross compile toolchain for raspberry pi and I can compile basic helloworld and run it on raspberry.
I'm stuck at compiling some open-source programs as ./configure is complaining about missing packages, for example:
configure: No package 'glib-2.0' found
I'm using this. ./configure --host=arm-linux-gnueabihf to cross compile and it looks good until that error above.
Should I tell ./configure to use libs from target system or? How to do it?
Pass options to the configure script so that it finds the development headers and libraries. It uses using LDFLAGS and CFLAGS.