douxian4376 2018-08-20 14:25
浏览 218

去用C库构建,遇到stdlib.h中重复的成员

I am doing some protocol stack programming with golang. I put codec thing in C. And build C with a simple CMake configuration as below:

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",

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.

  • 写回答

1条回答 默认 最新

  • drt12345678 2018-08-24 04:10
    关注

    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). It could also be due to an issue with your importing endian.h, or requiring some other C/GO/CGO import or define.

    Here's an excerpt from waitstatus.h (or see the full file on 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. GOLang is erroring because of this. You could resolve this by manually editing the file if you know which endian you're compiling for.

    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录