Last active
November 29, 2022 08:00
-
-
Save JackyCZJ/f2284567685596dd34ecc468626b1a73 to your computer and use it in GitHub Desktop.
How to cross compile an openwrt CGO program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TARGET= GreatCGOProgram | |
OPENWRT_SDK=/home/user/openwrt | |
STAGING_DIR=$(OPENWRT_SDK)/staging_dir | |
CC=$(BUILD_DIR)/$(OPENWRT_SDK)/staging_dir/$(toolchain_dir)/bin/$(ARCH)-openwrt-linux-gcc | |
# example: | |
# toolchain-aarch64_cortex-a53+crypto_gcc-8.4.0_musl | |
# aarch64-openwrt-linux-gcc | |
CGO_CFLAGS=-I$(STAGING_DIR)/target-$(ARCH)_[musl|glib]/usr/include | |
CGO_LDFLAGS=-L$(STAGING_DIR)/target-$(ARCH)_[musl|glib]/usr/lib -lubox -lblobmsg_json -lubus -luci -ljson-c | |
#example | |
# target-aarch64_cortex-a53+crypto_musl | |
all: clean $(TARGET) | |
$(TARGET): | |
STAGING_DIR="$(STAGING_DIR)" CC="$(CC)" CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_ENABLED=1 GOOS=linux GOARCH=$(ARCH) \ | |
go build -o $(TARGET) main.go |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment