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: go install doesn't recognize changes to c code in another directory #19883

Closed
alexd765 opened this issue Apr 7, 2017 · 3 comments
Closed

Comments

@alexd765
Copy link
Contributor

alexd765 commented Apr 7, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version devel +a8b2e4a Fri Mar 31 21:24:09 2017 +0000 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/alex/gopath"
GORACE=""
GOROOT="/home/alex/go"
GOTOOLDIR="/home/alex/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build681403283=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

  • go install -v program with c code
  • make changes to c code in different directory
  • go install -v again

If possible, provide a recipe for reproducing the error.

cat main.go:
package main

import "fmt"

/*
#include "test/test.h"
*/
import "C"

func main() {
	fmt.Println(C.x)
}
cat test/test.h:
int x=1;

on github

What did you expect to see?

go install -v
github.com/alexd765/cgo-issue

change to x=2 in test/test.h

go install -v
github.com/alexd765/cgo-issue

What did you see instead?

go install -v
github.com/alexd765/cgo-issue

change to x=2 in test/test.h

go install -v
  • go install thinks the code didn't change.
  • It works if the c code is in the same directory.
  • it doesn't work if the c code is in another directory (outside or subdirectory).
@alexd765 alexd765 changed the title cmd/go: go install doesn't recognise changes in c code in different directories cmd/go: go install doesn't recognize changes to c code in different directories Apr 7, 2017
@alexd765 alexd765 changed the title cmd/go: go install doesn't recognize changes to c code in different directories cmd/go: go install doesn't recognize changes to c code in another directory Apr 7, 2017
@bradfitz bradfitz added this to the Unplanned milestone Apr 9, 2017
@bradfitz
Copy link
Contributor

bradfitz commented Apr 9, 2017

Of note: cmd/go is a Go build system and not a C build system. But I'll let @rsc decide what to do here, if anything.

@alexd765
Copy link
Contributor Author

That makes sense.

This is obviously a minimal example. I want to give a little bit more context how I ran into this:

We have a not-so-thin wrapper around a C library that is a mix of Go and C code that we install with go install (without the -v). When we make changes to go code and c code at the same time everything works.
When we made only changes to the C Code it was quite surprising that the new version didn't get installed.

The workaround is to force rebuilding with go install -a.

@rsc
Copy link
Contributor

rsc commented Apr 10, 2017

The Go command essentially requires that your C code be in the same directory as the Go package using it, not in a subdirectory or other directory. This is by design: package directories are meant to be completely self-contained, although obviously this is difficult/impossible to enforce in all cases.

@rsc rsc closed this as completed Apr 10, 2017
@golang golang locked and limited conversation to collaborators Apr 10, 2018
@rsc rsc removed their assignment Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants