title: How to stop cmake from trying to link against non-existing library?
body: <p>I am sorry if this is a naive question, as I'm quite unfamiliar with CMake in general.</p>
  <p>I am trying to compile a very large open-source software project (OpenCV). I seem to have get most libraries that is needed into the path using the following command line arguments.</p>
  <pre><code>-DCUDNN_INCLUDE_DIR='${CONDA_PREFIX}/include' \
  -DCUDNN_LIBRARY='/${CONDA_PREFIX}/lib' \
  -DC_INCLUDE_PATH=${CONDA_PREFIX}/include:/usr/local/include:/usr/include/x86_64-linux-gnu: \
  -DINCLUDE_PATH=${CONDA_PREFIX}/include:/usr/local/include:/usr/include/x86_64-linux-gnu \
  -DC_PATH=${CONDA_PREFIX}/include:/usr/local/include:/usr/include/x86_64-linux-gnu \
  -DLD_LIBARY_PATH=${CONDA_PREFIX}/lib:/usr/lib/x86_64-linux-gnu \
  </code></pre>
  <p>Indeed, CMake is able to find the libraries it needs, like CUDA, CuDNN, OpenBlas, FFMpeg, etc. Everything seems to go well for a while.</p>
  <p>At the linking stage, however, CMake keeps attaching a weird library reference &quot;-llib&quot;. lib is a non-existent library, of course. For example, one such command is</p>
  <blockquote>
  <p>cd /home/albert/app/src/opencv/build/modules/cudev &amp;&amp; /usr/bin/cmake
  -E cmake_link_script CMakeFiles/opencv_cudev.dir/link.txt --verbose=1</p>
  </blockquote>
  <blockquote>
  <p>/usr/bin/c++ -fPIC    -fsigned-char -W -Wall -Werror=return-type
  -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Winit-self -Wpointer-arith -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -Wno-undef -Wno-missing-declarations -Wno-unused-function -Wno-unused-variable -Wno-enum-compare -Wno-shadow -O3 -DNDEBUG  -DNDEBUG -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a   -Wl,--gc-sections -Wl,--as-needed   -shared -Wl,-soname,libopencv_cudev.so.4.4 -o ../../lib/libopencv_cudev.so.4.4.0
  CMakeFiles/opencv_cudev.dir/src/stub.cpp.o   -L/usr/local/cuda/lib64
  -L/home/albert/.conda/envs/denseflow  -Wl,-rpath,/usr/local/cuda/lib64:/home/albert/.conda/envs/denseflow:::::::::::::::::::::::
  -ldl -lm -lpthread -lrt ../../3rdparty/lib/libippiw.a ../../3rdparty/ippicv/ippicv_lnx/icv/lib/intel64/libippicv.a
  -lcudart_static -lpthread -ldl -lrt -lnppc -lnppial -lnppicc -lnppidei -lnppif -lnppig -lnppim -lnppist -lnppisu -lnppitc -lnpps -lcublas <strong>-llib</strong> -lcufft -L/usr/local/cuda/lib64 -L/usr/lib/x86_64-linux-gnu -L/home/albert/.conda/envs/denseflow -lcudart_static -lpthread -ldl -lrt -lnppc -lnppial -lnppicc -lnppidei -lnppif -lnppig -lnppim -lnppist -lnppisu -lnppitc -lnpps -lm -lpthread -lcublas <strong>-llib</strong> -lcufft</p>
  </blockquote>
  <p>This causes the following error.</p>
  <blockquote>
  <p>/usr/bin/ld: cannot find -llib
  collect2: error: ld returned 1 exit status
  make[2]: *** [modules/cudev/CMakeFiles/opencv_cudev.dir/build.make:89: lib/libopencv_cudev.so.4.4.0] Error 1</p>
  </blockquote>
  <p>If I manually remove the &quot;-llib&quot; (both occurrences) from the C++ command, the command executes successfully.</p>
  <p>What is happening here?</p>
  <p>Although I'm unfamiliar with CMake, it feels like there should be a straightforward way to prevent CMake from doing this.</p>
  <p>Thank you so much for your help.</p>
  <p><strong>Update:</strong> There does seem to be something wrong with the OpenCV CMake files. When I run CMake, one of its output is</p>
  <blockquote>
  <p>--     Extra dependencies:          dl m pthread rt cudart nppc nppial nppicc nppidei nppif nppig nppim nppist nppisu nppitc npps cublas <strong>lib</strong>
  cufft -L/usr/local/cuda-11.6/lib64
  -L/home/albert/.conda/envs/denseflow</p>
  </blockquote>
  <p>The mysterious lib already appears here.</p>
  <p>Someone on the Internet suggests modifying CMakeCache.txt manually, but I wasn't able to get it to work. CMake just overwrites it after my modifications.</p>