On Thu, Oct 5, 2023 at 3:13 PM sbezverk <sbezv...@gmail.com> wrote:
>
> I struggle to understand why this simple cgo program does not get linked, I 
> would provide example in playground, but it does not seem to support cgo.
>
> ```
> package main
>
>
>
> // #include <stdio.h>
>
> //
>
> // extern int go_test_func(int c1, int c2);
>
> //
>
> // int c_test_func(int c1, int c2)
>
> // {
>
> //   return go_test_func(c1,c2);
>
> // }
>
> import "C"
>
>
>
> import (
>
>           "fmt"
>
> )
>
>
>
> //export go_test_func


Quoting from https://pkg.go.dev/cmd/cgo:

Using //export in a file places a restriction on the preamble: since
it is copied into two different C output files, it must not contain
any definitions, only declarations. If a file contains both
definitions and declarations, then the two output files will produce
duplicate symbols and the linker will fail. To avoid this, definitions
must be placed in preambles in other files, or in C source files.

Ian

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUZBWMusm3vFbbATyYTOTyVt3CCgPvxTyC4kTb8g1iTjQ%40mail.gmail.com.

Reply via email to