Monday, June 16, 2025
HomeGolangGo run important works, go construct -o important.go fails with GOOS and...

Go run important works, go construct -o important.go fails with GOOS and GOARCH specified – Getting Assist


Hello all.

once I do a go run important.go it runs – on my MBP -M1
once I do a go construct . it builds,
once I run attempt to construct it with the beneath exports or execute the Makefile it fails – error beneath

<ps I’ve tried this identical command/steps on a amizonlinux based mostly EC2 occasion (x86-64) on AWS, as I intend to deploy to Lambda>

BINARY_NAME=important
export GOOS=linux
export GOARCH=amd64
export CGO_ENABLED=0

.DEFAULT_GOAL := deploy

deploy:
	
	go construct -o ${BINARY_NAME} .
	zip -r operate.zip important
	aws lambda update-function-code --function-name "S3JSONDecomposer-Golang" --zip-file fileb://operate.zip --region="af-south-1" | jq .    

run:
	go run ${BINARY_NAME}.go
./important.go:130:14: undefined: kafka.ConfigMap
./important.go:142:25: undefined: kafka.NewProducer

please assist

G

Hello @georgelza,

I assume you utilize confluent-kaftka-go. This library relies on the C library librdkafka, due to this fact you want CGO for compiling.

Cross-compiling is easy for pure Go code solely. I’d maybe use a VM on the Mac (Docker Desktop, Podman Desktop, OrbStack, Colima,…) to arrange a Linux construct surroundings.

i’ve tried (with Python) docker compiling and sadly all the time battle, for Python I ended constructing this EC2 pictures, that has the goal OS/Structure…
As talked about, tried this compile on the EC2 occasion additionally and ended with the identical error, will attempt once more rapidly, by no means know :wink:

will advise, thanks for the perception.
G

setting CGO_ENABLED=1 (within the MAC, lets go attempt on my EC2 occasion)

go construct -o important .
# runtime/cgo
linux_syscall.c:67:13: error: name to undeclared operate 'setresgid'; ISO C99 and later don't assist implicit operate declarations [-Wimplicit-function-declaration]
linux_syscall.c:67:13: word: did you imply 'setregid'?
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/embrace/unistd.h:593:6: word: 'setregid' declared right here
linux_syscall.c:73:13: error: name to undeclared operate 'setresuid'; ISO C99 and later don't assist implicit operate declarations [-Wimplicit-function-declaration]
linux_syscall.c:73:13: word: did you imply 'setreuid'?
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/embrace/unistd.h:595:6: word: 'setreuid' declared right here
make: *** [deploy] Error 1

with my code copied onto the EC2 occasion, based mostly on Amazon Linux… x86-64… I’m again at

that is with CGO=0 … as I’d assume it’s the identical structure as my goal, and it’s x86-64 so i’m guessing it’s the identical structure because the supply.
if I set CGO=1 then it complains for lack of C compiler. should see what c compiler to put in, by no means performed that earlier than.

make deploy
go construct -o important .
# jsondecom
./important.go:130:14: undefined: kafka.ConfigMap
./important.go:142:25: undefined: kafka.NewProducer
make: *** [Makefile:11: deploy] Error 1

AWESOME, as mentioned, thanks for pointers.
put in gcc
set CGO=1
reran Makefile, it compiled…
thanks, now to check the app rapidly.
G

1 Like

eish…
it appears the required glib libs that i put in on my EC2 picture to get it compiled isn’t on the lambda OS by default, unusual by means of, lack of know-how, however i believed this is able to be an entire/self contained binary…

/var/process/important: /lib64/libm.so.6: model `GLIBC_2.29' not discovered (required by /var/process/important)
/var/process/important: /lib64/libc.so.6: model `GLIBC_2.25' not discovered (required by /var/process/important)
/var/process/important: /lib64/libc.so.6: model `GLIBC_2.32' not discovered (required by /var/process/important)
/var/process/important: /lib64/libc.so.6: model `GLIBC_2.34' not discovered (required by /var/process/important)
2023/07/02 07:47:37 exit standing 1
/var/process/important: /lib64/libm.so.6: model `GLIBC_2.29' not discovered (required by /var/process/important)
/var/process/important: /lib64/libc.so.6: model `GLIBC_2.25' not discovered (required by /var/process/important)
/var/process/important: /lib64/libc.so.6: model `GLIBC_2.32' not discovered (required by /var/process/important)
/var/process/important: /lib64/libc.so.6: model `GLIBC_2.34' not discovered (required by /var/process/important)
2023/07/02 07:47:37 exit standing 1

The CGO setting have to be set every time Go consists of C. That is impartial of the goal structure.

1 Like

Solely wir pure Go. Any included C code has C dependencies.

I don’t know something about LambdaOS, however I discovered this Stackoverflow thread that signifies that you just may must set LD_LIBRARY_PATH and doubtless additionally provide the required glibc someway.

1 Like

with lambda you solely present your code, you don’t have entry to any exterior Os stage variables.

Lambda’s are based mostly/deployed onto amazonelinux OS’s builds.
thanks for the stackoverflow pointer, will go look.

G

1 Like

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments