-
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
cmd/cgo: #include relative to current directory broken since Go 1.8 #20266
Comments
Put main.go into a package a use
go build github.com/you/yourproject
To build the package, rather than the file.
Explanation: when you involve go build (or run, or text) with a set of
file, rather than a package, the source code is compiled in a synthetic
package constructed in /tmp, which is why the file foo.h is not found.
…On Sat, 6 May 2017, 18:10 zan ***@***.***> wrote:
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version)?
go version devel +4b2f7b4 Sat May 6 01:28:38 2017 +0000 windows/amd64
What did you do?
main.go
`package main
//#cgo CFLAGS: -Iinc
//#include "foo.h"
import "C"
func main() {
println(C.FOO)
}
inc\foo.h#define FOO 5
`
go build main.go
*/d*/GoLang/projects/test/foo
.\main.go:4:10: fatal error: foo.h: No such file or directory
//#include "foo.h"
^~~~~~~
compilation terminated.
go1.8.1 is ok.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#20266>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAcA-uVz3HTrhqO5zTCscOevneVrC72ks5r3Cr5gaJpZM4NSq57>
.
|
If Go 1.8 is okay and tip is not, though, I want to make sure this was intentional. /cc @rsc @ianlancetaylor |
Works for me using both Go 1.8 and Go 1.9. For the failing case please show us the output of |
Fails for me on the tip on both windows-amd64 and linux-amd64:
Alex |
Oh, I see. It should work to write
See https://golang.org/cmd/cgo/ . I'm not sure whether we have introduced a new bug or whether your code is relying on undocumented behavior. I mean, you are definitely using undocumented behavior, and there is a documented workaround, but if a lot of people do what you are doing then perhaps we shouldn't change it. |
What didn't work? Could you show what you tried and what happened what you
did, please.
…On Mon, 22 May 2017, 19:02 Alessandro Arzilli ***@***.***> wrote:
you are definitely using undocumented behavior, and there is a documented
workaround
what's the documented workaround? Using go build pathtopackage, like
@davecheney <https://github.com/davecheney> said, doesn't work either, at
least not for me.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#20266 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAAcA7qGniWCvrkliTGr55UYZW4w3mbiks5r8U8vgaJpZM4NSq57>
.
|
@davecheney never mind, I didn't read all of @ianlancetaylor's message. |
This worked as recently as Go 1.8. Seems like we should keep it working for Go 1.9. |
CL https://golang.org/cl/44291 mentions this issue. |
Updates #20266. Fixes #20664. Change-Id: Ifca30409fc7971497efb6d84f3f98760157c2233 Reviewed-on: https://go-review.googlesource.com/45650 Reviewed-by: Austin Clements <austin@google.com>
What version of Go are you using (
go version
)?go version devel +4b2f7b4 Sat May 6 01:28:38 2017 +0000 windows/amd64
What did you do?
main.go
inc\foo.h
go build main.go
.\main.go:4:10: fatal error: foo.h: No such file or directory
//#include "foo.h"
^~~~~~~
compilation terminated.
go1.8.1 is ok.
The text was updated successfully, but these errors were encountered: