cgo build error - undefined symbol fcntl
Attempt to write a simple call to (musl?) C function, fails to compile at linking stage. TinyGo 0.24.0 Linux x86_64
package main
/*
#include <clang-c/Index.h>
#include <llvm/Config/llvm-config.h>
#include <stdio.h>
*/
import "C"
func main() {
// spawn `ls` command - list directory contents
var cmd = C.CString("ls")
prc := C.popen(cmd, C.CString("r"))
C.pclose(prc)
print(C.LLVM_VERSION_STRING, "\n")
}
tinygo build results in following error
tinygo:ld.lld: error: undefined symbol: fcntl
referenced by popen.c:42 (/usr/lib/tinygo/lib/musl/src/stdio/popen.c:42) popen.c.o:(popen) in archive /home/user/.cache/tinygo/musl-x86_64-unknown-linux-x86-64/lib.a referenced by popen.c:59 (/usr/lib/tinygo/lib/musl/src/stdio/popen.c:59) popen.c.o:(popen) in archive /home/user/.cache/tinygo/musl-x86_64-unknown-linux-x86-64/lib.a
Is it just not yet implemented or is there some other way how to link the C lib?
It is not implemented. Probably the only thing needed is to include some more files in https://github.com/tinygo-org/tinygo/blob/release/builder/musl.go#L108.
Why are you doing this? Is it because os/exec doesn't work yet?
@aykevl Thanks for the reply and yes, I'd like to spawn an external command and catch its output. Adapt original Go program which uses os/exec.