2

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I met same problem. I didn't use stdlib at all. The error is still there. And the preprocess is right. It compare the __BYTE_ORDER to ENDIAN. one variable isn't possible has 2 different value on same time
Thank you ,it helps I found I have a endian.h header file in my project that cause this error.
Glad to hear it @RaphaelYu. Go ahead and accept the answer if it helped :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.