I compile the following Go program on a linux/amd64 box:
package main
import (
"fmt"
"os/user"
)
func main() {
fmt.Println(user.Current())
}
This works fine. But when I cross compile it from a Mac box, I get the following error when I run that program on my linux box:
user: Current not implemented on linux/amd64
How can I cross compile and use the Current function in package os/user?
Edit 1:
I should add that these are the instructions I've used to setup cross compiling on my Mac box: https://code.google.com/p/go-wiki/wiki/WindowsCrossCompiling
Edit 2: cross compiling for windows/386 works fine.
This is due to Issue 6376: user.Current panic in darwin-amd64 when crosscompiled from linux-amd64:
os/user relies on cgo, and cgo is disabled for cross compiling,
thus this is expected.
if you use os/user, you must compile natively on OS X.
even if we enable cross compilation cgo support, I doubt everybody have
a working OS X cross toolchain on their linux machine.
Status: WorkingAsIntended
Related
I am want to compile linux 5.10.162 with CONFIG_DEBUG_INFO_BTF=y, the end goal being to enable bpf CO-RE. However, the build is failing with:
+ ./tools/bpf/resolve_btfids/resolve_btfids vmlinux
FAILED unresolved symbol udp_sock
I first thought it was something similar to this issue, but after moving to a newer gcc, the issue persists.
Relevant packages:
gcc 11.1.0 (also tested with 10.2)
dwarves 1.24 (also tested with 1.22)
Bear in mind don't have much experience compiling linux. Let me know if the config will be of use.
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
On a Raspberry Pi 1 model B I installed FreeBSD 10.3 using the SD Card Images RPI-B.
I can boot, get network, ssh into it, etc, all seems to be ok and functional. This is part of the dmesg output:
FreeBSD 10.3-RELEASE #0 r297264: Fri Mar 25 08:01:14 UTC 2016
root#releng1.nyi.freebsd.org:/usr/obj/arm.armv6/usr/src/sys/RPI-B arm
FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512
VT: init without driver.
CPU: ARM1176JZ-S rev 7 (ARM11J core)
Supported features: ARM_ISA THUMB2 JAZELLE ARMv4 Security_Ext
WB enabled LABT branch prediction enabled
16KB/32B 4-way instruction cache
16KB/32B 4-way write-back-locking-C data cache
real memory = 503312384 (479 MB)
avail memory = 483127296 (460 MB)
On a mac os X (10.11.6) with go 1.7.1:
go version go1.7.1 darwin/amd64
I am cross compile this code:
package main
import (
"fmt"
"time"
)
func main() {
t := time.Now().UTC()
fmt.Println("Location:", t.Location(), ":Time:", t.Format(time.RFC3339Nano))
}
With:
env GOOS=freebsd GOARCH=arm go build
Running the generated binary on the raspberry-pi generates a coredump:
freebsd#rpi-b:~ % ./time
Illegal instruction (core dumped)
On the time.core after typing:
$ strings time.core
besides many characters I see this:
fatal error: cgo callback before cgo call
Any idea how what flags to use or how to properly cross-compile for FreeBSD within a Raspberry pi ?
Thanks to #putu comment, I was available to cross-compile using GOARM=6
env GOOS=freebsd GOARCH=arm GOARM=6 go build
I was cross compiling C with toolchain from OpenWRT on MAC OS. The C program has a dependancy on libcurl which I already installed. However, when i build the C program, i got the error messages as below.
1.Installed libcurl on MAC
brew install curl
2.Used toolbarchain to cross compile the main.c
toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-uclibc-gcc -I/usr/local/opt/curl/include main.c
3.Compilation errors
In file included from /usr/local/opt/curl/include/curl/curl.h:35:0,
from main.c:4:
/usr/local/opt/curl/include/curl/curlrules.h:142:3: error: size of array '__curl_rule_01__' is negative
__curl_rule_01__
^
/usr/local/opt/curl/include/curl/curlrules.h:152:3: error: size of array '__curl_rule_02__' is negative
curl_rule_02
You will need to cross compile curl/libcurl using your mips toolchain.
( In fact you should do this for all other dependencies )
You have installed curl using brew, which essentially put x64 version of curl on your system.
There are certain headers in curl which gets generated at compile time ( I think curlbuild.h )
These headers define macros based on the architecture e.g. CURL_SIZEOF_LONG
As you are using curl headers (which were prepared for x64 arch ) to build mips application, it is unable to find the correct CURL_SIZEOF_LONG macro, leading -1 as a value.
Besides, at some point you will need to link against libcurl library. your current library will never link if you are using mips toolchain. So try cross-compiling curl first and use that version.
I am developing a program on OSX 10.6.4 (Snow Leopard), and I want to be able to run the compiled product on other Intel Macs, some of whom may not have XCode isntalled.
To simplify things, I first wrote a Hello World program.
#include<stdio.h>
int main() {
printf("Hello world!\n");
return 0;
}
If I compile it as
gcc -static prog.c
I get the folllowing error:
ld: library not found for -lcrt0.o
I don't know where to find this library. Now, some people have mentioned that I should not compile statically on macs since the system shared libraries should be available everywhere (third party libraries can be manually linked). However, when I try to run this Hello World program on another mac, I get the folowing error:
dyld: unknown required load command 0x80000022
Trace/BPT trap
So, how do you compile a program on mac so that it can be distributed? I am not having architecture issues, as most computers I am interested in are Intel Macs.
Don't use -static. Your executable will run fine on other 10.6.x x86 Macs. If you want to deploy on pre-10.6 Macs then you'll need to use the appropriate SDK but apart from that it should "just work", regardless of whether the developer tools are installed.
It might be worth using XCode to create your executable, using the Command Line program template (basic Unix executables), simply because it will manage a lot of the compiler options for you (including which SDK you are compiling against / which versions you are targeting).
My guess is that a default commmand-line compilation is going to compile against the current system libraries (10.6.4).