How to Compile telegram-cli in windows by cygwin? - c

I have Installed the complete cygwin packages and I have done the steps mentioned in this guide Link
The guide is like this:
...
Then, go to tg directory then generate Makefile.
cd tg
./configure
We need to patch Makefile and loop.c to compile in cygwin. Download this patch then untar. Then, patch in tg directory.
patch -p1 < telegram-cli-cygwin.patch
Then make
After compile is done, telegram-cli.exe will be generated in bin directory.
To run telegram-cli, type
bin/telegram-cli -k tg-server.pub
Caution: A binary compiled with Cygwin should be run in Cygwin Terminal.
I have done the all the steps successfully but when I patch the make file and the loop.c it says:
$ patch -p1 < telegram-cli-cygwin.patch
patching file Makefile
Hunk #1 succeeded at 4 with fuzz 2.
patching file loop.c
Hunk #1 FAILED at 383.
Hunk #2 succeeded at 739 with fuzz 2 (offset 105 lines).
1 out of 2 hunks FAILED -- saving rejects to file loop.c.rej
And for the next step when it says 'Then make' I have tried using the command "./configure" I dont know if I am doing this right?
And after executing the command:
bin/telegram-cli -k tg-server.pub
It says :
$ bin/telegram-cli -k tg-server.pub
-bash: bin/telegram-cli: No such file or directory
And It is right because there is no exe file created to be run. I would appreciate Any help.

I applied the patches manually after configure as #kaylum mentioned. It has to be after the configure command because the make file has to patched too and the configure command affects the make file. after that the make or make all command has to executed and the .exe file is created.

Related

Having trouble using the mingw32-make command to build json-c library

Here is the instructions: https://github.com/json-c/json-c/blob/master/README.md#build-instructions--
This is the first time I've ever built from source.
I'm on Windows 10 and I used CMake to build.
I did this and it all worked fine:
$ git clone https://github.com/json-c/json-c.git
$ mkdir json-c-build
$ cd json-c-build
$ cmake ../json-c
But I don't understand this part:
$ make
$ make test
$ make USE_VALGRIND=0 test # optionally skip using valgrind
$ make install
Can someone explain to me what these lines do?
I installed mingw32-make but when I run mingw32-make on its own like in the this tutorial it just says:
mingw32-make: *** No targets specified and no makefile found. Stop.
Do I need to create a Makefile? It doesn't say anywhere in the installation notes to do this but I cannot get past this step, what am I doing wrong?

How to compile nanopb .proto file into .h and .c files using nanopb and protobuf (`protoc` compile question)

