How i can static build GDB from source? - c

I've download gdb-6.5.bz2.tar. Untar this file.
I write:
LDFLAGS=-static
./configure
but as a result i get a gdb, which require a so files, for instance: ncurses.so.5 libc.so.0 etc
How i can build statically ?

This message seems to imply that the correct usage is
$ make LDFLAGS=-static
Which seems surprising. Unfortunately, it also says it fails to build, and there are no follow-ups. Still the message is from 1999 so everything might have changed, perhaps the proper way today is to do it your way.

You can use the following options for configure script to generate a static GDB executable:
./configure --prefix=<> --enable-static=yes && make && make install

Both gcc and gdb disrespect the --enable-static flag which should be passed to configure, the correct way to do this is:
In the case of gdb 8.0, you have to also add the --disable-interprocess-agent to successfully build a static version:
mkdir build-gdb && cd build-gdb && ../configure --prefix=... --enable-static --disable-interprocess-agent ...
In the case of gcc 7.1, you have to also add the --disable-libcc1 to successfully build a static version:
mkdir build-gcc && cd guild-gcc && ../configure --prefix=... --enable-static --disable-shared --disable-libcc1 ...

Related

How to static compile ps(procps)

For forensic reason I want to compile some basic tool on Centos like cat,grep,vi,find,md5sum,dir..etc.It's very important to check the process list when we do forensic.so I try to compile ps(procps) statically.and I do failed.
here are the steps I tried:
git clone https://gitlab.com/procps-ng/procps.git
cd procps
./autogen.sh
./configure LDFLAGS="-static"
make SHARED=0 CC='gcc -static'
also googled so many posts and tried:
./configure LDFLAGS="-all-static"
./configure --enable-static --disable-shared
make SHARED=0 CC='gcc -static'
make -e LDFLAGS=-all-static
export LDFLAGS="-static -Wl,--no-export-dynamic"
make -e LDFLAGS=-all-static
make sense CC="gcc -static"
and combination of these configuration with make,none of this working,some compile failed and some success,but when I check it with ldd pscommands,it showed
[root#localhost ps]# ldd pscommand
linux-vdso.so.1 => (0x00007ffca9bc2000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f3b078cd000)
libc.so.6 => /lib64/libc.so.6 (0x00007f3b07500000)
/lib64/ld-linux-x86-64.so.2 (0x00007f3b07ad1000)
Is procps has some deep dependent on these non static libary?
Just compiled for procps-ng-3.3.16 (the latest now), try :
./configure \
--disable-shared \
LDFLAGS=--static
You may need to install glibc-static.

macOS: library not found for -lpaho-mqtt3c

What I have done:
git clone https://github.com/eclipse/paho.mqtt.c
cd paho.mqtt.c
make
sudo make install
Then, I tried compiling a simple C program that includes the MQTT C library like this:
#include <MQTTClient.h>
The command I used was:
$ gcc -o mqttTest mqttTest.c -lpaho-mqtt3c
What I got was ...
... even though the libraries are clearly present in /usr/local/lib:
What do I need to do to compile my code?
I already tried adding -L/usr/local/lib to the compile command, to no avail.
I found the answer on GitHub. See VilleViktor's post here: https://github.com/eclipse/paho.mqtt.cpp/issues/150
All I had to do was:
$ mv /usr/local/lib/libpaho-mqtt3a.so.1.0 /usr/local/lib/libpaho-mqtt3a.so.1
$ mv /usr/local/lib/libpaho-mqtt3as.so.1.0 /usr/local/lib/libpaho-mqtt3as.so.1
$ mv /usr/local/lib/libpaho-mqtt3c.so.1.0 /usr/local/lib/libpaho-mqtt3c.so.1
$ mv /usr/local/lib/libpaho-mqtt3cs.so.1.0 /usr/local/lib/libpaho-mqtt3cs.so.1
Maybe that saves someone else a lot of time on Google ...

Using readline statically in C (compilation and linkage)

I would like to link readline statically with my program and I found this page about readline compilation from source http://www.bioinf.org.uk/software/profit/doc/node17.html but I'm a bit confused about the process.
The page talks about a variable READLINELIB in the makefile but I don't find it.
Could someone show me the way to use readline statically in my program, what to put in my Makefile for compiling readline from source and link it with my program?
Thank you.
Finally I figured out the proper way to do it, I using the --prefix option of the configure file I can tell where to put/install the library. The problem about installation was that I don't have the right to access other directories than my $HOME, so no problem doing this:
configure --prefix=$HOME/libreadline && make && make install-static
Then in my program I include the file from $HOME/libreadline/include.
To compile the main program I link the program with the archive libraries $HOME/libreadline/lib/libreadline.a and $HOME/libreadline/lib/libhistory.a.
Also since readline files uses directive like #include <readline/readline.h> which doesn't correspond to the location of the files, I must tell the compiler where to look for included files. To do this, before running gcc, I set the variable C_INCLUDE_PATH to $HOME/libreadline/include.
Finally, since readline uses ncurses dynamic library I must tell the compiler to dynamically link it with my program. It might be the case of termcap too...
The overall process looks like:
configure --prefix=$HOME/libreadline && make && make install-static
export C_INCLUDE_PATH=$HOME/libreadline/include
gcc -o myprogram myprogram.c $HOME/libreadline/lib/libreadline.a $HOME/libreadline/libhistory.a -lncurses -ltermcap
I was confused about what make install do, it only copy files to the location provided by the configure, by default it installs in system directories like /usr/include, etc... but providing the --prefix option make install will copy all files in the specified directory.
Installation is just copying compiled program, libraries, doc, etc to a certain location, by default standart system directories, if you don't have access to those directories like me you could "install" it in your own directory and then do whatever you wan't with it.
I could have installed the dynamic library instead the static one, but then I would have to modify the LD_LIBRARY_PATH environment.
get readline source
wget http://git.savannah.gnu.org/cgit/readline.git/snapshot/readline-master.tar.gz
tar zxvf readline-master.tar.gz
cd readline-master/
examples folder does not have Makefile, which is generated using Makefile.in script.
following steps build static & dynamic libs & puts them inside /usr/local/bin
./configure
make
sudo make install
may have to install curses as "sudo apt-get install libncurses5-dev"
Use following make file (strip down version from examples folder)
(Make sure tab is honored otherwise makefile will not work)
RM = rm -f
CC = gcc
CFLAGS = -g -O
INCLUDES = -I/usr/local/include
LDFLAGS = -g -L/usr/local/lib
READLINE_LIB = -lreadline
TERMCAP_LIB = -ltermcap
.c.o:
${RM} $#
$(CC) $(CFLAGS) $(INCLUDES) -c $<
SOURCES = rlversion.c
EXECUTABLES = rlversion
OBJECTS = rlversion.o
all: $(EXECUTABLES)
everything: all
rlversion: rlversion.o
$(CC) $(LDFLAGS) -o $# rlversion.o $(READLINE_LIB) $(TERMCAP_LIB)
clean mostlyclean:
$(RM) $(OBJECTS) $(OTHEROBJ)
$(RM) $(EXECUTABLES)
rlversion.o: rlversion.c
I was in need of libraries libreadline.a, libhistory.a for both 64 and 32 bit versions.
The answer provided by Rajeev Kumar worked for me. ( Had a little trouble finding and installing libncurses).
For 32-bit versions, using https://packages.ubuntu.com/search?keywords=lib32readline-dev, the following command worked for me.
sudo apt install lib32readline-dev
So it is hoped that for 64 also, it works
sudo apt install libreadline-dev

Build Jansson 2.7 failed if I copy the directory elsewhere

I'm using Jansson 2.7 for my project. I found something that causes a build failed.
If I try:
tar -zxvf jansson-2.7.tar.gz
cd jansson-2.7/
./configure
make
Everything is just fine. But If I try:
tar -zxvf jansson-2.7.tar.gz
cp jansson-2.7 jansson-2.7-test -r
cd jansson-2.7-test/
./configure
make
Configure will success, but make will fail:
make
CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/bash /home/nick/Downloads/jansson-2.7-test/missing aclocal-1.14
/home/nick/Downloads/jansson-2.7-test/missing: line 81: aclocal-1.14: command not found
WARNING: 'aclocal-1.14' is missing on your system.
You should only need it if you modified 'acinclude.m4' or
'configure.ac' or m4 files included by 'configure.ac'.
The 'aclocal' program is part of the GNU Automake package:
<http://www.gnu.org/software/automake>
It also requires GNU Autoconf, GNU m4 and Perl in order to run:
<http://www.gnu.org/software/autoconf>
<http://www.gnu.org/software/m4/>
<http://www.perl.org/>
make: *** [aclocal.m4] Error 127
Any clues? Thanks!
I ran into this same issue simply extracting and trying to run configure/make. Following the link provided by nick2100, I found the following commands fixed the problem:
./configure
make AUTOCONF=: AUTOHEADER=: AUTOMAKE=: ACLOCAL=:
make AUTOCONF=: AUTOHEADER=: AUTOMAKE=: ACLOCAL=: install

How to modify code for s_client?

I'm playing around with apps/s_client.c in the openssl source code. I want to make a few changes and run it, but my changes are not getting reflected after I save the file and do a make all, or a make.
For example, I changed the sc_usage function to this:
BIO_printf(bio_err,"This is how you use s_client\n");
BIO_printf(bio_err,"usage: s_client args\n");
BIO_printf(bio_err,"\n");
BIO_printf(bio_err," -host host - use -connect instead\n");
BIO_printf(bio_err," -port port - use -connect instead\n");
I then save and do a make all in the apps folder, but when I run the program by doing this: openssl s_client abc, I don't see the line I introduced, this is how you use s_client, in the output.
Where am I going wrong?
I want to make a few changes and run it, but my changes are not getting reflected after I save the file and do a make all, or a make.
Its even easier than that once you know the tricks.
Configure the OpenSSL library as normal (configure)
Build the OpenSSL library as normal (make depend && make)
Install the OpenSSL library as normal (sudo make install)
Make your changes to s_client.c
Compile s_client.c in place (the apps/ directory):
Here's the grease. You have to build some additional object files, like apps.o and apps_rand.o, to support s_client.o.
export OPENSSLDIR=/usr/local/ssl/darwin
gcc -DOPENSSL_NO_PSK -DMONOLITH -I$OPENSSLDIR/include -I../ -c apps.c
gcc -DOPENSSL_NO_PSK -DMONOLITH -I$OPENSSLDIR/include -I../ -c app_rand.c
gcc -DOPENSSL_NO_PSK -DMONOLITH -I$OPENSSLDIR/include -I../ -c s_cb.c
gcc -DOPENSSL_NO_PSK -DMONOLITH -I$OPENSSLDIR/include -I../ -c s_socket.c
gcc -DOPENSSL_NO_PSK -I$OPENSSLDIR/include -I../ \
app_rand.o apps.o s_cb.o s_socket.o \
$OPENSSLDIR/lib/libssl.a $OPENSSLDIR/lib/libcrypto.a \
s_client.c -o my_s_client.exe
The OPENSSL_NO_PSK is needed because a declaration (psk_key) was commented out. The -I../ is needed because e_os.h is not installed after a make install. It sure would be nice if OpenSSL actually tested their stuff before releasing it...
Then:
$ ./my_s_client.exe -connect www.google.com:443
CONNECTED(00000003)
depth=2 C = US, O = GeoTrust Inc., CN = GeoTrust Global CA
verify error:num=20:unable to get local issuer certificate
verify return:0
---
Certificate chain
0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=www.google.com
i:/C=US/O=Google Inc/CN=Google Internet Authority G2
...
No need to rebuild the whole library or all the apps. No need for openssl s_client ....
Are you sure you run the correct app? Try ./openssl.
In Linux, current directory is not searched for executable files by default, so you are probably running system's openssl.

Resources