pytgcalls / ntgcalls

A Native Implementation of Telegram Calls in a seamless way.
https://pytgcalls.github.io
GNU Lesser General Public License v3.0
49 stars 10 forks source link

Go Example build instruction is missing #24

Closed eugeny-dementev closed 6 days ago

eugeny-dementev commented 2 months ago

What the status of ./examples/go? Is it buildable?

Trying to build it with CGO_ENABLED=1 go build and only getting bunch of errors

What command should be used to build example?

Laky-64 commented 2 months ago

Yeah, is buildable, have you added the ".so"/".dll" file + header?

eugeny-dementev commented 2 months ago

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?

eugeny-dementev commented 2 months ago

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)
Laky-64 commented 2 months ago

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

eugeny-dementev commented 2 months ago

I've tried on windows and linux and pretty much having the same result

On windows and linux both statis and shared library releases.

Windows static

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

Windows shared

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

Linux shared

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

Linus static library

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

Remove -lntgcalls

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

eugeny-dementev commented 2 months ago

Could you please provide full context on how you build go example

eugeny-dementev commented 2 months ago

Managed to build it!

Solution for windows

Laky-64 commented 2 months ago

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

null-nick commented 2 months ago

@eugeny-dementev for MacOs Arm64

// #cgo LDFLAGS: -L . -lntgcalls

https://batbin.me/unarrayed

eugeny-dementev commented 2 months ago

Added PR, please review: https://github.com/pytgcalls/ntgcalls/pull/25

eugeny-dementev commented 2 months ago

@Laky-64 ping

SantiiRepair commented 1 week ago

pong