yocto arm-poky-linux-gcc eclipse linker missing libraries - linux

For some time I try to compile and debug a simple hello word application written in C.
Unfortunately, meta-toolchain or populate_sdk generate strangle failures.
My simple application works fine(compile and debug) with the buildroot toolchain. With the installed arm-poky-linux... I get some errors.
I try to do in the same console to create env.
. /opt/poky/3.1.17/environment-setup-armv5e-poky-linux-gnueabi
and run eclipse.
make all
Building target: MangoPi-R3-Gpio.elf
Invoking: GNU Arm Cross C Linker
arm-poky-linux-gnueabi-gcc -mcpu=arm926ej-s -marm -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -g3 -Xlinker --gc-sections -Wl,-Map,"MangoPi-R3-Gpio.map" -o "MangoPi-R3-Gpio.elf" ./gpio-example.o ./gpio_lib.o
/opt/poky/3.1.17/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/9.3.0/real-ld: cannot find Scrt1.o: No such file or directory
/opt/poky/3.1.17/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/9.3.0/real-ld: cannot find crti.o: No such file or directory
/opt/poky/3.1.17/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/9.3.0/real-ld: cannot find crtbeginS.o: No such file or directory
/opt/poky/3.1.17/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/9.3.0/real-ld: cannot find -lgcc
/opt/poky/3.1.17/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/9.3.0/real-ld: cannot find -lgcc_s
/opt/poky/3.1.17/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/9.3.0/real-ld: cannot find -lc
/opt/poky/3.1.17/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/9.3.0/real-ld: cannot find -lgcc
/opt/poky/3.1.17/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/9.3.0/real-ld: cannot find -lgcc_s
/opt/poky/3.1.17/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/9.3.0/real-ld: cannot find crtendS.o: No such file or directory
/opt/poky/3.1.17/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/9.3.0/real-ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [makefile:57: MangoPi-R3-Gpio.elf] Błąd 1
What did I do wrong? All of the mentioned files are in the installed folder of poky toolchain.
I created my toolchain using two options
bitbake console-image -c populate_sdk
and
bitbake meta-toolchain
the result is the same as above.
Adding
--sysroot=/opt/poky/3.1.17/sysroots/armv5e-poky-linux-gnueabi
also not changing anything.

Related

Building Debian with Buildroot: libDeviceIo.so: file format not recognized

Im trying to compile for a project debian for this device: https://www.engicam.com/vis-prod/PX30-Core/PX30-Core-EDIMM-SOM-based-on-RockChip--PX30 which has an aarch64 architecture. I'm using a VM provided by them which should already have all the tools and configurations ready, but I'm running into some issues. If I've understood correctly I have to build buildroot to build Debian, after adding a couple packages with make menuconfig and running make I get this error:
PATH="/home/user/px30/buildroot/output/host/bin:/home/user/px30/buildroot/output/host/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" /usr/bin/make -j9 CXXFLAGS+="-DRKDEVICEIO -I/home/user/px30/buildroot/../external/deviceio_release/DeviceIO/include" LFLAGS+=" -lDeviceIo -lasound" -C /home/user/px30/buildroot/output/build/qsetting-1.0
make[1]: Entering directory '/home/user/px30/buildroot/output/build/qsetting-1.0'
/home/user/px30/buildroot/output/host/bin/aarch64-buildroot-linux-gnu-g++ -lDeviceIo -lasound -o qsetting main.o mainwindow.o qtaudio.o qtbt.o qtfactory.o qtinputdialog.o qtkeyboard.o qtupdate.o qtwifi.o qrc_res.o moc_mainwindow.o moc_qtaudio.o moc_qtbt.o moc_qtfactory.o moc_qtinputdialog.o moc_qtkeyboard.o moc_qtupdate.o moc_qtwifi.o -lQt5Widgets -lQt5Multimedia -lQt5Gui -lQt5Network -lQt5Core -latomic -lrt -ldl /home/user/px30/buildroot/output/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/libGLESv2.so -lpthread -lrt -lpthread -ldl
/home/user/px30/buildroot/output/host/lib/gcc/aarch64-buildroot-linux-gnu/6.5.0/../../../../aarch64-buildroot-linux-gnu/bin/ld:/home/user/px30/buildroot/output/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/../lib64/libDeviceIo.so: file format not recognized; treating as linker script
/home/user/px30/buildroot/output/host/lib/gcc/aarch64-buildroot-linux-gnu/6.5.0/../../../../aarch64-buildroot-linux-gnu/bin/ld:/home/user/px30/buildroot/output/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/../lib64/libDeviceIo.so:0: syntax error
collect2: error: ld returned 1 exit status
Makefile:214: recipe for target 'qsetting' failed
make[1]: *** [qsetting] Error 1
make[1]: Leaving directory '/home/user/px30/buildroot/output/build/qsetting-1.0'
package/pkg-generic.mk:254: recipe for target '/home/user/px30/buildroot/output/build/qsetting-1.0/.stamp_built' failed
make: *** [/home/user/px30/buildroot/output/build/qsetting-1.0/.stamp_built] Error 2
I tried to open /px30/buildroot/output/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/libDeviceIo.so and it's an ASCII file
user#ubuntu:~/px30/buildroot/output/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib$ cat libDeviceIo.so
fake
user#ubuntu:~/px30/buildroot/output/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib$ file libDeviceIo.so
libDeviceIo.so: ASCII text
EDIT: I did not find a solution, I solved it by removing the package qsetting from the target packages

Converting Makefile to CMake cannot find linked shared object

I am attempting to convert a working Makefile into a CMake and need a little assistance. I am trying to cross compile a small program for a yocto device from a Ubuntu20 machine that is trying to link to the devices shared object file with cmake. I have a working Makefile that builds a working program. However, when I try and do this with a CMakeList file it fails at the make stage linking to the shared objects linker flag.
The file structure of the code is as follows;
Parent
- include/
- file1.h
- file2.h
- xxx.h
- lib/
- libOBD2.so
- src/
- test.c
- CMakeLists.txt # Not working
- Makefile. # working
The shared object is being linked from within the program parent directory but I have also tried with it in the /usr/lib and /usr/local/lib from here but with no change.
The working Makefile
.prevent_execution:
exit 0
#remove # for no make command prints
DEBUG = #
APP_DIR = .
BUILD_DIR := $(APP_DIR)/build
SRC_DIRS := $(APP_DIR)/src
HEADER_DIR := $(APP_DIR)/include
APP_LIBRARY_DIR = $(APP_DIR)/lib
APP_NAME = test
# Locate all the source c and cpp files to be built
APP_SRC_FILES := $(shell find $(SRC_DIRS) -name '*.cpp' -or -name '*.c')
INC_DIRS := $(shell find $(HEADER_DIR) -type d)
# Add a prefix to INC_DIRS. So moduleA would become -ImoduleA. GCC understands this -I flag
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
CFLAGS+=-fPIC
PATH1 = /opt/fsl-imx-x11/5.4-zeus/sysroots/x86_64-pokysdk-linux/usr/include/
PATH2 = /opt/fsl-imx-x11/5.4-zeus/sysroots/x86_64-pokysdk-linux/usr/include/libxml2/
PATH3 = /opt/fsl-imx-x11/5.4-zeus/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi/usr/lib/
MAKE_CMD = -g -O0 -s -o $(BUILD_DIR)/$(APP_NAME) $(INC_FLAGS) $(APP_SRC_FILES) - I$(PATH1) -I$(PATH2) -L$(APP_LIBRARY_DIR) -lz -lOBD2 -lssl -lcrypto -lcurl -lxml2 -L$(PATH3) -lm -ldl -lpthread -lrt
all:
$(DEBUG) $(CC) $(CFLAGS) $(MAKE_CMD)
clean:
rm -f $(BUILD_DIR)/$(APP_NAME)
The CmakeLists.txt
cmake_minimum_required( VERSION 3.5 )
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR ARM)
# -fPIC
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
project(iwtest)
set(PATH1 "/opt/fsl-imx-x11/5.4-zeus/sysroots/x86_64-pokysdk-linux/usr/include/")
set(PATH2 "/opt/fsl-imx-x11/5.4-zeus/sysroots/x86_64-pokysdk-linux/usr/include/libxml2/")
set(PATH3 "/opt/fsl-imx-x11/5.4-zeus/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi/usr/lib")
set(LIB_DIR "${CMAKE_SOURCE_DIR}/lib")
include_directories(${PROJECT_NAME} PRIVATE ${PATH1})
include_directories(${PROJECT_NAME} PRIVATE ${PATH2})
include_directories(${PROJECT_NAME} PRIVATE "${PROJECT_SOURCE_DIR}/include")
set(SOURCE_FILES src/test.c)
add_definitions("-g")
add_definitions("-O0")
add_definitions("-s")
# Connect the libOBD2 library to the project
add_library(libOBD2 SHARED IMPORTED)
set_target_properties(libOBD2 PROPERTIES IMPORTED_LOCATION ${LIB_DIR}/libOBD2.so)
include_directories(libOBD2 INTERFACE ${CMAKE_SOURCE_DIR}/lib)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
# target_link_libraries(${PROJECT_NAME} PRIVATE ${PATH3})
target_link_libraries(${PROJECT_NAME} PUBLIC libOBD2)
target_link_options(${PROJECT_NAME} PRIVATE -lz -lOBD2 -lssl -lcrypto -lcurl -lxml2 -L$(PATH3) -lm -ldl -lpthread -lrt)
# target_link_options(${PROJECT_NAME} PRIVATE -I$(PATH1) -I$(PATH2) -L$(LIB_DIR) -lz -lOBD2 -lssl -lcrypto -lcurl -lxml2 -L$(PATH3) -lm -ldl -lpthread -lrt)
The output of cmake
-- Toolchain file defaulted to '/opt/fsl-imx-x11/5.4-zeus/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake'
-- The C compiler identification is GNU 9.2.0
-- The CXX compiler identification is GNU 9.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /opt/fsl-imx-x11/5.4-zeus/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/fsl-imx-x11/5.4-zeus/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/dev/Workspace/build/cmakebuild
The output of make VERBOSE=1
/opt/fsl-imx-x11/5.4-zeus/sysroots/x86_64-pokysdk-linux/usr/bin/cmake -S/home/dev/Development/iwave-test-code -B/home/dev/Workspace/build/cmakebuild --check-build-system CMakeFiles/Makefile.cmake 0
/opt/fsl-imx-x11/5.4-zeus/sysroots/x86_64-pokysdk-linux/usr/bin/cmake -E cmake_progress_start /home/dev/Workspace/build/cmakebuild/CMakeFiles /home/dev/Workspace/build/cmakebuild//CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/dev/Workspace/build/cmakebuild'
make -f CMakeFiles/iwtest.dir/build.make CMakeFiles/iwtest.dir/depend
make[2]: Entering directory '/home/dev/Workspace/build/cmakebuild'
cd /home/dev/Workspace/build/cmakebuild && /opt/fsl-imx-x11/5.4-zeus/sysroots/x86_64-pokysdk-linux/usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/dev/Development/iwave-test-code /home/dev/Development/iwave-test-code /home/dev/Workspace/build/cmakebuild /home/dev/Workspace/build/cmakebuild /home/dev/Workspace/build/cmakebuild/CMakeFiles/iwtest.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/dev/Workspace/build/cmakebuild'
make -f CMakeFiles/iwtest.dir/build.make CMakeFiles/iwtest.dir/build
make[2]: Entering directory '/home/dev/Workspace/build/cmakebuild'
[ 50%] Building C object CMakeFiles/iwtest.dir/src/test.c.o
/opt/fsl-imx-x11/5.4-zeus/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/fsl-imx-x11/5.4-zeus/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi --sysroot=/opt/fsl-imx-x11/5.4-zeus/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi -I/home/dev/Development/iwave-test-code/iwtest -I/home/dev/Development/iwave-test-code/PRIVATE -I/opt/fsl-imx-x11/5.4-zeus/sysroots/x86_64-pokysdk-linux/usr/include -I/opt/fsl-imx-x11/5.4-zeus/sysroots/x86_64-pokysdk-linux/usr/include/libxml2 -I/home/dev/Development/iwave-test-code/include -I/home/dev/Development/iwave-test-code/libOBD2 -I/home/dev/Development/iwave-test-code/INTERFACE -I/home/dev/Development/iwave-test-code/lib -O2 -pipe -g -feliminate-unused-debug-types -fPIE -g -O0 -s -o CMakeFiles/iwtest.dir/src/test.c.o -c /home/dev/Development/iwave-test-code/src/test.c
In file included from /opt/fsl-imx-x11/5.4-zeus/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi/usr/include/bits/libc-header-start.h:33,
from /opt/fsl-imx-x11/5.4-zeus/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi/usr/include/stdio.h:27,
from /home/dev/Development/iwave-test-code/src/test.c:1:
/opt/fsl-imx-x11/5.4-zeus/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi/usr/include/features.h:382:4: warning: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Wcpp]
382 | # warning _FORTIFY_SOURCE requires compiling with optimization (-O)
| ^~~~~~~
[100%] Linking C executable iwtest
/opt/fsl-imx-x11/5.4-zeus/sysroots/x86_64-pokysdk-linux/usr/bin/cmake -E cmake_link_script CMakeFiles/iwtest.dir/link.txt --verbose=1
/opt/fsl-imx-x11/5.4-zeus/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/fsl-imx-x11/5.4-zeus/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi --sysroot=/opt/fsl-imx-x11/5.4-zeus/sysroots/cortexa7t2hf-neon-poky-linux-gnueabi -O2 -pipe -g -feliminate-unused-debug-types -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -fstack-protector-strong -Wl,-z,relro,-z,now -lz -lOBD2 -lssl -lcrypto -lcurl -lxml2 "-L\$$(PATH3)" -lm -ldl -lpthread -lrt CMakeFiles/iwtest.dir/src/test.c.o -o iwtest -Wl,-rpath,/home/dev/Development/iwave-test-code/lib /home/dev/Development/iwave-test-code/lib/libOBD2.so
/opt/fsl-imx-x11/5.4-zeus/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/9.2.0/real-ld: cannot find -lOBD2
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/iwtest.dir/build.make:104: iwtest] Error 1
make[2]: Leaving directory '/home/dev/Workspace/build/cmakebuild'
make[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/iwtest.dir/all] Error 2
make[1]: Leaving directory '/home/dev/Workspace/build/cmakebuild'
make: *** [Makefile:103: all] Error 2
Any help is much appreciated. Thanks in advance.
Thanks to Tsyvarev comment the solution was to remove the -lOBD2 from the target_link_options. As per Tsyvarev suggestion now all the linker options are linked through target_link_libraries.
The solution to the CMakeLists.txt
# remove the target_link_options line
# target_link_options(${PROJECT_NAME} PRIVATE -lz -lOBD2 -lssl -lcrypto -lcurl -lxml2 -L$(PATH3) -lm -ldl -lpthread -lrt)
# replace with
target_link_libraries(${PROJECT_NAME} PUBLIC libOBD2 pthread ssl crypto curl xml2 m dl rt)
On a side note, as i was cross-compiling for a yocto device the libOBD2.so was located in a different directory to the cross-compile pc of ${CMAKE_SOURCE_DIR}/lib. To fix this I copied libOBD2.so to the same directory seen on the device, in this case it was /usr/lib and change LIB_DIR to set(LIB_DIR "/usr/lib").
There's an easier way to do all this. I happen to be using the same toolchain, and likely the exact same iWave telematic device that you are. My CMakeLists.txt file is generic, nothing toolchain-specific in it at all (except the platform-specific library)...
cmake_minimum_required(VERSION 3.0.0)
project(testapp VERSION 0.1.0)
add_executable(testapp src/testapp.cpp)
target_include_directories(testapp PUBLIC include)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_directories(testapp PUBLIC lib)
target_link_libraries(testapp PRIVATE Threads::Threads libOBD2.so)
Once I have this file in my project folder, I run the following commands from the terminal:
source /opt/fsl-imx-x11/5.4-zeus/environment-setup-cortexa7t2hf-neon-poky-linux-gnueabi
mkdir build
cd build
cmake ..
make
CMake will now automatically detect the toolchain, and generate the appropriate makefiles to actually build your project. The nice thing is, if you're not linking in platform-specific libraries (such as the libOBD2.so file provided by iWave), you can easily retarget the build to another environment - I've successfully switched to a Raspberry Pi, or native Ubuntu. It all depends on what toolchain CMake detects when you run it. The "source" command sets that up, and CMake takes it all from there...
Regards,
David