Old title: How to compile nanopb/examples/simple/simple.proto file into simple.h and simple.c using nanopb and protobuf
Regarding this library: https://github.com/nanopb/nanopb
My goal is to follow this tutorial: https://jpa.kapsi.fi/nanopb/docs/concepts.html to convert nanopb/examples/simple/simple.proto into a .h and .c source file. I need simple instructions to do this on Ubuntu. I've been attempting it for days and am unable to get it to work.
The commands the tutorial says to do are:
protoc -omessage.pb message.proto
python ../generator/nanopb_generator.py message.pb
I cloned the nanopb repo, cd'ed into nanopb/examples/simple, and then substituting in simple.proto instead of message.proto in the commands above, I ran the following:
protoc -osimple.pb simple.proto
It worked fine, producing a simple.pb file.
The 2nd part, however, fails. When running from inside the nanopb/examples/simple folder, I get:
$ python ../../generator/nanopb_generator.py simple.pb
********************************************************************
*** Failed to import the protocol definitions for generator. ***
*** You have to run 'make' in the nanopb/generator/proto folder. ***
********************************************************************
Traceback (most recent call last):
File "../../generator/nanopb_generator.py", line 39, in <module>
import proto.nanopb_pb2 as nanopb_pb2
File "/home/gabriels/GS/dev/Protocol_Buffers/Nanopb/source/nanopb/generator/proto/nanopb_pb2.py", line 11, in <module>
from google.protobuf import symbol_database as _symbol_database
ImportError: cannot import name symbol_database
Running make does nothing (says it's already done):
nanopb/generator/proto $ make
make: Nothing to be done for `all'.
Note that I am running the latest version of protoc, built from the Google protobuf repo from source: https://github.com/protocolbuffers/protobuf.
I have also sought help from nanopb here, but am unable to figure it out, and feel like there's something basic here I'm missing because I just don't know enough: https://github.com/nanopb/nanopb/issues/417. Feels like I'm beating my head into the wall on something that should be simple and has already been done by at least 1448+ people before me (the number of stars on nanopb).
Solved. #PetteriAimonen had given me the missing clue:
the protoc version needs to match with the python library version
Then it occurred to me: originally, when compiling protobuf from scratch, I followed only the C++ installation instructions, as shown here: https://github.com/protocolbuffers/protobuf/tree/master/src. But, what if I follow the Python installation instructions too? https://github.com/protocolbuffers/protobuf/tree/master/python
So, that's what I did.
TLDR; Do the Python installation of the protobuf library too (not just the C++ installation):
Protobuf Python installation steps I followed:
python -V # See if I have Python 2.7 or newer (I must to continue)
cd protobuf/python # cd into Python source directory
python setup.py build
python setup.py test
(cd .. && make)
(cd .. && sudo make install)
python setup.py build --cpp_implementation
python setup.py test --cpp_implementation # look to see all tests pass
sudo python setup.py install
Two-step compile of .proto files:
That all worked, so now lets go back and try compiling our simple.proto file again.
cd into nanopb/examples/simple. We already ran the first command to produce the simple.pb file, so now just run the 2nd command that previously would fail, and it works!
2nd Command only:
nanopb/examples/simple $ python ../../generator/nanopb_generator.py simple.pb
Output:
nanopb/examples/simple $ python ../../generator/nanopb_generator.py simple.pb
Writing to simple.pb.h and simple.pb.c
2-commands shown together again for completeness:
protoc -osimple.pb simple.proto
nanopb/examples/simple $ python ../../generator/nanopb_generator.py simple.pb
Beautiful! IT WORKED! simple.pb.h and simple.pb.c are now created!
Now build the "simple" project:
make
And run it:
./simple
And the output is:
nanopb/examples/simple $ ./simple
Your lucky number was 13!
Now I can study the project to see how simple.proto was turned into simple.pb.h and simple.pb.c, and I can study simple.c (which contains the main() function) to see a full usage of these auto-generated .h and .c files, including looking at the following header files which it includes:
#include <pb_encode.h> # found up 2 levels, in "nanopb" folder
#include <pb_decode.h> # found up 2 levels, in "nanopb" folder
#include "simple.pb.h" # just generated right here in "nanopb/examples/simple" folder
One-line command to build .proto files:
Instead of doing the two-line command to build .proto files:
# From inside folder "/home/gabriels/GS/dev/Protocol_Buffers/Nanopb/source/nanopb/examples/simple":
protoc -osimple.pb simple.proto
python ../../generator/nanopb_generator.py simple.pb
we can do a one-line command to build .proto files which just uses the protoc executable plus the protoc-gen-nanopb plugin:
protoc --plugin=protoc-gen-nanopb=/home/gabriels/GS/dev/Protocol_Buffers/Nanopb/source/nanopb/generator/protoc-gen-nanopb --nanopb_out=. simple.proto
And then, of course, we still need to make and run the main C project:
# From inside folder "/home/gabriels/GS/dev/Protocol_Buffers/Nanopb/source/nanopb/examples/simple":
make && ./simple

How to link the Valgrind 3.11.0 in my MacBook Pro (El Capitan)?

First of all, my Mac OS version is 10.11.3 (El Capitan).
So, I am learning c through http://c.learncodethehardway.org/book/. It's a tutorial by Zed A. Shaw. On that tutorial, he asked the reader to instal the Valgrind. The steps are as below:
# 1) Download it (use wget if you don't have curl)
curl -O http://valgrind.org/downloads/valgrind-3.6.1.tar.bz2
# use md5sum to make sure it matches the one on the site
md5sum valgrind-3.6.1.tar.bz2
# 2) Unpack it.
tar -xjvf valgrind-3.6.1.tar.bz2
# cd into the newly created directory
cd valgrind-3.6.1
# 3) configure it
./configure
# 4) make it
make
# 5) install it (need root)
sudo make install
So, I did as above and got stuck at step 4. If I am not mistaken, the command line said no target to be make (something like that). I'm realised then that it is not the latest version of Valgrind, so by using exactly the above steps, I've managed to install the latest one. I managed to go until step 5 although sometimes there are some negative messages from the command line during installation.
The problem is, whenever I enter valgrind, the command prints -bash: valgrind: command not found. Then through brew doctor, this message is printed:
Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
valgrind
When I type brew link valgrind, this message is printed out:
Linking /usr/local/Cellar/valgrind/3.11.0...
Error: Could not symlink include/valgrind/callgrind.h
/usr/local/include/valgrind is not writable.
I even tried brew install --HEAD valgrind and this message is printed out:
Warning: valgrind-3.11.0 already installed, it's just not linked
What is happening? How can I fix this? Is this thing happened because of my mistake in trying to install an outdated Valgrind before by using the make command (although the make command cannot be executed at that time if I remember correctly)?

Can't analyse the output (the profile file) of gperftools profiler

I'm using gperftools for analysing my C code. An as a result I can't analyze the profile file using pprof application.
$ gcc -g prog.c -o prog -lprofiler
$ export CPUPROFILE=info.prof
$ ./prog
Inside main()
Inside func1
Inside new_func1()
Inside func2
PROFILE: interrupts/evictions/bytes = 1133/0/300
$ ls
info.prof prog prog.c
$ ls -lah info.prof
-rw-rw-r-- 1 mm mm 2.6K Jun 6 09:36 info.prof
$ pprof info.prof prog
Reading Profile files in profile.*
Error: Could not open profile.0.0.0: No such file or directory
profile.ftab: No such file or directory
$
What do I wrong? What's the profile.ftab file?
You're not using the correct 'pprof' tool. In particular, you're using http://www.cs.uoregon.edu/research/tau/docs/newguide/bk03ch01s08.html (which is totally unrelated), whereas you need the one here: https://code.google.com/p/gperftools/ I had the same issue and solved the problem by downloading the gperftools' source, building it, and using ./src/pprof
I just ran into this and I think it is worth mentioning how to deal with this in recent versions of Ubuntu (18.04 specifically).
When one tries to run the pprof command, the system suggests installing the tau package:
Command 'pprof' not found, but can be installed with:
sudo apt install tau
Do not install that package though, because it is entirely unrelated as David Carney pointed out in his answer. Install the google-perftools package instead, but be aware that the executable in it is called google-pprof instead of just pprof.
You installed the wrong pprof.
If you already have golang installed. You can install pprof using go.
Just do,
go get github.com/google/pprof
Also install graphviz if you want to generate PDFs using
sudo apt-get install graphviz

Issue Statically Compiling Thrift 0.9.0 on Centos 6.5

I'm working to compile the Thrift 0.9.0 binary statically in a CentOS VM. I get the issue that the libthrift.a binary is not being created. I am using a vagrant box to run centos:
https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box
Once I ssh to the vagrant box I run the following commands:
wget https://archive.apache.org/dist/thrift/0.9.0/thrift-0.9.0.tar.gz
tar -zxvf thrift-0.9.0.tar.gz
cd thrift-0.9.0
./configure --enable-static
make
This will run but I ran a find command (sudo find / -name "*.a") on the system to see if there was any ".a" files made and the only file that was made was "libparse.a" which doesn't seem right. From my understanding it should be "libthrift.a".
Searching through the config.log file it says that it does want to build the static libraries:
configure:11944: checking whether to build static libraries
configure:11948: result: yes
Looking at more locations in the log file that has the keyword "static" reveals potential places that may be errors.
configure:9028: checking if gcc static flag -static works
configure:9056: result: no
configure:13915: checking if g++ static flag -static works
configure:13943: result: no
lt_cv_prog_compiler_static_works=no
lt_cv_prog_compiler_static_works_CXX=no
The full log file is here: http://www.filehosting.org/file/details/449460/staticThriftErrorLog.rtf
Any help is appreciated
I was able to generate the libthrift.a file. After running the command for the extra dependancies mentioned in my comment I forgot to run the make command. So after doing the make command I found the libthrift.a file in "thrift-0.9.0/lib/cpp/.libs/". Interestingly enough, even after fixing the dependencies, config.log still had the same potential problem areas regarding the gcc/g++ static flag and static compiler.
Specifically the dependency command is as follows:
sudo yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel openssl-devel.x86_64
Edit: After getting advice on the Jira ticket, it turns out the specific vagrant box I was using was causing the errors. Using the VM he linked I was able to successfully build Thrift using the provided instructions. (Jira ticket https://issues.apache.org/jira/browse/THRIFT-2559)

Resources