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

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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)