You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some C libraries (e.g. openssl) expect/require macros containing a quoted string. However, CGO chokes on quotes failing with malformed argument errors:
package main
/*#cgo CFLAGS: -DMYDEFINE='"quotedstring"'*/import"C"funcmain() {}
What did you expect to see?
I expect this file to build/run successfully.
What did you see instead?
$ go run main.go
package main: [...]/main.go: malformed #cgo argument: -DMYDEFINE="quotedstring"
Note, I can hack around this issue by replacing the CGO preamble statement with a direct define
package main
/*#define MYDEFINE "quotedstring"*/import"C"funcmain() {}
but the issue is that I would need to inject this into all CGO enabled Go files, opposed to just having a single CGO preamble file for all the sources.
The text was updated successfully, but these errors were encountered:
tklauser
changed the title
CGO chokes on quoted defines
cmd/cgo: chokes on quoted defines
Jun 25, 2018
We take a cautious approach to the characters permitted in #cgo directives, to avoid any possible security implications. The current restrictions are implemented in code at https://golang.org/src/go/build/build.go#L1368 .
The #cgo CFLAGS directive only applies to the current package, so it does not seem like an enormous burden to add the #define line to each cgo-using file in a single package.
I'm going to close this as working-as-expected. Please comment if you disagree.
@ianlancetaylor That seems a reasonable explanation and restriction. Perhaps one suggestion would be to add a note about it to https://golang.org/cmd/cgo/ so people have a means to find this limitation.
What version of Go are you using (
go version
)?go version go1.10.1 linux/amd64
Does this issue reproduce with the latest release?
I guess, don't see why it wouldn't :P
What operating system and processor architecture are you using (
go env
)?What did you do?
Some C libraries (e.g. openssl) expect/require macros containing a quoted string. However, CGO chokes on quotes failing with malformed argument errors:
What did you expect to see?
I expect this file to build/run successfully.
What did you see instead?
Note, I can hack around this issue by replacing the CGO preamble statement with a direct define
but the issue is that I would need to inject this into all CGO enabled Go files, opposed to just having a single CGO preamble file for all the sources.
The text was updated successfully, but these errors were encountered: