Go Service Error - CGO_ENABLED Required (IBM DB2)

a year ago

Hi Railway Support Team,

I'm encountering an error in one of our Go services. It seems the service requires CGOENABLED=1 to be enabled because it utilizes the IBM DB2 library, which relies on CGO. You can find the library here: https://github.com/ibmdb/goibm_db.

Does anyone have suggestions on how to achieve this CGO_ENABLED setting for this service?

Below are the error logs:
0.442 cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in $PATH

Thank you
Pol

View Deploy details

ⓘ Deployment information is only viewable by project members and Railway employees.

Solved

11 Replies

a year ago

Hey,

Looks like you should be able to set a service variableCGO_ENABLED to 1

https://nixpacks.com/docs/providers/go#environment-variables

I'm not sure if that will automatically add gcc to the build but if it doesn't let me know and we can sort out some config that will.


a year ago

Hi Brody

I've tried setting the CGO_ENABLED environment variable to 1, but I'm still encountering the same error. I'm unsure why this isn't resolving the issue.

Thanks,

Pol


a year ago

It's likely that gcc isn't being automatically included in the build.

Try adding this nixpacks.toml file to your project -

[phases.setup]
    nixPkgs = ['...', 'gcc']

a year ago

Hi Brody

I have done adding the nixpacks.toml file and now it's a different error:
1.112 /root/go/pkg/mod/github.com/ibmdb/go_ibm_db@v0.4.5/api/api_unix.go:14:11: fatal error: sqlcli1.h: No such file or directory

Jul 29 21:16:21

1.112 14 | // #include <sqlcli1.h>


a year ago

I'm unsure of the cause at the moment. I've attached the error logs from the build for your reference.

Attachments


a year ago

As per - https://github.com/ibmdb/go_ibm_db/issues/21#issuecomment-1461194956

It looks like you will have to run setup.go and setenv.sh

If you are able to provide me with a minimal reproduceable example I would be able to dig into this further.


Status changed to Awaiting User Response ray-chen about 1 year ago


a year ago

Thank you Brody for this info, by the way, how can we execute this script in Railway for the setup.go and setenv.sh? I have provided the public tests Github repo https://github.com/itrepablik/test-ibm-db2 and I just wanted to test if the errors of `/root/go/pkg/mod/github.com/ibmdb/go_ibm_db@v0.4.5/api/api_unix.go:14:11: fatal error: sqlcli1.h: No such file or directory
will be fixed.

I've already added the following environment variables in Railway:
CGO_CFLAGS=-I$IBM_DB_HOME/include

CGO_ENABLED=1

CGO_LDFLAGS=-L$IBM_DB_HOME/lib

IBM_DB_DOWNLOAD_URL=https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/v11.5.9/linuxx64_odbc_cli.tar.gz

IBM_DB_HOME=/home/uname/go/src/github.com/ibmdb/clidriver

LD_LIBRARY_PATH=/home/uname/go/src/github.com/ibmdb/clidriver/lib

Could you advise on the best approach to execute these scripts and set the environment variables within Railway's deployment process?


Status changed to Awaiting Railway Response Railway about 1 year ago


a year ago

Thank you for the repo, I will play around and see if I can get it to build. Will circle back!


Status changed to Awaiting User Response Railway about 1 year ago


a year ago

Hi brody, please let me know thank you very much!


Status changed to Awaiting Railway Response Railway about 1 year ago


a year ago

Hey, I've hacked away at this for quite some time and was able to get setup.go and setenv.sh to run without issues but it made no difference, so, unfortunately, I don't have a solution for you.

Perhaps look into a pure Go database driver so you won't need cgo.


Status changed to Awaiting User Response Railway about 1 year ago


a year ago

Brody, thank you for your assistance. I believe this is the only official library available for IBM DB2 in Go. I'll explore the possibility of using a Windows machine in the cloud as an alternative solution.


Status changed to Awaiting Railway Response Railway about 1 year ago


Status changed to Completed brody about 1 year ago


Status changed to Closed brody about 1 year ago


Status changed to Solved ray-chen about 1 year ago


Go Service Error - CGO_ENABLED Required (IBM DB2) - Railway Help Station