Comments (7)
I have a full tdlib-tdjson binding package here (Autogenerated all types/methods from tdlib.tl) : https://github.com/Arman92/go-tdlib
from td.
We haven't tested static linking of the libtdjson_static library to Golang code, but it looks like Golang (using cgo) supports static linking of ะก libraries and everything should work fine. You will also need to statically link all TDLib dependencies, namely ilibtdactor, libtddb, libtdnet, libtdsqlite, libtdutils, libcrypto, libssl, libz and standard C++ library (libc++/libstdc++). What errors do you get?
from td.
@levlam seems like the libs order is the key. After researching CMakeLists.txt
I recover the right order:
/*
#cgo LDFLAGS: -ltdjson_static -ltdjson_private -ltdclient -ltdcore -ltdactor -ltddb -ltdsqlite -ltdnet -ltdutils -lstdc++ -lssl -lcrypto -ldl -lz -lm
#include <stdlib.h>
#include <td/telegram/td_json_client.h>
#include <td/telegram/td_log.h>
*/
import "C"
After this I compiled the binary, but with few warnings:
//usr/local/lib/libtdsqlite.a(sqlite3.c.o): In function `unixDlOpen':
sqlite3.c:(.text+0x15b17): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
//usr/local/lib/libtdutils.a(IPAddress.cpp.o): In function `td::IPAddress::init_host_port(td::CSlice, td::CSlice)':
IPAddress.cpp:(.text._ZN2td9IPAddress14init_host_portENS_6CSliceES1_+0x244): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
Because of it seems like Go static builds linked with glibc
are not working:
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x0]
runtime stack:
runtime.throw(0x1b4c034, 0x2a)
/usr/lib/go-1.9/src/runtime/panic.go:605 +0x95
runtime.sigpanic()
/usr/lib/go-1.9/src/runtime/signal_unix.go:351 +0x2b8
goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x4cb380, 0xc42005bde0, 0xc42005be01)
/usr/lib/go-1.9/src/runtime/cgocall.go:132 +0xe4 fp=0xc42005bdb0 sp=0xc42005bd70 pc=0x4027b4
github.com/L11R/go-tdjson._Cfunc_td_json_client_create(0x0)
github.com/L11R/go-tdjson/_obj/_cgo_gotypes.go:92 +0x4a fp=0xc42005bde0 sp=0xc42005bdb0 pc=0x4c7cea
github.com/L11R/go-tdjson.NewClient(0x1b45955)
/home/savely/go/src/github.com/L11R/go-tdjson/tdjson.go:37 +0x40 fp=0xc42005be48 sp=0xc42005bde0 pc=0x4c8050
main.main()
/home/savely/go/src/Aggregator/main.go:29 +0xb6 fp=0xc42005bf80 sp=0xc42005be48 pc=0x4cab66
runtime.main()
/usr/lib/go-1.9/src/runtime/proc.go:195 +0x226 fp=0xc42005bfe0 sp=0xc42005bf80 pc=0x42afb6
runtime.goexit()
/usr/lib/go-1.9/src/runtime/asm_amd64.s:2337 +0x1 fp=0xc42005bfe8 sp=0xc42005bfe0 pc=0x456cd1
goroutine 5 [syscall]:
os/signal.signal_recv(0x0)
/usr/lib/go-1.9/src/runtime/sigqueue.go:131 +0xa6
os/signal.loop()
/usr/lib/go-1.9/src/os/signal/signal_unix.go:22 +0x22
created by os/signal.init.0
/usr/lib/go-1.9/src/os/signal/signal_unix.go:28 +0x41
Article with very similar problem:
https://tschottdorf.github.io/golang-static-linking-bug
To finalize:
go build -a -ldflags '-linkmode external -extldflags -static'
-- not working, so we can't build TOTALLY static build.
go build
-- working. We can launch it on the machines without TDlib, but have to install libs like libz
, etc. It is quite acceptable.
from td.
I have a few suggestions for you:
- You can try to manually remove calls to some glibc functions that can't be linked statically.
In order to remove call to dlopen in sqlite, just add to sqlite/CMakeFiles.txt
target_compile_definitions(tdsqlite PRIVATE -DSQLITE_OMIT_LOAD_EXTENSION)
In order to remove call to getaddrinfo, replace function in tdutils/td/utils/port/IPAddress.cpp with
Status IPAddress::init_host_port(CSlice host, CSlice port) {
return Status::Error("Unsupported");
}
There is no critical functionality in TDLib which depends on that function, it should work fine. - As noted in the linked by you article, you can try to use another libc, for example, musl.
from td.
@levlam thanks for suggestions!
- I tried first one, two warnings were disappear, but appeared another one ๐ข
/usr/lib/x86_64-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
(.text+0x11): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
- If I understood correctly, I should compile TDLib with musl, but I got many errors, like:
/home/savely/td/sqlite/sqlite/sqlite3.c:20258:26: fatal error: openssl/rand.h: No such file
I tried to add-I/usr/include
atsqlite/CMakeLists.txt
, but then got another errors, tried to solve them, but they appearing "avalanche-like".
from td.
- This comes from OpenSSL now. You could try to build OpenSSL from sources with
no-dso
configure option, which should remove calls to dlopen. - You probably also need to recompile OpenSSL and zlib with musl and specify musl-compiled libraries as dependencies when building TDLib, It doesn't sounds like an easy way.
from td.
@levlam thanks for advices. For me easier to link statically against TDLib only. Other libs like OpenSSL, ZLib and others is simpler to install on target system from package manager.
For readers:
Set right flags for CGO:
/*
#cgo LDFLAGS: -ltdjson_static -ltdjson_private -ltdclient -ltdcore -ltdactor -ltddb -ltdsqlite -ltdnet -ltdutils -lstdc++ -lssl -lcrypto -ldl -lz -lm
#include <stdlib.h>
#include <td/telegram/td_json_client.h>
#include <td/telegram/td_log.h>
*/
import "C"
Compile dynamic binary with default command:
go build
Now your binary will depends only from libs like OpenSSL and zLib.
from td.
Related Issues (20)
- How to understand that this is a link to a bot? HOT 2
- Share phone number with bot HOT 2
- Separate message_ids in the same post HOT 3
- PHP code fails to compile: `Unsupported tl-schema version -1` HOT 10
- Unknown error in class "messageReplyToMessage" HOT 1
- "Request is empty" on authorization in Ubuntu HOT 4
- How do I launch the bot correctly? HOT 2
- Can someone show the references of the SetAuthenticationPhoneNumber() function HOT 3
- Telegram
- I need to build libtdjsonandroid to work on android using Unity (C#) HOT 1
- GetSupergroup return error "400 Invalid supergroup identifier" HOT 1
- Why I cannot create this json format to send text? HOT 8
- user-bot rate limit HOT 6
- Isn't there an instant way to change the hint password? HOT 3
- How to buy/subscribe to Telegram Business/Premium on Test DC? HOT 2
- Problem with secret messaging in Telegram X HOT 3
- Exclude x86 libs from android build? HOT 1
- When send voicenote with own client official desktop telegram shows it strange HOT 8
- [static const] please write code that complies with the C++ standard HOT 5
- How often does TDLib phone back to server to decide on the connection state? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from td.