void type alias can not be understood in cgo

60 views
Skip to first unread message

hui zhang

unread,
Apr 26, 2017, 3:20:14 AM4/26/17
to golang-nuts
Check code below
go call c opengl/opengles code,   typedef void GLvoid

func GenVertexArrays(n int32, arrays *uint32) {
//C.glGenVertexArrays((C.GLsizei)(n), (*C.GLuint)(unsafe.Pointer(arrays))) --> ok on darwin amd64
C.glGenVertexArraysOES((C.GLsizei)(n), (*C.GLuint)(unsafe.Pointer(arrays))) --> fail on darwin arm
}
Error Message

cgo-gcc-prolog:36:10: error: field has incomplete type 'GLvoid' (aka 'void')

For the GLvoid(aka void)  can not be understood by cgo

function decalred
void glGenVertexArrays(GLsizei n, GLuint *arrays); -->on darwin amd64 opengl
GLvoid glGenVertexArraysOES(GLsizei n, GLuint *arrays) -->on darwin arm opengles




hui zhang

unread,
Apr 26, 2017, 3:59:15 AM4/26/17
to golang-nuts
I simply the case  as below , how to fix it?

package main

/*
#include <stdlib.h>
#include <stdio.h>
typedef void GLvoid;
GLvoid Foo() {
printf("foo");
}
*/
import "C"

func main() {
C.Foo()
}
go build void.go

cgo-gcc-prolog:34:10: error: field has incomplete type 'GLvoid' (aka 'void')

在 2017年4月26日星期三 UTC+8下午3:20:14,hui zhang写道:

hui zhang

unread,
Apr 26, 2017, 4:37:38 AM4/26/17
to golang-nuts
this code runs well on ubuntu gcc --version
gcc (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005
but build fail on mac

 gcc --version

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1

Apple LLVM version 8.0.0 (clang-800.0.42.1)

Target: x86_64-apple-darwin15.5.0

Thread model: posix


any workaround ?


在 2017年4月26日星期三 UTC+8下午3:59:15,hui zhang写道:

hui zhang

unread,
Apr 26, 2017, 5:03:50 AM4/26/17
to golang-nuts
Is this bug  in cgo  or  in clang

for  gcc runs well ?

CC=clang CGO_ENABLE=1 go build -v void.go             -->fail
command-line-arguments
# command-line-arguments
./void.go:47:10: error: field has incomplete type 'GLvoid' (aka 'void')

CC=gcc CGO_ENABLE=1 go build -o void -v void.go      -->ok
command-line-arguments

在 2017年4月26日星期三 UTC+8下午4:37:38,hui zhang写道:
Reply all
Reply to author
Forward
0 new messages