Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors when building for Mac #47

Closed
prasanthcaibmcom opened this issue Nov 28, 2019 · 21 comments
Closed

Errors when building for Mac #47

prasanthcaibmcom opened this issue Nov 28, 2019 · 21 comments

Comments

@prasanthcaibmcom
Copy link

prasanthcaibmcom commented Nov 28, 2019

Can we cross compile a Mac build of our binary which uses go_ibm_db on a Linux machine?

When running with CGO_ENABLED=1:

+ CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o agent-linux .
+ CGO_ENABLED=1 GOOS=windows go build -a -installsuffix cgo -o agent-windows .
+ CGO_ENABLED=1 GOOS=darwin go build -a -installsuffix cgo -o agent-darwin .
# net
../../tools/org.jenkinsci.plugins.golang.GolangInstallation/1.13/src/net/cgo_bsd.go:15:72: could not determine kind of name for C.AI_MASK
# os/user
../../tools/org.jenkinsci.plugins.golang.GolangInstallation/1.13/src/os/user/getgrouplist_darwin.go: In function ‘mygetgrouplist’:
../../tools/org.jenkinsci.plugins.golang.GolangInstallation/1.13/src/os/user/getgrouplist_darwin.go:16:11: warning: implicit declaration of function ‘getgrouplist’ [-Wimplicit-function-declaration]
  int rv = getgrouplist(user, (int) group, buf, ngroups);

Is it possible to cross-compile the package without building the driver into the binary? And allow the appropriate driver to be present at runtime ?

We are importing and using the driver like this:

import (
	"database/sql"

	_ "github.com/ibmdb/go_ibm_db"
)
	db, err := sql.Open("go_ibm_db", con)

We would like to use a single Linux environment to build all binaries for Windows, Mac, and Linux.

@akhilravuri1
Copy link
Contributor

Hi @prasanthcaibmcom
Before Go 1.12 we can use binary-only packages but from Go1.12 binary-only packages are not supported.

You can cross-compile but our go driver needs clidriver of that platform(compilation) so if you have that platform clidriver you can use it.

Thanks,
Akhil

@prasanthcaibmcom
Copy link
Author

Can we cross compile without CGO_ENABLED=1 as long the clidriver is present?

CGO_ENABLED=1 seems to cause the issue that I posted above for a Mac build. But I cannot seem to compile with CGO_ENABLED=0 either without error.

@akhilravuri1
Copy link
Contributor

Our go driver is on top of the cli driver(which is written in c language) so you need to enable the CGO flag(CGO_ENABLED=1).

This may help you
https://medium.com/@diogok/on-golang-static-binaries-cross-compiling-and-plugins-1aed33499671

Thanks
Akhil

@prasanthcaibmcom
Copy link
Author

prasanthcaibmcom commented Dec 2, 2019

I am trying to understand the nuance here about cross compiling:

Namely: Is there a way to not package the go_ibm_db2 driver building the go executable, so that we can build it without CGO_ENABLED ?

And then later, drop in the appropriate driver ?

@akhilravuri1
Copy link
Contributor

Sorry!! you cannot use package go_ibm_db to an executable without enabling the CGO_ENABLED flag.

In the windows version, you can use it without the cgo_enabled flag.

Thanks,
Akhil

@prasanthcaibmcom
Copy link
Author

Thanks. Closing this issue.

@prasanthcaibmcom
Copy link
Author

prasanthcaibmcom commented Dec 5, 2019

I built the binary on a Mac system with CGO_ENABLED. When running on another Mac system, I get the following:

drsmac:~ macadmin$ ./drs-agent
dyld: Library not loaded: libdb2.dylib
Referenced from: /Users/macadmin/./drs-agent
Reason: image not found
Abort trap: 6

Does the cli driver always have to be bundled with the application using the driver?

This is with CGO_ENABLED=1 go build

@akhilravuri1
Copy link
Contributor

I have never tested it. As of my knowledge no need to bundle the clidriver in the application. But the cli driver has to be present in the system where you are running the binary.

I will also give a try.

Thanks,
Akhil

@prasanthcaibmcom
Copy link
Author

So this would mean packaging the clidriver folder that is generated by installer/setup.go for each platform?

@akhilravuri1
Copy link
Contributor

akhilravuri1 commented Dec 6, 2019

Yes!!

dyld: Library not loaded: libdb2.dylib

This is error occurs when clidriver/lib is not found in the $DYLD_LIBRARY_PATH
It's not just packaging you need to set the env variables required.

@prasanthcaibmcom
Copy link
Author

Ah, I see. Thanks !

@akhilravuri1
Copy link
Contributor

Ah, I see. Thanks !

I will try to reproduce the issue..

Thanks,
Akhil

@prasanthcaibmcom
Copy link
Author

@akhilravuri1 Is the go ibm driver supported on Linux ?

@akhilravuri1
Copy link
Contributor

Yes. go_ibm_db is supported on Linux.

@prasanthcaibmcom
Copy link
Author

@akhilravuri1 Sorry! Dumb question. I meant to ask if it's supported on AIX.

@akhilravuri1
Copy link
Contributor

akhilravuri1 commented Dec 17, 2019

Our Go driver supports all platforms where clidriver and Go are supported.

Our driver should support on AIX as go and clidriver is supported there. But, I never tested on that platform.

@prasanthcaibmcom
Copy link
Author

@akhilravuri1 Thanks...but I don't quite understand the process. What steps would be run for grabbing the cli driver? Which environment variables would be exported?

Your instructions have steps for Mac, Linux, and Windows.....would I follow the Linux steps?

@akhilravuri1
Copy link
Contributor

Your instructions have steps for Mac, Linux, and Windows.....would I follow the Linux steps?

Yes, you can follow Linux steps.

@prasanthcaibmcom
Copy link
Author

@akhilravuri1 Thanks...and this may be a silly question, but how would one build Golang on AIX machine? Seeing as golang does not provide installers for this platform:

https://golang.org/dl/

Is AIX treated as Linux-like for the purpose of installing/compiling Go ?

@akhilravuri1
Copy link
Contributor

Hi @prasanthcaibmcom
If you want to use go on AIX you need to build it from the source.
All the steps are given in this link https://golang.org/doc/install/source?download=go1.13.5.src.tar.gz

Like which tools are required to build and how to use them and how to set the env's.

If you face any issues while building please feel free to contact me.

Thanks,
Akhil

@akhilravuri1
Copy link
Contributor

akhilravuri1 commented Dec 17, 2019

Hi @prasanthcaibmcom

I have found this rpm package you can try using this build.
http://www.bullfreeware.com/pkg?id=5515

Thanks
Akhil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants