/usr/bin/ld: cannot find -lcrypto while trying to link - linker

gcc -o clxd -m64 -L/usr/local/lib64 -L/usr/lib64 -L/usr/lib64/nptl
-Wl,-rpath,/home/y/lib64 -ldl -lrt -lpthread -lstdc++ -lgcc -lc -lm -lev -L/home/y/lib64 -Wl,-Bstatic -lboost_program_options -lboost_date_time -lboost_filesystem -lboost_regex -lboost_system -lboost_thread -llua -lcrypto -Wl,-Bdynamic -L/usr/lib
The above command is from a make file while executing make using V=1 (verbose) to understand if I have passed on directories properly or not. And it exits with the following error:
/usr/bin/ld: cannot find -lcrypto collect2: ld returned 1 exit status
My understanding from the gcc command, -Bstatic tries to statically link lib crypto (-lcrypto).
When I checked under /usr/lib64, I have the following files:
libcrypto.so -> libcrypto.so.1.0.1e
libcrypto.so.10 -> libcrypto.so.1.0.1e
libcrypto.so.1.0.1e
Does -Bstatic link the shared files statically or not? If not how do I get libcrypto.a?

I solved this on Linux/Macosx by installing libssl-dev.
sudo apt-get install libssl-dev

Related

installed check for c but "check.h" not found

Im using windows 10 with wsl ubuntu 18.04 Im trying to run the code from here :
https://www.ccs.neu.edu/home/skotthe/classes/cs5600/fall/2015/labs/intro-check-lab-code.tgz
I installed gcc, makefile, and check in the ubuntu terminal. But when I di $ make it says:
gcc money.o check_money.o -lcheck -lm -lpthread -lrt -lgcov -coverage -o check_money_tests
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libcheck.a(check_log.o): In function `subunit_lfun':
(.text+0x5f4): undefined reference to `subunit_test_start'
(.text+0x6bf): undefined reference to `subunit_test_fail'
(.text+0x6d4): undefined reference to `subunit_test_pass'
(.text+0x6ef): undefined reference to `subunit_test_error'
collect2: error: ld returned 1 exit status
Makefile:23: recipe for target 'check_money_tests' failed
make: *** [check_money_tests] Error 1
so I open the check_money.c it says that check.h cannot be found. What did I miss here?
Simple version: you should also link with -lsubunit flag, i.e.:
TST_LIBS = -lcheck -lm -lpthread -lrt -lsubunit
Better yet, all the flags should be taken from check's package configuration, as the requirements depend on how the check library was built (and that's what pkg-config has been invented for). So instead of hardcoding your options, you could improve your Makefile like this:
CFLAGS = -c -Wall $(shell pkg-config --cflags check)
TST_LIBS = $(shell pkg-config --libs check)
Result:
$ make
gcc -c -Wall -pthread -fprofile-arcs -ftest-coverage src/*.c
gcc -c -Wall -pthread -fprofile-arcs -ftest-coverage tests/*.c
gcc money.o check_money.o -lcheck_pic -pthread -lrt -lm -lsubunit -lgcov -coverage -o check_money_tests
...

Compile C on CentOS to static library

I'm able to compile and run my application in C on CentOS with the following parameters:
gcc test.c -o test -lpcap -lssl -lcrypto -L /usr/local/lib -L /usr/local/opt/openssl/lib/ -lhiredis
But I need to run the application on a machine where I cannot compile, nor download ex. hiredis.
So I need to compile everything together on my own CentOS - which does match in setup.
I've read about the static flag, but when doing so I get the following errors:
gcc -static test.c -o test -lpcap -lssl -lcrypto -L /usr/local/lib -L /usr/local/opt/openssl/lib/ -lhiredis
/usr/bin/ld: cannot find -lpcap
/usr/bin/ld: cannot find -lssl
/usr/bin/ld: cannot find -lcrypto
/usr/local/lib/libhiredis.a(net.o): In function `_redisContextConnectTcp':
/home/alfredballe/hiredis/net.c:399: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: error: ld returned 1 exit status
What am I doing wrong?

Trying to build a PyQt5 app for Android and get a link error: cannot find -lc++

I try to build the demo app from pyqtdeploy and I am running into this linker error.
cannot find -lc++
Here is the command which generates the error:
/home/art/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -D__ANDROID_API__=27 -target aarch64-none-linux-android -gcc-toolchain /home/art/Android/Sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a --sysroot=/home/art/Android/Sdk/ndk-bundle/platforms/android-27/arch-arm64/ -Wl,-soname,libpyqt-demo.so -Wl,-rpath=/home/art/Qt/5.12.3/android_arm64_v8a/lib -Wl,--no-undefined -Wl,-z,noexecstack -shared -o libpyqt-demo.so pyqtdeploy_main.o pyqtdeploy_start.o pdytools_module.o _abc.o _bisectmodule.o blake2b_impl.o blake2module.o blake2s_impl.o _datetimemodule.o _hashopenssl.o _heapqmodule.o _math.o _posixsubprocess.o _randommodule.o sha3module.o _ssl.o _struct.o binascii.o mathmodule.o selectmodule.o socketmodule.o zlibmodule.o qrc_pyqtdeploy.o -L/home/art/Sourcecode/pyqtdeploy-2.4/demo/sysroot-android-64/lib -L/home/art/Sourcecode/pyqtdeploy-2.4/demo/sysroot-android-64/lib/python3.7/site-packages/PyQt5 -lQtAndroidExtras -lQtCore -lQtGui -lQtNetwork -lQtWidgets -lcrypto -lpython3.7 -lsip -lssl -lz -L/home/art/Qt/5.12.3/android_arm64_v8a/lib -lQt5Widgets -L/opt/android/android-ndk-r18b/sources/cxx-stl/llvm-libc++/libs/arm64-v8a -lQt5Gui -lQt5Network -lQt5AndroidExtras -lQt5Core -lGLESv2 -L/home/art/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/arm64-v8a /home/art/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++.so.27 -llog -lz -lm -ldl -lc -v
Android (5220042 based on r346389c) clang version 8.0.7 (https://android.googlesource.com/toolchain/clang b55f2d4ebfd35bf643d27dbca1bb228957008617) (https://android.googlesource.com/toolchain/llvm 3c393fe7a7e13b0fba4ac75a01aa683d7a5b11cd) (based on LLVM 8.0.7svn)
Target: aarch64-none-linux-android
Thread model: posix
InstalledDir: /home/art/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin
Found candidate GCC installation: /home/art/Android/Sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x
Selected GCC installation: /home/art/Android/Sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x
Candidate multilib: .;#m64
Selected multilib: .;#m64
"/home/art/Android/Sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld" --sysroot=/home/art/Android/Sdk/ndk-bundle/platforms/android-27/arch-arm64/ -EL --fix-cortex-a53-843419 -z now -z relro --hash-style=both --enable-new-dtags --eh-frame-hdr -m aarch64linux -shared -o libpyqt-demo.so /home/art/Android/Sdk/ndk-bundle/platforms/android-27/arch-arm64//usr/lib/crtbegin_so.o -L/home/art/Sourcecode/pyqtdeploy-2.4/demo/sysroot-android-64/lib -L/home/art/Sourcecode/pyqtdeploy-2.4/demo/sysroot-android-64/lib/python3.7/site-packages/PyQt5 -L/home/art/Qt/5.12.3/android_arm64_v8a/lib -L/opt/android/android-ndk-r18b/sources/cxx-stl/llvm-libc++/libs/arm64-v8a -L/home/art/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/arm64-v8a -L/home/art/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/8.0.7/lib/linux/aarch64 -L/home/art/Android/Sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x -L/home/art/Android/Sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib/../lib64 -L/home/art/Android/Sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib -L/home/art/Android/Sdk/ndk-bundle/platforms/android-27/arch-arm64//usr/lib --exclude-libs libgcc.a --exclude-libs libatomic.a -soname libpyqt-demo.so -rpath=/home/art/Qt/5.12.3/android_arm64_v8a/lib --no-undefined -z noexecstack pyqtdeploy_main.o pyqtdeploy_start.o pdytools_module.o _abc.o _bisectmodule.o blake2b_impl.o blake2module.o blake2s_impl.o _datetimemodule.o _hashopenssl.o _heapqmodule.o _math.o _posixsubprocess.o _randommodule.o sha3module.o _ssl.o _struct.o binascii.o mathmodule.o selectmodule.o socketmodule.o zlibmodule.o qrc_pyqtdeploy.o -lQtAndroidExtras -lQtCore -lQtGui -lQtNetwork -lQtWidgets -lcrypto -lpython3.7 -lsip -lssl -lz -lQt5Widgets -lQt5Gui -lQt5Network -lQt5AndroidExtras -lQt5Core -lGLESv2 /home/art/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++.so.27 -llog -lz -lm -ldl -lc -lc++ -lm -lgcc -ldl -lc -lgcc -ldl /home/art/Android/Sdk/ndk-bundle/platforms/android-27/arch-arm64//usr/lib/crtend_so.o
/home/art/Android/Sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -lc++
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
Has anybody got an idea how to fix this?
Just in case other people are also running into a similar problem.
I could solve this problem using NDK 19 instead of NDK-20.

gcc cannot find -lglfw3

I'm on a linux system (arch linux specifically) and I'm trying to compile the introduction project from the official glfw page but I cannot seem to get gcc to compile it. If anyone doesn't know what I'm talking about it's this.
Also this is how I'm trying to compile it:
gcc -Iinclude test.c -o test -lglfw3 -lm -lGL -lGLU
and it gives me the following errors:
/usr/bin/ld: cannot find -lglfw3
collect2: error: ld returned 1 exit status
I completely forgot about this question until I got a notification for it. For me the solution was to not use -lglfw3 but rather use -lglfw
If you've installed pkg-config, and glfw3.pc is in the search path, try:
gcc -Iinclude test.c -o test `pkg-config --libs glfw3` -lm -lGL -lGLU
If you only have the static build, use: pkg-config --static --libs glfw3, which will add the dependencies that libglfw3.a requires.
Find libglfw3.a or libglfw3.so on your system
Mention that path to gcc using -L
gcc -Iinclude test.c -o test -L/dir/where/glfw3/resides -lglfw3 -lm -lGL -lGLU

undefined reference to `gst_riff_create_video_caps'

I'm trying to build a software that uses gstreamer-1.0 and its plugins. I get this error when I try to make using the following g++ command:
g++ vis.cpp -o vis -O3 -D__STDC_CONSTANT_MACROS -std=c++11 -lopencv_highgui -lopencv_imgproc -lopencv_core -lpng -lv4l1 -lv4l2 -ldc1394 -lswscale -lavdevice -lavformat -lavcodec -lswresample -lavutil -lpthread -lbz2 -lz -lc -lrt -llzma -lva -Idependencies/include -Ldependencies/lib `pkg-config --cflags --libs gstreamer-1.0 gstreamer-base-1.0 gstreamer-app-1.0 gstreamer-pbutils-1.0 gtk+-2.0`
cap_gstreamer.cpp:(.text._ZN23CvVideoWriter_GStreamer4openEPKcid6CvSizeb+0x434): undefined reference to `gst_riff_create_video_caps'
collect2: error: ld returned 1 exit status
make: *** [vis] Error 1
Isn't gst_riff_create_video_caps already in the base plug-in? Or do I have to link another plugin for it?
I solved my problem. Obviously, I had to add -lgstriff-1.0 to the library flags as pointed out here:
http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-libs/html/gstreamer-riff.html

Resources