1

Observe:

$ cat /tmp/plugin.go
package main

import "fmt"

var V int

func F() { fmt.Printf("Hello, number %d\n", V) }

$ go build -buildmode=plugin -o /tmp/plugin.so /tmp/plugin.go
# runtime/cgo
cgo-builtin-prolog:1:57: fatal error: stddef.h: No such file or directory
compilation terminated.

Why is that?

This is under Ubuntu 17.04, and I have build-essentials installed:

$ go version
go version go1.9 linux/amd64

$ uname -r
4.10.0-37-generic

$ lsb_release -a 
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 17.04
Release:        17.04
Codename:       zesty

$ apt-cache policy build-essential
build-essential:
  Installed: 12.1ubuntu2
  Candidate: 12.1ubuntu2

please not the "Compilation error: "stddef.h: No such file or directory"" is NOT the answer as my gcc-core package and gcc-g++ are of the same version -- here are my gcc related packages:

 gcc_4:6.3.0-2ubuntu1
 gcc-6_6.3.0-12ubuntu2
 gcc-6-base:amd64_6.3.0-12ubuntu2
 libgcc-6-dev:amd64_6.3.0-12ubuntu2
 libgcc1:amd64_1:6.3.0-12ubuntu2

UPDATE:

thanks @peterSO, seems to be my gcc's own problem:

$ cat /tmp/foo.c 
#include <stdio.h>

$ gcc /tmp/foo.c 
In file included from /tmp/foo.c:1:0:
/usr/include/stdio.h:33:21: fatal error: stddef.h: No such file or directory
 # include <stddef.h>

While searching for solution for it, I found someone suggested to reinstall gcc, so I did, together with libc6-dev:

apt-get --reinstall install libgcc-6-dev gcc-6 gcc-6-base:amd64 libc6-dev:amd64

Now my simple .c file compiles OK now, but I'm bumped into a new problem with cgo:

$ go build -buildmode=plugin -o /tmp/plugin.so /tmp/plugin.go
# runtime/cgo
In file included from /usr/include/errno.h:35:0,
                 from cgo-gcc-prolog:21:
/usr/include/x86_64-linux-gnu/bits/errno.h:24:26: fatal error: linux/errno.h: No such file or directory
 # include <linux/errno.h>
                          ^
compilation terminated.

I know this might be a Ubuntu/gcc specific problem (Ref: Why is stddef.h not in /usr/include? and my stddef.h is under /usr/src/linux-headers-4.10.0-37/include/linux/stddef.h), but anybody here knows Go and gcc good enough to know how to fix it, so that Go plugins can be compiled properly?

Thx!

xpt
  • 20,363
  • 37
  • 127
  • 216
  • Works for me: 16.04 & 17.10; gcc5 & gcc7; go1.8, go1.9, gotip; etc. I have `gcc` and `libc6-dev` installed. – peterSO Oct 29 '17 at 23:18
  • I installed Ubuntu 17.04 and updated all packages (`apt update`, `apt upgrade`). All the necessary packages, including `gcc` and `libc6-dev`, were preinstalled. I downloaded and installed `go1.9.2` (https://golang.org/dl/ and https://golang.org/doc/install). I created `/tmp/plugin.go` and ran `go build -v -buildmode=plugin -o /tmp/plugin.so /tmp/plugin.go`. It completed successfully and created `/tmp/plugin.so`. Your Ubuntu 17.04 installation is broken. – peterSO Oct 30 '17 at 13:12
  • 1
    Your Ubuntu 17.04 installation is broken. You may have to reinstall the OS. You might try refreshing the OS to 17.10 (Upgrading from Ubuntu 17.04: https://wiki.ubuntu.com/ArtfulAardvark/ReleaseNotes). – peterSO Oct 30 '17 at 13:15
  • Thanks @peterSO, I guess so. Thanks for going all the way trying. I've just verified that my other machine works fine, which was installed the same way. I'll trying to reinstall everything `gcc` related and see if it'd help... – xpt Oct 31 '17 at 00:15

0 Answers0