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

Have error api/api_unix.go:15:11: fatal error: 'sql.h' file not found #192

Open
tayalone opened this issue Jan 29, 2024 · 7 comments
Open

Comments

@tayalone
Copy link

I got the error
api/api_unix.go:15:11: fatal error: 'sql.h' file not found

OS: OS X
unixODBC: 2.3.12

Screenshot 2567-01-29 at 16 27 08
@alexbrainman
Copy link
Owner

This error comes from cgo. If you installed unixODBC libraries, then cgo should be able to find unixODBC sql.h file. Can you build small C program that uses unixODBC package?

Alex

@bdgca-wjp
Copy link

You need install unixodbc package. For example, on Ubuntu you would need to do:

sudo apt install unixodbc-dev

@hut8
Copy link

hut8 commented Aug 16, 2024

I'm getting the same error and am rather confused by it...

go get github.com/alexbrainman/odbc/api # works fine
go get github.com/alexbrainman/odbc # works fine

Then if I execute:

mkdir odbctest
cd odbctest
go mod init odbctest

then put this in main.go in that folder:

package main

import (
	"database/sql"

	_ "github.com/alexbrainman/odbc"
)

func querySources() {
	sourceDB, err := sql.Open("odbc", "DSN=my_dsn_goes_here")
	if err != nil {
		panic(err)
	}
	defer sourceDB.Close()
}

func main() {
  querySources()
}

Then run go build from that directory, it fails with:

# github.com/alexbrainman/odbc/api
../../go/pkg/mod/github.com/alexbrainman/[email protected]/api/api_unix.go:15:11: fatal error: 'sql.h' file not found
 #include <sql.h>
          ^~~~~~~
1 error generated.

Here's proof that I have it:

$ find /opt/homebrew -iname 'sql.h'                                                                                                                                                     
/opt/homebrew/include/sql.h
/opt/homebrew/Cellar/mailutils/3.17/include/mailutils/sql.h
/opt/homebrew/Cellar/zig/0.13.0/lib/zig/libc/include/any-windows-any/sql.h
/opt/homebrew/Cellar/unixodbc/2.3.12/include/sql.h

$ brew info unixodbc
==> unixodbc: stable 2.3.12 (bottled)
ODBC 3 connectivity for UNIX
https://www.unixodbc.org/
Conflicts with:
  virtuoso (because both install `isql` binaries)
Installed
/opt/homebrew/Cellar/unixodbc/2.3.12 (47 files, 2.3MB) *
  Poured from bottle using the formulae.brew.sh API on 2023-08-16 at 16:35:33
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/u/unixodbc.rb
License: LGPL-2.1-or-later
==> Dependencies
Required: libtool ✔
==> Analytics
install: 18,758 (30 days), 57,966 (90 days), 304,584 (365 days)
install-on-request: 2,108 (30 days), 6,370 (90 days), 34,881 (365 days)
build-error: 5 (30 days)

@hut8
Copy link

hut8 commented Aug 16, 2024

Running this command gets me a working executable, but prints out warnings:

$ CGO_CFLAGS="-I/opt/homebrew/Cellar/unixodbc/2.3.12/include" CGO_LDFLAGS="-L/opt/homebrew/Cellar/unixodbc/2.3.12/lib" go build
# inventory
ld: warning: ignoring duplicate libraries: '-lodbc'
ld: warning: search path '/usr/local/opt/unixodbc/lib' not found

@alexbrainman
Copy link
Owner

@hut8

I don't use Mac OS myself.

But try following https://github.com/alexbrainman/odbc/wiki/GettingStartedOnOSX , perhaps it will help.

Alex

@hut8
Copy link

hut8 commented Aug 22, 2024

I appreciate you writing that page for us Mac users 😄 Unfortunately I did actually follow those directions, and the weird part that really confuses me is that go get succeeded without errors but then actually trying to use the package only partly succeeded (with warnings).

However, the actual issue is now immaterial for me because Informix, which I am burdened with using, stopped making the ODBC driver for Mac, and the latest one they have doesn't work with recent versions of OSX 😓

@FACorreiaa
Copy link

I am having a similar error

# command-line-arguments
ld: warning: ignoring duplicate libraries: '-lodbc'
ld: warning: search path '/usr/local/opt/unixodbc/lib' not found

Some env variables I have added:

export CGO_CFLAGS="-I/opt/homebrew/opt/unixodbc/include"
export CGO_LDFLAGS="-L/opt/homebrew/opt/unixodbc/lib"

my files do exist:

❯ ls /opt/homebrew/opt/unixodbc/lib

libodbc.2.dylib     libodbc.dylib       libodbccr.a         libodbcinst.2.dylib libodbcinst.dylib
libodbc.a           libodbccr.2.dylib   libodbccr.dylib     libodbcinst.a       pkgconfig

pkg-config also seems to return the right path.

❯ pkg-config --libs odbc

-L/opt/homebrew/Cellar/unixodbc/2.3.12/lib -lodbc

I am on the most recent version of macos. And I think that will be an issue too. go run

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

5 participants