Unable to cross-compile dropbear for uclibc

I am trying to cross-compile Dropbear for an x86 machine where glibc is missing and instead, uclibc is being used. For that aim, I have cross-compiled zlib for this same instruction set using a custom crosstool-ng toolchain and installed it to a custom location.
msainz#ubuntu:~$ ls Projects/zlib_install/lib
libz.a libz.so libz.so.1 libz.so.1.2.11 pkgconfig
I have copied Projects/zlib_install/include/zlib.h and Projects/zlib/include/zconf.h to Projects/dropbear/zlibincludes/.
I've set my env variables this way:
msainz#ubuntu:~$ echo $PATH
usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:
/usr/local/games:/snap/bin:/home/msainz/x-tools/x86_64-multilib-linux-uclibc/bin
msainz#ubuntu:~/Projects/dropbear$ echo $LDFLAGS
/home/msainz/Projects/zlib_install/lib/libz.a
msainz#ubuntu:~/Projects/dropbear$ echo $CFLAGS
-Izlibincludes -I../zlibincludes
I launch the configure script this way: ./configure --prefix=/home/msainz/Projects/tmp_top_dir --host=x86
The execution terminates with the following error:
configure:4851: x86_64-multilib-linux-uclibc-gcc -o conftest -Izlibincludes -I../zlibincludes -Wno-
pointer-sign -fno-strict-overflow -fPIE -fstack-protector-strong -D_FORTIFY_SOURCE=2 -mfunction-
return=thunk -mindirect-branch=thunk /home/msainz/Projects/zlib_install/lib/libz.a -pie -Wl,-z,now -
Wl,-z,relro conftest.c -lz >&5
/home/msainz/x-tools/x86_64-multilib-linux-uclibc/bin/../lib/gcc/x86_64-multilib-linux-
uclibc/8.3.0/../../../../x86_64-multilib-linux-uclibc/bin/ld.bfd: cannot find -lz
collect2: error: ld returned 1 exit status
Any ideas to solve this? Thanks in advance.
Solved the problem adding --with-zlib=/home/msainz/Projects/zlib_install/ to the ./configure call.

