-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
proposal: cmd/cgo: expand $GOPATH in -I and -L directives #20606
Comments
Note that $GOPATH is not a single value; it is a list of paths. That complicates this proposal a bit. |
As does vendoring: if this package is vendored (along with its internal packages) then the -I option is not right anymore. |
cgo always puts a -I <path to package dir> onto the command line, so if you have headers in some directory at a fixed location relative to the package dir, you should be able to #include with a relative path. For example if your code is in github.com/chewxy/mypkg and you want the headers in github.com/chewxy/path/to/internal/sharedheaders, then |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.8.3 linux/amd64
What operating system and processor architecture are you using (
go env
)?What did you
dowant?What did you expect to see?
Compilation to complete.
What did you see instead?
Compilation failed.
Workarounds
Instead the ugly solution is really ugly: you'd have to use the full absolute path:
Another solution would be copy the
.h
files into each individual directory. This makes building libraries a bit messy and reliant on abs paths (for context, I'm working on improvements on the CUDA library), and would most likely require things like makefiles, which makes a library unappealing to use/install.Currently cgo accepts
${SRCDIR}
to handle statically compiled libs to be included in a directory.So you can see why a solution which expands
${GOPATH}
the same way${SRCDIR}
would be nice to have, and I suspect, fairly trivial to add. The checks for internal packages may be a bit tricky.References/Related Issues
Issue #19745 : @bradfitz and @rsc said that the goal of cmd/go is not to be a C build tool. To which I agree. I propose only limiting this to
internal
packages. This does away with the problem of implicit dependency issues (the logic of it goes: all the dependencies go into theinternal
package anyway as a "final destination")Thoughts appreciated.
The text was updated successfully, but these errors were encountered: