d99kris / nchat

Terminal-based Telegram / WhatsApp client for Linux and macOS
MIT License
538 stars 41 forks source link

WhatsAppMd -- Segmentation fault (core dumped) #106

Closed 99702 closed 1 year ago

99702 commented 1 year ago

Description: I've compiled and try to run nchat --setup in fedora. It works for telegram while doesn't works for whatsapp option, as soon as i type 2 (whatsapp) option it throws error saying

Here is my log of nchat:

2023-05-30 08:13:15.687 | INFO  | starting nchat v3.59  (main.cpp:215)
2023-05-30 08:13:17.263 | DEBUG | init dir /home/kali/.nchat/profiles version 1  (fileutil.cpp:221)
2023-05-30 08:13:17.267 | ERROR | failed dlopen /usr/local/bin/../lib/libwmchat.so  (main.cpp:73)

Environment:

d99kris commented 1 year ago

Hi @99702 - thanks for reporting a bug. I cannot reproduce the problem on a fresh Fedora 38 installation using the following commands:

sudo dnf install git ccache file-devel file-libs gperf readline-devel golang sqlite-devel file-devel openssl-devel zlib-devel cmake make automake gcc gcc-c++
git clone https://github.com/d99kris/nchat && cd nchat
./make.sh build && ./make.sh install

Can I check what output you get if running the following?

file /usr/local/bin/../lib/libwmchat.so
ldd /usr/local/bin/../lib/libwmchat.so
file $(which nchat)

Another thing you could try is to disable dynamic loading of protocol plugins (such as WhatsApp) by editing CMakeLists.txt and changing line 53 from option(HAS_DYNAMICLOAD "Dynamic Load" ON) to option(HAS_DYNAMICLOAD "Dynamic Load" OFF) and then rebuild and see if it helps.

99702 commented 1 year ago

Hello, Thanks for helping.I installed libraries sudo dnf install git ccache file-devel file-libs gperf readline-devel golang sqlite-devel file-devel openssl-devel zlib-devel cmake make automake gcc gcc-c++ and tried to use option(HAS_DYNAMICLOAD "Dynamic Load" OFF) which crashed when compiling giving following output and didnt worked..

...
/usr/bin/ld: lib/libwmchat.so: undefined reference to `image_1color.Gray..d'
/usr/bin/ld: lib/libwmchat.so: undefined reference to `net_1http.Client..p'
/usr/bin/ld: lib/libwmchat.so: undefined reference to `runtime.mapaccess1__faststr'
/usr/bin/ld: lib/libwmchat.so: undefined reference to `internal_1bytealg..types'
/usr/bin/ld: lib/libwmchat.so: undefined reference to `runtime.mapaccess2'
/usr/bin/ld: lib/libwmchat.so: undefined reference to `path..types'
/usr/bin/ld: lib/libwmchat.so: undefined reference to `sort..types'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/nchat.dir/build.make:487: bin/nchat] Error 1
make[1]: *** [CMakeFiles/Makefile2:487: CMakeFiles/nchat.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
build failed, exiting.

Here is my output of following

d99kris commented 1 year ago

Hi @99702 - thanks for providing the info! It appears there's some problem with building the Go interfacing part. Can you please share the output of go version and also go env?

99702 commented 1 year ago

go version : go version go1.18 gccgo (GCC) 13.1.1 20230511 (Red Hat 13.1.1-2) linux/amd64

and go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/kali/.cache/go-build"
GOENV="/home/kali/.config/go/env"
GOEXE=""
GOEXPERIMENT="fieldtrack,regabiwrappers"
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/kali/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/kali/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/libexec/gcc/x86_64-redhat-linux/13"
GOVCS=""
GOVERSION="go1.18 gccgo (GCC) 13.1.1 20230511 (Red Hat 13.1.1-2)"
GCCGO="/usr/bin/gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/kali/Code/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1063314908=/tmp/go-build -gno-record-gcc-switches -funwind-tables"
d99kris commented 1 year ago

Thank you, this is very useful information 👍

I can now reproduce the problem on a fresh Fedora 38 system with the following commands:

dnf install gccgo
sudo dnf install git ccache file-devel file-libs gperf readline-devel golang sqlite-devel file-devel openssl-devel zlib-devel cmake make automake gcc gcc-c++
./make.sh build && ./make.sh install

It seems nchat whatsapp library compiled using gccgo fails to load / crashes.

You can work around the problem by selecting golang as your default go compiler:

sudo update-alternatives --config go

It will present a menu like:

There are 2 programs which provide 'go'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/bin/go.gcc
   2           /usr/lib/golang/bin/go

Proceed to select the number for golang / /usr/lib/golang/bin/go (in the above menu example it's number 2).

Before building nchat again, go to the folder with your local clone and remove any local changes:

git checkout .

and remove all build-generated files:

git clean -ffdx

Then build again:

./make.sh build

As for the actual root cause of the problem I am not sure yet, I might take a look at pinpointing it eventually (or at least have the build script warn if gccgo is the selected go compiler), but for now nchat only supports golang version of go.

d99kris commented 1 year ago

Support for gccgo has been added in the above commit, so you may disregard from the workaround mentioned in my previous comment above, and instead get latest nchat, and it should be able to build / work fine with gccgo as the default go compiler.

Please let me know if you still encounter any issues.

99702 commented 1 year ago

wow Great, Thank you alot @d99kris . It works now.