Hi,
I am using Go 1.15 on Ubuntu 18.04
I am learning about cgo via the following tutorial
https://golang.org/cmd/cgo/
I have the following two files which I am able to run via
go run cgo_main.go
Knowing that it runs, I'd like to build it into an executable but I get
the following errors
```
$ go build .
# example.com/user/cgohello
/tmp/go-build161353644/b001/_x003.o: In function `printf':
/usr/include/x86_64-linux-gnu/bits/stdio2.h:104: multiple definition of
`Hello'
/tmp/go-build161353644/b001/_x002.o:/usr/include/x86_64-linux-gnu/bits/stdio2.h:104:
first defined here
collect2: error: ld returned 1 exit status
```
```
// cgo_main.go
package main
/*
#include "hello.c"
*/
import "C"
import (
"errors"
"log"
)
func main() {
//Call to void function without params
err := Hello()
if err != nil {
log.Fatal(err)
}
}
//Hello is a C binding to the Hello World "C" program. As a Go user you
could
//use now the Hello function transparently without knowing that it is
calling
//a C function
func Hello() error {
_, err := C.Hello() //We ignore first result as it is a void function
if err != nil {
return errors.New("error calling Hello function: " + err.Error())
}
return nil
}
```
```
//hello.c
#include <stdio.h>
void Hello(){
printf("Hello world [cgo]\n");
}
```
Cheers
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/baf14cf9-6d57-439c-9b3e-2b4b8e3a538cn%40googlegroups.com.