[英]go build with c library, met duplicated members which are in stdlib.h
I am doing some protocol stack programming with golang.我正在用 golang 做一些协议栈编程。 I put codec thing in C. And build C with a simple CMake configuration as below:
我将编解码器放在 C 中。并使用如下简单的 CMake 配置构建 C:
cmake_minimum_required (VERSION 2.8)
project (Demo1)
aux_source_directory(. DIR_SRCS)
add_library(codecLib SHARED ${DIR_SRCS})
and Link the shared library with this kind code并使用这种代码链接共享库
//#cgo CFLAGS:-I./codec/
//#cgo LDFLAGS: ./codec/build -lcodecLib
//#include <protocol.h>
import "C"
import "fmt"
at last, I met following error while building it with command "CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build",最后,我在使用命令“CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build”构建它时遇到了以下错误,
In file included from /usr/include/stdlib.h:42:0,
from _cgo_export.c:2:
/usr/include/x86_64-linux-gnu/bits/waitstatus.h:79:15: error: duplicate member ‘__w_retcode’
unsigned int __w_retcode:8;
^
/usr/include/x86_64-linux-gnu/bits/waitstatus.h:80:15: error: duplicate member ‘__w_coredump’
unsigned int __w_coredump:1;
^
/usr/include/x86_64-linux-gnu/bits/waitstatus.h:81:15: error: duplicate member ‘__w_termsig’
unsigned int __w_termsig:7;
^
/usr/include/x86_64-linux-gnu/bits/waitstatus.h:93:15: error: duplicate member ‘__w_stopsig’
unsigned int __w_stopsig:8; /* Stopping signal. */
^
/usr/include/x86_64-linux-gnu/bits/waitstatus.h:94:15: error: duplicate member ‘__w_stopval’
unsigned int __w_stopval:8; /* W_STOPPED if stopped. */
I didn't find the solution yet.我还没有找到解决方案。 I appreciate for the solution.
我感谢解决方案。
The problem you're having is probably due to GOLang not parsing the pre-processor commands in the GNU C Library properly (or at all).您遇到的问题可能是由于 GOLang 没有正确(或根本没有)解析 GNU C 库中的预处理器命令。 It could also be due to an issue with your importing
endian.h
, or requiring some other C/GO/CGO import or define.也可能是由于您导入的
endian.h
出现问题,或者需要其他一些 C/GO/CGO 导入或定义。
Here's an excerpt from waitstatus.h
( or see the full file on GitHub ):以下是
waitstatus.h
的摘录( 或查看 GitHub 上的完整文件):
# if __BYTE_ORDER == __LITTLE_ENDIAN
unsigned int __w_termsig:7;
unsigned int __w_coredump:1;
unsigned int __w_retcode:8;
unsigned int:16;
# endif /* Little endian. */
# if __BYTE_ORDER == __BIG_ENDIAN
unsigned int:16;
unsigned int __w_retcode:8;
unsigned int __w_coredump:1;
unsigned int __w_termsig:7;
# endif /* Big endian. */
You'll notice that the same variables are announced twice - one for each Endian.您会注意到相同的变量被宣布了两次 - 每个 Endian 一个。 GOLang is erroring because of this.
由于这个原因,GOLang 出错了。 You could resolve this by manually editing the file if you know which endian you're compiling for.
如果您知道要编译的字节序,则可以通过手动编辑文件来解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.