dongtang9855 2017-10-29 21:11
浏览 650

Go 1.8插件,致命错误:stddef.h:无此类文件

Observe:

$ cat /tmp/plugin.go
package main

import "fmt"

var V int

func F() { fmt.Printf("Hello, number %d
", 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!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了