I am trying to statically link zstd library(I have libzstd.a or libzstd.so) to my shared library libtest.so. The idea is that when deploying libtest.so in our application, we don't have to depend on libzstd.a or libzstd.so any more, so we have to statically link the zstd library.
I tried these:
cc -fPIC -Wl,-soname=libtest.so -static-libgcc -shared -o libtest.so myobjects.o -ldl -lc -L/path/to/libzstd -l:libzstd.a
cc -fPIC -Wl,-soname=libtest.so -static-libgcc -shared -o libtest.so myobjects.o -ldl -lc -Wl,-Bstatic -L/path/to/libzstd -l:libzstd.a
cc -fPIC -Wl,-soname=libtest.so -static-libgcc -shared -o libtest.so myobjects.o -ldl -lc /path/to/libzstd/libzstd.a
But they're all giving me this error:
/bin/ld: /path/to/libzstd/libzstd.a(zstd_common.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object;
recompile with -fPIC
/path/to/libzstd/libzstd.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make: *** [libtest.so] Error 1
What are the problem here? Thank you!
All object files that are linked into a shared library must be compiled
as Position Independent Code (compiler option -fPIC).
The linker error:
/bin/ld: /path/to/libzstd/libzstd.a(zstd_common.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object;
recompile with -fPIC
is telling you that the linkage of the shared library libtest.so needs the object file zstd_common.o from the
archive libzstd.a, but that object file was not compiled with -fPIC.
So you must rebuild libzstd.a from source, this time compiling the object
files that it contains with -fPIC.
Related
I have a set of cross compiled dynamic libraries generated. While trying to link it, I am getting the following error:
arm-linux-ld: xxx.so: undefined reference to symbol '__aeabi_uldivmod##GCC_3.5'
Does anybody have any idea what I am missing?
Below is the libraries I am linking and the order of linking:
some user defined libraries + -lcrypto -lssl -lz -lpthread -lxml2
-lcsvparser -lubox -lini -lyuarel -lsqlite3 -lcurl -lm -ldl -lrt -lc -lgcc
uranus#uranus:~/lib/SDL2-2.0.5$ make
/bin/bash build-scripts/updaterev.sh
LTLINK build/libSDL2.la
build/.libs/SDL_mirvideo.o: In function 'MIR_InitDisplayFromOutput':
/home/uranus/lib/SDL2-2.0.5/src/video/mir/SDL_mirvideo.c:258: undefined reference to 'mir_output_get_current_mode'
collect2: error: ld returned 1 exit status
Makefile:147: recipe for target 'build/libSDL2.la' failed
make: *** [build/libSDL2.la] Error 1
SDL2 Configure Summary:
Building Shared Libraries
Building Static Libraries
Enabled modules : atomic audio video render events joystick haptic power filesystem threads timers file loadso cpuinfo assembly
Assembly Math : mmx 3dnow sse sse2
Audio drivers : disk dummy oss alsa(dynamic) pulse(dynamic) sndio
Video drivers : dummy x11(dynamic) opengl opengl_es2 mir(dynamic)
X11 libraries : xcursor xdbe xinerama xinput2 xinput2_multitouch xrandr xscrnsaver xshape xvidmode
Input drivers : linuxev linuxkd
Using libudev : YES
Using dbus : YES
Using ime : YES
Using ibus : NO
Using fcitx : NO
The linker needs the name of the library where is this function.
I fixed it, adding in my Makefile file "-lmirclient".
# diff Makefile Makefile-ORG
26c26
< EXTRA_LDFLAGS = -Wl,--no-undefined -lm -ldl -lasound -lm -ldl -lpthread -lsndio -lX11 -lXext -lXcursor -lXinerama -lXi -lXrandr -lXss -lXxf86vm -lpthread -lrt -lmirclient
---
> EXTRA_LDFLAGS = -Wl,--no-undefined -lm -ldl -lasound -lm -ldl -lpthread -lsndio -lX11 -lXext -lXcursor -lXinerama -lXi -lXrandr -lXss -lXxf86vm -lpthread -lrt
#
A quick fix is to set static linking to the mir library when running configure:
./configure --enable-mir-shared=no
This causes the EXTRA_LDFLAGS variable to have the -lmirclient option added to it, as per Juan's answer.
As for why there is a problem, see bug 3539, which was resolved in a patch shortly after.
Looking at the patch, it appears there was a missing definition needed to allow dynamic linking to the 'mir_output_get_current_mode' function mentioned in the error message.
i had the same problem and i couldn't solve
but i used SDL2.0.3 and i didn't face any problems and it worked and Compiled fine with me
You can install it from here
https://sourceforge.net/projects/libsdl/files/SDL/2.0.3/
This question already has answers here:
Linking OpenSSL libraries to a program
(4 answers)
Closed 5 years ago.
Encountering error while creating a shared library of AES. The following commands are used :
gcc -Wall Test1.c x64/libSESDAPI.a -fPIC -lssl -lcrypto
gcc -shared -o libfile.so a.out -nostartfiles
And I am getting the following errors:
/usr/bin/ld: error in a.out(.eh_frame); no .eh_frame_hdr table will be created.
/usr/bin/ld: libfile.so: No symbol version section for versioned symbol `AES_cbc_encrypt##OPENSSL_1.0.0'
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
I am new to shared libraries so please help.
Edit: I have edited and added the lcrypto and lssl
Edit2: By adding a -c in the first command, the above errors are now resolved. But now accessing the .so file with python gives a new error
OSError: ./libfile.so: undefined symbol: SDSCListDevs
Please tell why this error is coming.
You should be creating your shared library from an object file, not from an executable program.
You also need to link with the SSL libraries.
Commands to use:
# Compile the source file, generate object file
gcc -Wall Test1.c -c -fPIC
# Link object file with libraries to create the shared object
gcc -shared -fPIC -o libfile.so Test1.o x64/libSESDAPI.a -lssl -lcrypto
I am trying to compile the examples of libhand, but I get the following output:
/usr/bin/ld: /usr/local/lib/libOgreMainStatic.a(OgreDynLib.cpp.o): undefined reference to symbol 'dlopen##GLIBC_2.1'
/usr/bin/ld: note: 'dlopen##GLIBC_2.1' is defined in DSO /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libdl.so so try adding it to the linker command line
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/libdl.so: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
make[2]: *** [bend_one_finger] Error 1
make[1]: *** [CMakeFiles/bend_one_finger.dir/all] Error 2
make: *** [all] Error 2
The same thing happens when I try to compile my own example using the direction from libhand example. I believe it has something to do with the configuration file of libhand (LibHandConfig.cmake).
The same example compiles fine when I build it as a part of libhand, the problem occurs when I try to use libhand as a package (using cmake's FIND_PACKAGE() )
Not a complete answer, but just a step toward:
try to issue the following command after you got the make error:
/usr/bin/c++ CMakeFiles/example.dir/example.cc.o -o example -rdynamic -ldl -lXt /path/libs/libHand/hand_cpp/dist/libhand_hog.a /path/libs/libHand/hand_cpp/dist/libhand_renderer.a /path/libs/libHand/hand_cpp/dist/libhand_utils.a -lopencv_core -lopencv_flann -lopencv_imgproc -lopencv_highgui -lopencv_features2d -lopencv_calib3d -lopencv_cudaarithm -lopencv_cudawarping -lopencv_ml -lopencv_objdetect -lopencv_cuda -lopencv_cudafilters -lopencv_cudaimgproc -lopencv_video -lopencv_legacy -lopencv_cudaoptflow -lopencv_photo -lopencv_videostab -lopencv_ts -lopencv_cudacodec -lopencv_ocl -lopencv_superres -lopencv_cudafeatures2d -lopencv_nonfree -lopencv_stitching -lopencv_softcascade -lopencv_shape -lopencv_optim -lopencv_cudastereo -lopencv_cudabgsegm -lopencv_contrib -lopencv_bioinspired /path/libs/libHand/hand_cpp/dist/libdot_sceneloader.a /path/libs/libHand/hand_cpp/dist/libtinyxml.a /usr/local/lib/libOgreMainStatic.a -lzzip -lz -lfreeimage -lfreetype -lSM -lICE -lX11 -lXext -lXaw -lXrandr -ltbb /usr/local/lib/OGRE/libRenderSystem_GLStatic.a -lGLU -lGL /usr/local/lib/libOgreMainStatic.a -lzzip -lz -lfreeimage -lfreetype -lSM -lICE -lX11 -lXext -lXaw -lXrandr -ltbb /usr/local/lib/OGRE/libRenderSystem_GLStatic.a -lGLU -lGL /usr/local/lib/OGRE/libPlugin_OctreeSceneManagerStatic.a -ldl
If it succeeds than you have to manually add -ldl to the end of your libraries list ( target_link_libraries(example ${SOME_LIBS} ${OTHER_LIBS} -ldl) ). It seems that the configuration part of LibOGRE is slightly incorrect (it doesn't include a library libdl necessary to carelessly link application with it.
I am trying to build my root file system by referring to
http://emreboy.wordpress.com/2012/12/20/building-a-root-file-system-using-busybox/comment-page-1/
The change I did was (arm-linux-gnueabi- in place of arm-linux-)
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- defconfig
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig
$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- install
It fails on this step(partial error log). Please advise
CC util-linux/volume_id/volume_id.o
CC util-linux/volume_id/xfs.o
AR util-linux/volume_id/lib.a
LINK busybox_unstripped
Trying libraries: crypt m
Failed: -Wl,--start-group -lcrypt -lm -Wl,--end-group
Output of:
arm-linux-gnueabi-gcc -Wall -Wshadow -Wwrite-strings -Wundef -Wstrict-prototypes -Wunused -Wunused-parameter -Wunused-function -Wunused-value -Wmissing-prototypes -Wmissing-declarations -Wdeclaration-after-statement -Wold-style-definition -fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer -ffunction-sections -fdata-sections -fno-guess-branch-probability -funsigned-char -static-libgcc -falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1 -Os -static -o busybox_unstripped -Wl,--sort-common -Wl,--sort-section,alignment -Wl,--start-group applets/built-in.o archival/lib.a archival/libarchive/lib.a console-tools/lib.a coreutils/lib.a coreutils/libcoreutils/lib.a debianutils/lib.a e2fsprogs/lib.a editors/lib.a findutils/lib.a init/lib.a libbb/lib.a libpwdgrp/lib.a loginutils/lib.a mailutils/lib.a miscutils/lib.a modutils/lib.a networking/lib.a networking/libiproute/lib.a networking/udhcp/lib.a printutils/lib.a procps/lib.a runit/lib.a selinux/lib.a shell/lib.a sysklogd/lib.a util-linux/lib.a util-linux/volume_id/lib.a archival/built-in.o archival/libarchive/built-in.o console-tools/built-in.o coreutils/built-in.o coreutils/libcoreutils/built-in.o debianutils/built-in.o e2fsprogs/built-in.o editors/built-in.o findutils/built-in.o init/built-in.o libbb/built-in.o libpwdgrp/built-in.o loginutils/built-in.o mailutils/built-in.o miscutils/built-in.o modutils/built-in.o networking/built-in.o networking/libiproute/built-in.o networking/udhcp/built-in.o printutils/built-in.o procps/built-in.o runit/built-in.o selinux/built-in.o shell/built-in.o sysklogd/built-in.o util-linux/built-in.o util-linux/volume_id/built-in.o -Wl,--end-group -Wl,--start-group -lcrypt -lm -Wl,--end-group
==========
debianutils/lib.a(mktemp.o): In function `mktemp_main':
mktemp.c:(.text.mktemp_main+0x70): warning: the use of `tempnam' is dangerous, better use `mkstemp'
networking/lib.a(nslookup.o): In function `print_host':
nslookup.c:(.text.print_host+0x24): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
networking/lib.a(ipcalc.o): In function `ipcalc_main':
ipcalc.c:(.text.ipcalc_main+0x15c): warning: Using 'gethostbyaddr' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
libbb/lib.a(inet_common.o): In function `INET_resolve':
inet_common.c:(.text.INET_resolve+0x32): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
networking/lib.a(inetd.o): In function `reread_config_file':
inetd.c:(.text.reread_config_file+0x546): warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
networking/lib.a(netstat.o): In function `ip_port_str':
netstat.c:(.text.ip_port_str+0x28): warning: Using 'getservbyport' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
networking/lib.a(inetd.o): In function `reread_config_file':
inetd.c:(.text.reread_config_file+0x4e4): warning: Using 'getrpcbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
networking/lib.a(inetd.o): In function `unregister_rpc':
inetd.c:(.text.unregister_rpc+0xc): undefined reference to `pmap_unset'
networking/lib.a(inetd.o): In function `register_rpc':
inetd.c:(.text.register_rpc+0x30): undefined reference to `pmap_unset'
inetd.c:(.text.register_rpc+0x46): undefined reference to `pmap_set'
networking/lib.a(inetd.o): In function `prepare_socket_fd':
inetd.c:(.text.prepare_socket_fd+0x52): undefined reference to `bindresvport'
collect2: ld returned 1 exit status
make: *** [busybox_unstripped] Error 1
With the help from vinay hunachyal the answer is as follows
use latest stable busybox code
use the same tool chain (arm-none-linux-gnueabi-gcc) for all the steps (not as the one actually given on the blog)