Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cgo: can't build with both inline C function define and Go function export #10982

Closed
xiezhenye opened this issue May 29, 2015 · 1 comment

Comments

@xiezhenye
Copy link

commented May 29, 2015

can't build with both inline C function define andGo function export

code:

package main

//
// int add(int a, int b) {
//   int ret = a + b;
//   return ret;
// }
//
// extern void foo();
//
import "C"

import (
  "fmt"
)

//export foo
func foo() {
}

func main() {
  var n int32
  n = int32(C.add(C.int(2), C.int(3)))
  fmt.Println(n)
}

got compile error:

# GOROOT=/opt/go-1.4.2 /opt/go-1.4.2/bin/go build cgo.go
# command-line-arguments
/tmp/go-build570506490/command-line-arguments/_obj/cgo.cgo2.o: In function `add':
./cgo.go:5: multiple definition of `add'
/tmp/go-build570506490/command-line-arguments/_obj/_cgo_export.o:/root/test/testgoc/cgo.go:5: first defined here
collect2: error: ld returned 1 exit status

cgo writes the inline C functions both in cgo.cgo2.c and _cgo_export.h

@minux minux closed this May 29, 2015

@minux

This comment has been minimized.

Copy link
Member

commented May 29, 2015

@mikioh mikioh changed the title can't build with both inline C function define andGo function export cmd/cgo: can't build with both inline C function define and Go function export May 29, 2015

@golang golang locked and limited conversation to collaborators Jun 25, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants
You can’t perform that action at this time.