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: build failed when any code have CFLAGS: -Werror=unused-vairable #8420

gopherbot opened this Issue Jul 24, 2014 · 6 comments


None yet
6 participants

gopherbot commented Jul 24, 2014

by Snyh1010:

1. What is a short input program that triggers the error?
package main

//#cgo CFLAGS: -Werror=unused-variable
//void test(){}
import "C"

func main() {

2. What is the full compiler output?
snyh:shm$go build
# _/run/shm
./a.go: In function ‘_cgo_043ca501ac1f_Cfunc_test’:
./a.go:32:49: error: unused variable ‘a’ [-Werror=unused-variable]
cc1: some warnings being treated as errors

I have fixed this by  a CL  

The  CL(  had fix this problem under gcc. 
The first time I hasn't notice clang, so when the CL has been submitted, it broken
freebsd because clang.  And the CL has been undo.

The broken problem is not caused by my code, it's appeared upon the submission because
the CL contains the test code let the problem appeared. 

I have fixed the problem  both clang and gcc.  But it seems no one have confidence to
submit it this time, I have send the CL request. 
Anyway I want the problem be fixed, with or without my CL.

This comment has been minimized.


ianlancetaylor commented Jul 25, 2014

Comment 1:

Labels changed: added repo-main, release-go1.4.


This comment has been minimized.


mdempsky commented Aug 12, 2014

Comment 2:

At least since 2.95, GCC has supported the "unused" attribute to suppress warnings about
unused variables.  I've prepared to make use
of this in cgo.
It also looks like -Werror=unused-variable has been supported since GCC 4.2, so it
should be available on OS X and BSD too.  Though even if we wanted to support an
old-timey platform using an older GCC, we could just add an appropriate "// +build
!openbsd,vax" line to issue8420.go.
snyh: Can you please confirm whether the above CL adequately addresses your needs?

This comment has been minimized.


rsc commented Sep 15, 2014

Comment 3:

I'm not touching this for the 1.4 release. There is an easy fix. Do not say CFLAGS:

Labels changed: added release-none, removed release-go1.4.

Status changed to Accepted.

@rsc rsc added this to the Unplanned milestone Apr 10, 2015

@rsc rsc removed release-none labels Apr 10, 2015


This comment has been minimized.


ysmolsky commented Nov 6, 2018

Compiling this program

package main

// #cgo CFLAGS: -Werror=unused-variable
// void test(){}
import "C"

func main() {

on mac gives me:

...go/src/tmp % go build
# tmp
./main.go:8:2: could not determine kind of name for C.test

@mdempsky should we fix this?


This comment has been minimized.


ianlancetaylor commented Nov 6, 2018

It's fine if someone wants to fix this, but it's not an important bug to fix.


This comment has been minimized.

mohamadpk commented Dec 9, 2018

disable c go on environment variable or CGO_ENABLED=0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment