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

Open
gopherbot opened this issue Jul 24, 2014 · 6 comments
Open
Labels
help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@gopherbot
Copy link
Contributor

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() {
        C.test()
}


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 https://golang.org/cl/118890044/  

The  CL(https://golang.org/cl/109640045)  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.
@ianlancetaylor
Copy link
Contributor

Comment 1:

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

@mdempsky
Copy link
Contributor

Comment 2:

At least since 2.95, GCC has supported the "unused" attribute to suppress warnings about
unused variables.  I've prepared https://golang.org/cl/121550043/ 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?

@rsc
Copy link
Contributor

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:
-Werror=unused-variable.

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

Status changed to Accepted.

@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@ysmolski
Copy link
Member

ysmolski commented Nov 6, 2018

Compiling this program

package main

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

func main() {
	C.test()
}

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?

@ianlancetaylor
Copy link
Contributor

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

@ianlancetaylor ianlancetaylor added help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Nov 6, 2018
@mohamadpk
Copy link

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
Labels
help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants