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

cmd/go: cgo flags drops quotes. #12281

Open
omeid opened this issue Aug 23, 2015 · 2 comments
Open

cmd/go: cgo flags drops quotes. #12281

omeid opened this issue Aug 23, 2015 · 2 comments
Milestone

Comments

@omeid
Copy link

@omeid omeid commented Aug 23, 2015

There doesn't seem to be a way to pass a quoted value with cgo flags.

package libsass

/*
#cgo CFLAGS: -D VERSION="3.2.4-0ae11a4"


char* version(void) {
  return VERSION;
}
*/
import "C"

func Version() string {
    return C.GoString(C.version())
}
$ go build -x -v
WORK=/tmp/go-build030587731
test/cgoflag
mkdir -p $WORK/test/cgoflag/_obj/
mkdir -p $WORK/test/cgoflag/_obj/exe/
cd /home/ome/go/src/test/cgoflag
CGO_LDFLAGS="-g" "-O2" /usr/local/go/pkg/tool/linux_amd64/cgo -objdir $WORK/test/cgoflag/_obj/ -importpath test/cgoflag -- -I $WORK/test/cgoflag/_obj/ -D VERSION=3.2.4-0ae11a4 main.go
# test/cgoflag
./main.go: In function 'version':
<command-line>:0:9: error: too many decimal points in number
./main.go:8:10: note: in expansion of macro 'VERSION'
   return VERSION;
          ^
<command-line>:0:15: error: invalid suffix "ae11a4" on integer constant
./main.go:8:10: note: in expansion of macro 'VERSION'
   return VERSION;

I have also tried '"3.2.4-0ae11a4"' and some other variations, they all yield:
can't load package: package test/cgoflag: /home/ome/go/src/test/cgoflag/main.go: malformed #cgo argument: VERSION="3.2.4-0ae11a4"

@ianlancetaylor ianlancetaylor changed the title cmd/compile: cgo flags drops quotes. cmd/go: cgo flags drops quotes. Aug 25, 2015
@c4milo

This comment has been minimized.

Copy link
Member

@c4milo c4milo commented Sep 21, 2015

I'm running into this same issue.

@zengming00

This comment has been minimized.

Copy link

@zengming00 zengming00 commented Jul 25, 2019

I had the same problem, When I try to use quickjs
quickjs has a macro CONFIG_VERSION is a string, Using the #cgo directives is always wrong, I made a successful attempt with the CGO_CFLAGS environment, but this may not be a good approach

CGO_CFLAGS="-DCONFIG_VERSION=\"1.0.0\"" go build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.