"C source files not allowed when not using cgo" error

3,860 views
Skip to first unread message

Silvan Jegen

unread,
Oct 8, 2014, 12:08:46 PM10/8/14
to golan...@googlegroups.com
Hi

when building the https://github.com/boltdb/bolt package on Linux amd64 I get the following error message.

"db.go:8:2: C source files not allowed when not using cgo: debug.c"

I am using

go version devel +c5ee3f481631 Wed Oct 08 07:10:04 2014 -0700 linux/amd64

with the following go env

GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/silvan/build/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

db.go:8:2 in package github.com/boltdb/bolt imports "runtime/debug". Packages that do not import "runtime/debug" seem to build and work fine.

The debug.c in runtime/debug seems to be an empty placeholder file. Does anyone know what could be the issue?


Cheers,

Silvan

Dave Cheney

unread,
Oct 9, 2014, 4:25:23 AM10/9/14
to golan...@googlegroups.com
This should only happen if you are using the development version of Go. Are you ? Are you sure that you don't have bits of a release version of Go installed as well ? In your PATH ? If you have not unset GOROOT.

Silvan Jegen

unread,
Oct 9, 2014, 5:12:27 AM10/9/14
to Dave Cheney, golan...@googlegroups.com
On Thu, Oct 09, 2014 at 01:25:23AM -0700, Dave Cheney wrote:
> This should only happen if you are using the development version of Go. Are
> you ? Are you sure that you don't have bits of a release version of Go
> installed as well ? In your PATH ? If you have not unset GOROOT.

I am using the dev version of Go and apparently there were some old
release version files lying around as well. I deleted them and now the
package builds correctly.

I have set GOROOT to /usr/lib/go but since this is not the default
location (/usr/local/go) I think that should be okay even when using
the development version of Go.


Cheers and thanks,

Silvan

Dave Cheney

unread,
Oct 9, 2014, 5:14:43 AM10/9/14
to Silvan Jegen, golang-nuts
>
> I have set GOROOT to /usr/lib/go but since this is not the default
> location (/usr/local/go) I think that should be okay even when using
> the development version of Go.

this is a mistake, you should not need to set GOROOT.

When building from source the value of GOROOT is taken from where the
source is checked out into, usually somewhere in your home directory.

Rather than building, then moving Go and setting GOROOT, just build it
in its final location.

Silvan Jegen

unread,
Oct 9, 2014, 5:48:15 AM10/9/14
to Dave Cheney, golang-nuts
I see. I did it that way in order to make a package that can be managed
by the package manager of my distro. Building Go in the final install
destination directly should be about as easy though and will probably
lead to fewer problems down the road.

Dave Cheney

unread,
Oct 9, 2014, 5:52:27 AM10/9/14
to Silvan Jegen, golang-nuts
If you want to do that use GOROOT_FINAL, http://golang.org/src/make.bash

chai2010

unread,
Oct 11, 2014, 4:06:09 AM10/11/14
to Dave Cheney, Silvan Jegen, golang-nuts
I have the same error:

bridge.go:22:2: C source files not allowed when not using cgo: cdata.c

go version
go version devel +7b51e20e6835 Fri Oct 10 20:30:24 2014 -0400 windows/amd64

go env
set GOARCH=amd64
set GOBIN=
set GOCHAR=6
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\go\go.pkg;D:\work\chai2010.gopkg;D:\work\godev2013
set GORACE=
set GOROOT=C:\go\go.tip
set GOTOOLDIR=C:\go\go.tip\pkg\tool\windows_amd64
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1

gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/tdm-gcc-64/bin/../libexec/gcc/x86_64-w64-mingw32/4.8.1/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-4.8.1/configure --build=x86_64-w64-mingw32 --enable-targets=all --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-libgomp --enable-lto --enable-graphite --enable-cxx-flags=-DWINPTHREAD_STATIC --enable-libstdcxx-debug --enable-threads=posix --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libstdcxx-threads --enable-libstdcxx-time --with-gnu-ld --disable-werror --disable-nls --disable-win32-registry --prefix=/mingw64tdm --with-local-prefix=/mingw64tdm --with-pkgversion=tdm64-2 --with-bugurl=http://tdm-gcc.tdragon.net/bugs
Thread model: posix
gcc version 4.8.1 (tdm64-2)

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Dave Cheney

unread,
Oct 11, 2014, 4:09:34 AM10/11/14
to chai2010, golang-nuts, Silvan Jegen

Sorry, the use of the built in c compiler, 6c is going away in go 1.4. What that package does is no longer supported.

chai2010

unread,
Oct 11, 2014, 4:34:29 AM10/11/14
to Dave Cheney, golang-nuts, Silvan Jegen
I see, thanks!

Gustavo Niemeyer

unread,
Oct 11, 2014, 5:31:05 AM10/11/14
to chai2010, Dave Cheney, Silvan Jegen, golang-nuts
If you merge from upstream that issue will go away. It was already
fixed in the qml package.
gustavo @ http://niemeyer.net

dani...@dropbox.com

unread,
Dec 10, 2014, 4:53:56 PM12/10/14
to golan...@googlegroups.com, chais...@gmail.com, da...@cheney.net, s.j...@gmail.com
I'm building a library to allow c code to invoke go code (by spawning a process and managing a socket per goroutine). In my package I want a few c files so that C programs can link to those and some go files as well.
https://github.com/dropbox/godropbox/tree/master/cinterop with C files in https://github.com/dropbox/godropbox/tree/master/cinterop/lib

In the past things would build fine...but with top of tree I get this error

go get -t -v ./...

"C source files not allowed when not using cgo"


Is there any way to mark files as not buildable so that I'd can just ignore the C files if possible.  In the past it was as simple as

#ifdef __STDC__

<source code here>

#endif

But that option has now gone away :-(

Is there a marker I can put in place to make go build ignore those files while having them in my repo for C code to link against?

Thanks

Dave Cheney

unread,
Dec 10, 2014, 5:13:14 PM12/10/14
to dani...@dropbox.com, chai2010, golang-nuts, s.j...@gmail.com

Try

// +build none

At the top of the file. I've written a but about the rules for build tags here, http://dave.cheney.net/2013/10/12/how-to-use-conditional-compilation-with-the-go-build-tool

Dave Cheney

unread,
Dec 10, 2014, 6:13:04 PM12/10/14
to Daniel Horn, chai2010, golang-nuts, Silvan Jegen
You're welcome. Technically "none" is not a magic name, it just
happens to not match any GOOS or GOARCH value in use. You'll find that
in the golang.org/x/talks repo they use // +build OMIT, because OMIT
is a magic flag that tells the present tool it not print that line, so
it serves two purposes.

On Thu, Dec 11, 2014 at 9:50 AM, Daniel Horn <dani...@dropbox.com> wrote:
> Thank you so much for the prompt and useful help!
>
> // +build none
>
> works like a charm

Daniel Horn

unread,
Dec 10, 2014, 8:06:51 PM12/10/14
to Dave Cheney, chai2010, golang-nuts, s.j...@gmail.com
Thank you so much for the prompt and useful help!

// +build none

works like a charm

On Wed, Dec 10, 2014 at 2:12 PM, Dave Cheney <da...@cheney.net> wrote:
Reply all
Reply to author
Forward
0 new messages