I need to build libldap under linux (and windows, but that's a different story).
When I do
./configure --prefix="$OPENLDAP_BUILD_PATH" --disable-slapd
make
make install
make clean
I get with ldd that libldap is linked with system libraries libssl.so and libcrypto.so. And what I need is to link it with my custom builds of this libraries.
I also tried this:
OPENLDAP2_BUILD_PATH="$BUILD_PATH/openldap2"
mkdir "$OPENLDAP2_BUILD_PATH"
OPENSSL_DEPENDENCY_PATH="$BUILD_PATH/openssl"
LD_LIBRARY_PATH="$OPENSSL_DEPENDENCY_PATH/lib:$LD_LIBRARY_PATH"
CPPFLAGS="-l$OPENSSL_DEPENDENCY_PATH/include/openssl"
LDFLAGS="-L$OPENSSL_DEPENDENCY_PATH/lib"
./configure --prefix="$OPENLDAP2_BUILD_PATH" --disable-slapd
make
make install
make clean
With no success either.
ldd libldap.so shows this:
linux-vdso.so.1 => (0x00007ffc91923000)
liblber-2.4.so.2 => /home/me/Work-U14/proj/shared/BUILD/openldap2/lib/liblber-2.4.so.2 (0x00007ff0ef638000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007ff0ef3f8000)
libssl.so.1.0.0 => /lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007ff0ef198000)
libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007ff0eedbc000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff0ee9f4000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff0ee7ef000)
/lib64/ld-linux-x86-64.so.2 (0x000056386adf5000)
Found that below could work:
export LDFLAGS="-L/your/dir/to/openssl/lib"
export CPPFLAGS="-I/your/dir/to/openssl/include"
./configure ...
could work, the include path is:
-I/your/dir/to/openssl/include NOT
-I/your/dir/to/openssl/include/openssl
which the .h head files are all in the sub openssl dir under include,
the key point is get rid of the openssl dir under include dir, which by default for other packages we have to add this sub-directory under include, e.g. for apr, you have to make it as: -I/your/dir/to/apr/include/apr-1.
It's not a good solution, but a well-enough workaround for me.
I've written build.sh as follows:
#!/bin/sh
if [ -z "$BUILD_PATH" ]
then
echo "Variable BUILD_PATH isn't specified!"
exit
fi
OPENLDAP2_BUILD_PATH="$BUILD_PATH/openldap2"
export MY_OPENSSL_ROOT="$BUILD_PATH/openssl"
./configure --prefix=$OPENLDAP2_BUILD_PATH --disable-slapd >/home/sherst/Desktop/configure_log.openldap2 2>&1
make >/home/sherst/Desktop/make_log.openldap2 2>&1
make install >/home/sherst/Desktop/make_install_log.openldap2 2>&1
I've patched configure file as such:
LINE 15485
LIBS="-Wl,-rpath=$ORIGIN/ -L. -lssl -lcrypto $LIBS"
LINE 15582
TLS_LIBS="-Wl,-rpath=$MY_OPENSSL_ROOT/lib -L$MY_OPENSSL_ROOT/lib -lssl -lcrypto -lRSAglue -lrsaref"
LINE 15584
TLS_LIBS="-Wl,-rpath=$MY_OPENSSL_ROOT/lib -L$MY_OPENSSL_ROOT/lib -lssl -lcrypto"
In such way (I'm quite sure that it's very crude and overabundant) I've achieved that ldd shows links to my openssl libs. TO hard code them is a bad idea, but when, in distro, there will be no such paths, I expect ld to find them in local dir, where we plan to put them.
openldap faq says this should be achieved ain such way:
env CPPFLAGS=-I/path/to/openssl/include \
LDFLAGS=-L/path/to/openssl/lib-dir \
configure --with-tls ...
But that didn't work for me (perhaps, I did it wrong).
I found info how to add rpath here:
https://www.openldap.org/doc/admin24/install.html
Simply pass it to configure script:
/configure --enable-wrappers \
CPPFLAGS="-I/usr/local/include" \
LDFLAGS="-L/usr/local/lib -Wl,-rpath,/usr/local/lib"
Related
So in my userspace program I am calling some functions like bpf_object__open_file which are part of libbpf library installed with PKG_CONFIG_PATH=/build/root/lib64/pkgconfig DESTDIR=/build/root make install
So when I compile the it compiles just fine, no error with this command
clang -L /build/root/usr/lib64/ -I /usr/include/ -Wall -o user u.c -lbpf
so these files exists in my /build/root/usr/lib64 directory
libbpf.a libbpf.so libbpf.so.0 libbpf.so.0.7.0 pkgconfig
But when I run the program like
sudo ./user
It throws message that
./user: error while loading shared libraries: libbpf.so.0: cannot open shared object file: No such file or directory
So basically I am creating shared library, giving the path but why running the program not able to find my libbpf.so.0 shared library
can anyone tell why is that the case I am getting message can't find library
As Qeole mentioned in comment
So I did this
root#/dir/# ldd ./user
and it gives me this output without any location where did it tried to find path directory
linux-vdso.so.1 (0x00007ffcd77e7000)
libbpf.so.0 => not found
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9b3943c000)
/lib64/ld-linux-x86-64.so.2 (0x00007f9b39642000)
You should add the libbpf library directory to your LD_LIBRARY_PATH variable.
$ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/build/root/usr/lib64
$ export LD_LIBRARY_PATH
Then go ahead an run the program. Note that if you run it with sudo, you may also need to set root's LD_LIBRARY_PATH
$ sudo su
# LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/build/root/usr/lib64
# export LD_LIBRARY_PATH
# ./user
You can verify that libbfp was found with the same ldd command.
After spending almost an hour on filtering output of
clang -v hello_world.c
I got the following linking command:
ld -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 \
/usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o \
hello_world.o /usr/lib/x86_64-linux-gnu/libc.so \
/usr/lib/x86_64-linux-gnu/crtn.o
Is there an easier way to find out that -lc will expand to /usr/lib/x86_64-linux-gnu/libc.so?
I need to know which files are used so I can copy them to another system for cross compiling.
edit
Looks like I should use the cross-compile toolchain. From clang docs:
https://clang.llvm.org/docs/CrossCompilation.html
When you have extracted your cross-compiler from a zip file into a
directory, you have to use --sysroot=. The path is the root
directory where you have unpacked your file, and Clang will look for
the directories bin, lib, include in there.
Where can I get that zip file they refer to? I'm interested in x86_64-linux-gnu target.
This will list all the files linked to libc.so.6:
for i in `find . -type f -executable`
do
j=$(ldd $i | grep libc.so.6 | wc -l)
if [ $j -gt 0 ]
then
echo $i
fi
done
In case you want to find out what the path of libc.so.6 is, stated in the original question something similar to:
ldd `which ld` | sed 's/^[[:space:]]libc.so.6[[:space:]]=>[[:space:]]\(.*\)[[:space:]](.*)/\1/p' | grep --color=never libc.so
will type the path, you can obviously replace the expression after ldd with any filename.
From the comments, there is a way with clang directly though it will generate a lot of noise which is significantly harder to exclude compared to the ldd way.
clang -Wl,--verbose hello_world.c
will tell the linker to be verbose and it will eventually tell you all the library paths tried for each library.
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.
This question already has answers here:
Build OpenSSL with RPATH?
(2 answers)
How to compile OpenSSL with relative rpath
(5 answers)
Closed 4 years ago.
I have different openssl versions on my system and I don't want to install the most current openssl version into the system location - e.q. /usr/bin/openssl.
Now, when I compile openssl then I get this running ldd:
root => ldd /FaF/openssl/bin/openssl
linux-vdso.so.1 (0x00007ffe60d92000)
--> libssl.so.1.1 => not found
--> libcrypto.so.1.1 => not found
libdl.so.2 => /lib64/libdl.so.2 (0x00007facf337b000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007facf315e000)
libc.so.6 => /lib64/libc.so.6 (0x00007facf2dbd000)
/lib64/ld-linux-x86-64.so.2 (0x00007facf357f000)
I refer to libssl.so.1.1 and libcrypto.so.1.1 which are not found and this is OK that far.
Running ldd with preceded LD_LIBRARY_PATH works:
root => LD_LIBRARY_PATH=/FaF/openssl/lib/ ldd /FaF/openssl/bin/openssl
linux-vdso.so.1 (0x00007fff221a1000)
libssl.so.1.1 => /FaF/openssl/lib/libssl.so.1.1 (0x00007f45f842a000)
libcrypto.so.1.1 => /FaF/openssl/lib/libcrypto.so.1.1 (0x00007f45f7f9a000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f45f7d96000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f45f7b79000)
libc.so.6 => /lib64/libc.so.6 (0x00007f45f77d8000)
/lib64/ld-linux-x86-64.so.2 (0x00007f45f869b000)
/FaF/openssl/lib is the directory where the correct libraries are.
I have now these possible solutions:
Adding /FaF/openssl/lib to /etc/ld.so.conf and running ldconfig - This is not really an option because it may break the system version of openssl.
As I did in the above example I can precede each time I need opensslwith LD_LIBRARY_PATH=/FaF/openssl/lib/ - not really a good option and it isn't always possible.
I can link the path with --rpath=/FaF/openssl/lib into openssl.
My question:
For the moment I didn't figure out how to set --rpath=/FaF/openssl/lib in the configure command which generates openssl. Can somebody provide me this information?
I tried setting LD_LIBRARY_PATH and LDFLAGS but nothing works.
I prefer a solution which is hard-coded into openssl so there are not other settings required.
OK. Here is the - very simple - way how to solve it according to 3) from my question.
I ran ./config -h and got this output:
root => ./config -h
Usage: config [options]
-d Build with debugging when possible.
-t Test mode, do not run the Configure perl script.
-v Verbose mode, show the exact Configure call that is being made.
-h This help.
Any other text will be passed to the Configure perl script.
See INSTALL for instructions.
Operating system: x86_64-whatever-linux2
Configuring for linux-x86_64
The text Any other text will be passed to the Configure perl script. says it all.
I just added the --rpath at the end to the config command which looks now like this:
./config --prefix=/FaF/openssl threads shared -Wl,--rpath=/FaF/openssl/lib
I have currently complied lighttpd from source
./configure --prefix=/home/lighttpd \
--without-pcre \
--without-zlib \
--without-bzip2
I also tried -enable-static --disable-shared option, but modules still loading from lib directory
I want to compile all lighttpd module in single binary instead of loading from lib directory, how to do that ?
Cross-posted to https://redmine.lighttpd.net/boards/3/topics/6615
Lighttpd can be built statically using SCons or using make. Briefly:
SCons:
$ scons -j 4 build_static=1 build_dynamic=0 prefix=/custom/inst/path install
make:
# edit src/Makefile.am and in the section under 'if LIGHTTPD_STATIC', update lighttpd_SOURCES with each module to be included in the static build or just use the entire list that is already there
$ LIGHTTPD_STATIC=yes ./configure -C --enable-static=yes
$ make
More details in https://redmine.lighttpd.net/boards/3/topics/5912
[edit] To build statically using 'make', use lighttpd git master branch or lighttpd 1.4.40+
Compile it with flag -DLIGHTTPD_STATIC. If gcc will warn you about syntax, force interpret gcc as the C99 standard:
make CFLAGS=-DLIGHTTPD_STATIC -std=c99
Also you must change src/Makefile.in which is generated by configure to add the modules you want to include. Specifically, add to am__liblightcomp_la_SOURCE_DIST, am__lighttpd_SOURCES_DIST and common_src:
mod_access.c mod_staticfile.c
And also add the objects.
To am__objects_1 and am__objects_2
mod_access.$(OBJEXT) mod_staticfile.$(OBJEXT)
if src/plugin-static.h file is not available, change src/plugin.c file, find line #include "plugin-static.h", coment it and add this below:
PLUGIN_INIT(mod_access)
PLUGIN_INIT(mod_staticfile)
The documentation of lighttpd explains that using build_static will only cause it to be statically linked with its own modules (mod_*.so files). It will still dynamically link external dependencies (those in /lib*/*).
If you were not mixing these up, regarding your experience of:
I also tried -enable-static --disable-shared option, but modules still loading from lib directory
And all you wanted was for these modules to be statically included in the lighttpd binary, then the other answers should be correct and valid.
However, if you want to have a single binary, so that there are no externally dynamic dependencies. Then you need to use both scons and replace build_static=1 with build_fullstatic=1. The Makefile setup doesn't have this option.
build_static=1
scons -j 4 build_static=1 build_dynamic=0
Using ldd to show which dynamic libraries it needs:
ldd sconsbuild/static/build/lighttpd
linux-vdso.so.1 (0x00007fff0478f000)
libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007f760191e000)
libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f76018e4000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f76016bc000)
/lib64/ld-linux-x86-64.so.2 (0x00007f7601a5a000)
PS: if you built a shared version, the mod_*.so files would still not show up here, as those are lazily loaded from within the execution of lighttpd, based on your config file.
build_fullstatic=1
scons -j 4 build_fullstatic=1 build_dynamic=0
ldd sconsbuild/fullstatic/build/lighttpd
not a dynamic executable
Which is what I assume you wanted to see.