Closed eugeny-dementev closed 6 days ago
Yeah, is buildable, have you added the ".so"/".dll" file + header?
Hello! No, I'm not. It's first time I'm dealing with cgo and lacking knowledge on how it's usually done. What would be the set of commands that should be run to build it with freshly cloned repo
I assume since .so/.dll files mentioned, first is to build C library itself, how to do that?
Builded library, still cannot build go bindings
Okay, my bad. I've expected build instruction to be in readme.md file but it's on the website. Successfully builded shared release for macos on arm64. Have ntgcalls.h
and libntgcalls.dylib
files now
Moved these files into ./examples/go/ntgcalls/
folder.
Now trying to build go and have that issue that I'm not sure relates to what
> CGO_ENABLED=1 go build
# gotgcalls
/opt/homebrew/Cellar/go/1.22.4/libexec/pkg/tool/darwin_arm64/link: running cc failed: exit status 1
ld: unknown options: -rpath=./
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Currently, the build is already precompiled for macOS, you can find the files here: https://github.com/pytgcalls/ntgcalls/releases/tag/v1.2.1
As regards the inclusion of files on macOS within Go, it is incomplete since I currently don't know why the import doesn't work and not having a Mac I can't try, but in any case, it's just a problem of importing from the Go side
I've tried on windows and linux and pretty much having the same result
On windows and linux both statis and shared library releases.
ntgcalls.h
and ntgcall.lib
files copied to examples/go/ntgcalls
directory
> $env:CGO_ENABLED=1; go build
# gotgcalls
C:\Program Files\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:/ProgramData/mingw64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lntgcalls: No such file or directory
collect2.exe: error: ld returned 1 exit status
ntgcalls.dll
, ntgcalls.h
, ntgcalls.lib
files copied to examples/go/ntgcalls
directory
> $env:CGO_ENABLED=1; go build
# gotgcalls
C:\Program Files\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:/ProgramData/mingw64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lntgcalls: No such file or directory
collect2.exe: error: ld returned 1 exit status
libntgcalls.so
and ntgcalls.h
files copied to examples/go/ntgcalls
directory
> CGO_ENABLED=1 go build
# gotgcalls
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: cannot find -lntgcalls
collect2: error: ld returned 1 exit status
libntgcalls.a
and ntgcalls.h
files copied to examples/go/ntgcalls
directory
> CGO_ENABLED=1 go build
# gotgcalls
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: cannot find -lntgcalls
collect2: error: ld returned 1 exit status
Obvious similarity. --library flag (-l for short) won't find library for some reason. Something wrong. Something is missing no matter the target platform. When trying to remove that flag since it lib name and wild assumption we could compile without setting lib name (maybe there is a default)
> CGO_ENABLED=1 go build
# gotgcalls
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: /tmp/go-link-2846990317/000021.o: in function `_cgo_dcb2bb26fc19_Cfunc_ntg_calls':
/tmp/go-build/cgo-gcc-prolog:59: undefined reference to `ntg_calls'
/usr/bin/ld: /tmp/go-link-2846990317/000021.o: in function `_cgo_dcb2bb26fc19_Cfunc_ntg_calls_count':
/tmp/go-build/cgo-gcc-prolog:81: undefined reference to `ntg_calls_count'
/usr/bin/ld: /tmp/go-link-2846990317/000021.o: in function `_cgo_dcb2bb26fc19_Cfunc_ntg_change_stream':
/tmp/go-build/cgo-gcc-prolog:104: undefined reference to `ntg_change_stream'
/usr/bin/ld: /tmp/go-link-2846990317/000021.o: in function `_cgo_dcb2bb26fc19_Cfunc_ntg_connect':
/tmp/go-build/cgo-gcc-prolog:127: undefined reference to `ntg_connect'
# ... bunch of other files
and pretty much the same thing for windows
> $env:CGO_ENABLED=1; go build
# gotgcalls
C:\Program Files\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:/ProgramData/mingw64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\takin\AppData\Local\Temp\go-link-126883592\000015.o: in function `_cgo_dcb2bb26fc19_Cfunc_ntg_calls':
/tmp/go-build/cgo-gcc-prolog:59: undefined reference to `__imp_ntg_calls'
C:/ProgramData/mingw64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\takin\AppData\Local\Temp\go-link-126883592\000015.o: in function `_cgo_dcb2bb26fc19_Cfunc_ntg_calls_count':
/tmp/go-build/cgo-gcc-prolog:81: undefined reference to `__imp_ntg_calls_count'
So lib name is essential and for now that's all my ideas
Could you please provide full context on how you build go example
env
Managed to build it!
ntgcalls.h
file into examples/go/ntgcalls
directoryntgcalls.dll
and ntgcalls.lib
to examples/go
directory $env:CGO_ENABLED=1; go build
or $env:CGO_ENABLED=1; go run .
Yes, however, I would appreciate it if you would open a PR with the build instructions for Go, for Linux the instructions are very similar
Added PR, please review: https://github.com/pytgcalls/ntgcalls/pull/25
@Laky-64 ping
pong
What the status of
./examples/go
? Is it buildable?Trying to build it with
CGO_ENABLED=1 go build
and only getting bunch of errorsWhat command should be used to build example?