export and extern not working
package main
import (
"fmt"
)
func main() {
fmt.Println("ptr: ", ptr)
}
//export test
func test(a int) {
fmt.Println("tets ", a)
}
//go:extern test
var ptr uintptr
Result:
function declaration may only have a unique !dbg attachment
ptr @test.4
error: verification error after compiling package command-line-arguments
I want to get a pointer to an exported function without the syscall package.
I am implementing scheduler.threads for contribute. There is a need for a way to obtain a function pointer without circular references due to syscall in internal/task.
What version of tinygo are you using and how are you compiling this?
@fgsch tinygo version 0.31.0-dev linux/amd64 (using go version go1.21.3 and LLVM version 15.0.7)
Right, but what command line are you using to compile this?
No other options. tinygo run main.go.
The same goes in play.tinygo.org.
Works here with:
tinygo version 0.30.0 darwin/amd64 (using go version go1.21.5 and LLVM version 16.0.1)
under macos Sonoma.
Can you repro with 0.30.0?
There was a typo error in the code. Could you please try again?
Same error in tinygo version 0.30.0 linux/amd64 (using go version go1.21.3 and LLVM version 16.0.1).
$ tinygo version
tinygo version 0.30.0 linux/amd64 (using go version go1.21.3 and LLVM version 16.0.1)
$ tinygo run main.go
function declaration may only have a unique !dbg attachment
ptr @test.2
error: verification error after compiling package command-line-arguments
Ah, yes. I can reproduce it 👍
I'm a bit confused though, you are exporting different symbols with the same name. This is not going to work.
When I saw that a C function was imported with go:extern, I thought it would be possible since it has the same role.
Any ideas on how to get an exported function pointer without a syscall import dependency?
https://github.com/tinygo-org/tinygo/pull/4047 Currently I need to use asm because this problem.