Exporting functions with C type as a parameter [cannot use x (type *C.ctype) as type *package.C.ctype in argument to package.Func]
<h3>Library Code (Simplified Version):</h3>

<pre class="lang-golang prettyprint-override"><code>// package1.go

package package1

import "C"

func Play(s *C.char) {
}
</code></pre>

<h3>Client Code:</h3>

<pre class="lang-golang prettyprint-override"><code>// main.go

package main

import "C"

import (
    "path/to/package1"
)

func PlayMore(s *C.char) {
    package1.Play(s)
}

func main() {
}
</code></pre>

<h3>Build Error:</h3>

<pre class="lang-none prettyprint-override"><code># command-line-arguments
main.go:12: cannot use s (type *C.char) as type *package1.C.char
            in argument to package1.Play
</code></pre>

<p>It seems that the "C" package is local to each package, the compiler treats them as different packages. I tried something like:</p>

<pre class="lang-golang prettyprint-override"><code>func PlayMore(s *package1.C.char) {
    package1.Play(s)
}
</code></pre>

<p>But then it is a syntax error.</p>

<h3>Question:</h3>

<ul>
<li>How can I make the code compile?</li>
</ul>

<h3>More Information:</h3>

<p>In the original problem, the parameter type is not <code>*C.char</code>. It is a pointer to a C type from a legacy library.</p>

<p><code>package1</code> has a low-level API and a high-level API:</p>

<ul>
<li>The low-level API just wraps the C signatures with Go syntax. The parameter and return types are <code>C.xxx</code> types.</li>
<li>The high-level API provides a pure Go interface to the legacy library, which means there are no <code>C.xxx</code> parameter or return types. For instance, <code>string</code> is used instead of <code>*C.char</code>. The implementation prepares the parameters, and calls the low-level API for actual work.</li>
</ul>

<p>The client code above (the <code>main</code> package), is in fact another package (<code>package2</code>) which is intended to be callable from C. You can treat it as a C library built on top of another C library, but the implementation is written in Go. For instance, <code>PlayMore()</code> above is exported in the original problem, via <code>//export PlayMore</code>, in order to be callable from C.</p>

<p>When <code>package2</code> needs to call the functions provided by the legacy library, it calls the low-level API of <code>package1</code>. In fact, the reason why the low-level API of <code>package1</code> is public is to allow packages like <code>package2</code> to reuse it.</p>

<h3>Related Questions:</h3>

<p><a href="https://stackoverflow.com/q/31099620/142239">Trouble using exported function type with C types as parameters</a></p>

<p><a href="https://stackoverflow.com/q/38784963/142239">Go: Exporting functions with anonymous struct as a parameter [cannot use value (type struct {...}) as type struct {...} in argument to package.Func]</a></p>