When I `make` darknet with CUDA=1, `/usr/bin/ld: cannot find -lcuda`occured. How to fix it without root permission

I'm trying to train YOLOv4 with darknet on a computing cluster. But when I make the darknet, it occured that:
/usr/bin/ld: cannot find -lcuda
collect2: error: ld returned 1 exit status
make: *** [darknet] Error 1
This computing cluster can load software with module load. For example, when I need CUDA10.2, just run module load devel/cuda/10.2.
So that means the files of CUDA still locate in the system directory, and I don't have the access to modify any of it.
In this case, how can I fix this problem?
More detail about this error:
[usr#*hpc darknet]$ make
chmod +x *.sh
g++ -std=c++11 -std=c++11 -Iinclude/ -I3rdparty/stb/include -DOPENCV `pkg-config --cflags opencv4 2> /dev/null || pkg-config --cflags opencv` -DGPU -I/usr/local/cuda/include/ -DCUDNN -Wall -Wfatal-errors -Wno-unused-result -Wno-unknown-pragmas -fPIC -Ofast -DOPENCV -DGPU -DCUDNN -I/usr/local/cudnn/include obj/image_opencv.o obj/http_stream.o obj/gemm.o obj/utils.o obj/dark_cuda.o obj/convolutional_layer.o obj/list.o obj/image.o obj/activations.o obj/im2col.o obj/col2im.o obj/blas.o obj/crop_layer.o obj/dropout_layer.o obj/maxpool_layer.o obj/softmax_layer.o obj/data.o obj/matrix.o obj/network.o obj/connected_layer.o obj/cost_layer.o obj/parser.o obj/option_list.o obj/darknet.o obj/detection_layer.o obj/captcha.o obj/route_layer.o obj/writing.o obj/box.o obj/nightmare.o obj/normalization_layer.o obj/avgpool_layer.o obj/coco.o obj/dice.o obj/yolo.o obj/detector.o obj/layer.o obj/compare.o obj/classifier.o obj/local_layer.o obj/swag.o obj/shortcut_layer.o obj/activation_layer.o obj/rnn_layer.o obj/gru_layer.o obj/rnn.o obj/rnn_vid.o obj/crnn_layer.o obj/demo.o obj/tag.o obj/cifar.o obj/go.o obj/batchnorm_layer.o obj/art.o obj/region_layer.o obj/reorg_layer.o obj/reorg_old_layer.o obj/super.o obj/voxel.o obj/tree.o obj/yolo_layer.o obj/gaussian_yolo_layer.o obj/upsample_layer.o obj/lstm_layer.o obj/conv_lstm_layer.o obj/scale_channels_layer.o obj/sam_layer.o obj/convolutional_kernels.o obj/activation_kernels.o obj/im2col_kernels.o obj/col2im_kernels.o obj/blas_kernels.o obj/crop_layer_kernels.o obj/dropout_layer_kernels.o obj/maxpool_layer_kernels.o obj/network_kernels.o obj/avgpool_layer_kernels.o -o darknet -lm -pthread `pkg-config --libs opencv4 2> /dev/null || pkg-config --libs opencv` -L/usr/local/cuda/lib64 -lcuda -lcudart -lcublas -lcurand -L/usr/local/cudnn/lib64 -lcudnn -lstdc++
/usr/bin/ld: cannot find -lcuda
collect2: error: ld returned 1 exit status
make: *** [darknet] Error 1
On a machine with a GPU (and driver) installed, the -lcuda dependency can usually be satisfied because the driver installs the libcuda.so (or equivalent on windows) in the link search path (typically).
However on a machine with no GPU installed (e.g. a login node or build machine in a cluster) the driver won't be installed and therefore libcuda.so won't be in the "usual place".
In these situations, "stub" libraries are provided, usually in the /stubs directory off the CUDA toolkit library install directory (e.g. /usr/local/cuda/lib64).
Therefore, if you change your Makefile at this line to read:
LDFLAGS+= -L/usr/local/cuda/lib64 -lcudart -lcublas -lcurand -L/usr/local/cuda/lib64/stubs -lcuda
it should allow that library to be located.

Link options are incompatible - don't see options anywhere in command

g++ -Wl,-rpath,/usr/local/lib -o /path-to/executable {list of .o files} -L/usr/X11R6/lib -L/usr/local/lib -lQtGui -L/usr/local/lib -L/usr/openwin/lib -lSM -lICE -lXext -lX11 -lresolv -lsocket -lnsl -lQtCore -lm -lrt -ldl -lpthread
I'm using the above command to compile an executable. Well actually a makefile is doing it for me..but regardless.
I'm getting an error with the above command:
ld: fatal: option -dn and -P are incompatible
ld: fatal: Flags processing errors
I don't see where -dn or -P are being supplied to the linker anywhere in the command or in the makefile. Where is the linker getting this info?
By trying to temporarily remove each segment of the linking command, I found that removing ",rpath,/usr/local/lib" made the thing work. Which got me thinking that I was setting linker options somewhere else in linux world.
Further investigation proved that I was setting LD_LIBRARY_PATH which included some linker options that caused the conflict. Upon changing that LD_LIBRARY_PATH, things worked as they should have.

Resources