Trying to get OpenCV included in my C++ project, but having issues for some reason...
I followed the instructions to install from source:
git clone https://github.com/opencv/opencv.git
mkdir build && cd build
cmake ../opencv
make -j4
make install
I can see it in my /usr/local/include under 'opencv4'
In my CMakeLists.txt I have:
add_executable(Nssams main.cpp ${BACKWARD_ENABLE})
add_subdirectory(camera)
add_subdirectory(mqtt_client)
add_subdirectory(jsoncpp)
add_subdirectory(serial)
add_subdirectory(backward-cpp)
if(${BUILD_WITH_TESTING})
add_subdirectory(tests)
endif()
find_package(PahoMqttCpp REQUIRED)
find_package(spdlog REQUIRED)
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV_INCLUDE_DIRS = ${OpenCV_INCLUDE_DIRS}")
message(STATUS "OpenCV LIBS = ${OpenCV_LIBS}")
target_link_libraries(Nssams
mqtt
camera
jsoncpp
serial
PahoMqttCpp::paho-mqttpp3-static
spdlog
${OpenCV_LIBS}
)
The messages are spitting out:
[cmake] -- OpenCV_INCLUDE_DIRS = /usr/local/include/opencv4
[cmake] -- OpenCV LIBS = opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_gapi;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;
But when I try to #include, i.e.
#include "opencv4/opencv2/core.hpp"
It's red underlined and the error says
#include errors detected based on information provided by the configurationProvider setting. Squiggles are disabled for this translation unit (/home/bwhitely/Projects/NSSAMS/nssams-cpp-ebcmos/src/camera/ebcmos.cpp).C/C++(1696)
cannot open source file "opencv2/core/cvdef.h" (dependency of "opencv4/opencv2/core.hpp")C/C++(1696)
Where am I going wrong?
I have done very similar things with the spdlog library that's in the CMakeLists.txt with no issues. Just built it from source, added it to the CMakeLists.txt and could use without issues
EDIT:
CMakeLists.txt build output while having #include "opencv4/opencv2/core/core.hpp" included in a .cpp file
[main] Building folder: nssams-cpp-ebcmos
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /home/bwhitely/Projects/NSSAMS/nssams-cpp-ebcmos/build --config Debug --target all -j 4 --
[build] Consolidate compiler generated dependencies of target backward_object
[build] Consolidate compiler generated dependencies of target camera
[build] Consolidate compiler generated dependencies of target jsoncpp
[build] Consolidate compiler generated dependencies of target mqtt
[build] [ 6%] Built target backward_object
[build] [ 12%] Building CXX object src/camera/CMakeFiles/camera.dir/ebcmos.cpp.o
[build] [ 31%] Built target mqtt
[build] [ 43%] Built target jsoncpp
[build] Consolidate compiler generated dependencies of target serial
[build] Consolidate compiler generated dependencies of target backward
[build] [ 56%] Built target backward
[build] [ 68%] Built target serial
[build] In file included from /home/bwhitely/Projects/NSSAMS/nssams-cpp-ebcmos/src/camera/ebcmos.cpp:8:
[build] /usr/local/include/opencv4/opencv2/core/core.hpp:48:10: fatal error: opencv2/core.hpp: No such file or directory
[build] 48 | #include "opencv2/core.hpp"
[build] | ^~~~~~~~~~~~~~~~~~
[build] compilation terminated.
[build] gmake[2]: *** [src/camera/CMakeFiles/camera.dir/build.make:104: src/camera/CMakeFiles/camera.dir/ebcmos.cpp.o] Error 1
[build] gmake[1]: *** [CMakeFiles/Makefile2:219: src/camera/CMakeFiles/camera.dir/all] Error 2
[build] gmake: *** [Makefile:136: all] Error 2
[proc] The command: /usr/bin/cmake --build /home/bwhitely/Projects/NSSAMS/nssams-cpp-ebcmos/build --config Debug --target all -j 4 -- exited with code: 2 and signal: null
[build] Build finished with exit code 2
It does build correctly if I do not have that include defined
output below:
[main] Building folder: nssams-cpp-ebcmos
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /home/bwhitely/Projects/NSSAMS/nssams-cpp-ebcmos/build --config Debug --target all -j 4 --
[build] [ 6%] Building CXX object src/camera/CMakeFiles/camera.dir/ebcmos.cpp.o
[build] [ 12%] Built target backward_object
[build] [ 25%] Built target jsoncpp
[build] [ 43%] Built target mqtt
[build] [ 56%] Built target serial
[build] [ 68%] Built target backward
[build] [ 75%] Linking CXX static library ../../lib/libcamera.a
[build] [ 87%] Built target camera
[build] Consolidate compiler generated dependencies of target Nssams
[build] [ 93%] Linking CXX executable ../bin/Nssams
[build] [100%] Built target Nssams
[build] Build finished with exit code 0
Related
I have been trying on and off for the past year to import the NLopt library into my work. I have been unsuccessful, and I am desperate for help.
Here is some of my CMAKE file
cmake_minimum_required(VERSION 3.21)
project(DynamicRRT)
set(CMAKE_CXX_STANDARD 17)
set(CONAN_CMAKE_CXX_STANDARD 17)
include_directories(/opt/homebrew/Cellar/eigen/3.4.0_1/include/eigen3/)
find_library(nlopt /Users/brandon/Extern/nlopt_install/ NAMES libnlopt nlopt NLopt)
include_directories(/Users/brandon/Extern/nlopt_install/include/ )
link_directories(/Users/brandon/Extern/nlopt_install/include/ )
#INCLUDE_DIRECTORIES(/Users/brandon/CLionProjects/nlopt/)
#INCLUDE_DIRECTORIES(/opt/homebrew/Cellar/nlopt/2.7.1/include/)
#include_directories(/usr/local/include/)
#add_library(nlopt /Users/brandon/Extern/nlopt_install/include)
#add_compile_options(-Wa,-mbig-obj)ยก
add_executable(DynamicRRT main.cpp utilities.cpp utilities.h rrt_star.cpp rrt_star.h tree.cpp tree.h Nodes.cpp Nodes.h Obstacles.cpp Obstacles.h macro_rrt_star.cpp macro_rrt_star.h collisions.cpp collisions.h dynamic_rrt_star.cpp dynamic_rrt_star.h trajectory.cpp trajectory.h transformer.cpp transformer.h print_utilities.cpp print_utilities.h random_utilities.cpp random_utilities.h)# inverse_kinematics.cpp inverse_kinematics.h)# rrt_star.cpp rrt_star.h)#rrt_star_util.cpp rrt_star_util.h
target_link_libraries(DynamicRRT nlopt)
You can see that I've commented out a number of attempts at getting this imported. CMake does not throw any errors. However, if I try building the project, I get:
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/brandonmeng/CLionProjects/DynamicRRT/cmake-build-default-gcc --target all -- -j 8
[ 14%] Building CXX object CMakeFiles/DynamicRRT.dir/Obstacles.cpp.o
[ 14%] Building CXX object CMakeFiles/DynamicRRT.dir/utilities.cpp.o
[ 35%] Building CXX object CMakeFiles/DynamicRRT.dir/rrt_star.cpp.o
[ 35%] Building CXX object CMakeFiles/DynamicRRT.dir/macro_rrt_star.cpp.o
[ 35%] Building CXX object CMakeFiles/DynamicRRT.dir/Nodes.cpp.o
[ 42%] Building CXX object CMakeFiles/DynamicRRT.dir/main.cpp.o
[ 50%] Building CXX object CMakeFiles/DynamicRRT.dir/tree.cpp.o
[ 57%] Building CXX object CMakeFiles/DynamicRRT.dir/collisions.cpp.o
[ 64%] Building CXX object CMakeFiles/DynamicRRT.dir/dynamic_rrt_star.cpp.o
[ 71%] Building CXX object CMakeFiles/DynamicRRT.dir/trajectory.cpp.o
[ 78%] Building CXX object CMakeFiles/DynamicRRT.dir/transformer.cpp.o
[ 85%] Building CXX object CMakeFiles/DynamicRRT.dir/print_utilities.cpp.o
[ 92%] Building CXX object CMakeFiles/DynamicRRT.dir/random_utilities.cpp.o
[100%] Linking CXX executable bin/DynamicRRT
ld: library not found for -lnlopt
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bin/DynamicRRT] Error 1
make[1]: *** [CMakeFiles/DynamicRRT.dir/all] Error 2
make: *** [all] Error 2
link_directories(/Users/brandon/Extern/nlopt_install/include/ )
The library to link with is likely not in the include directory with the header files. It's more likely they're in a lib directory:
link_directories(/Users/brandon/Extern/nlopt_install/lib)
I want to import spdlog in my project using CMake. And I use VS Code.
But my code doesn't work well. I think I don't have any problem in my code because I copy and paste all professor's code.
I think that it is simple setting error, but I don't know the solution.
CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
set(PROJECT_NAME cmake_project_example)
set(CMAKE_CXX_STANDARD 17)
project(${PROJECT_NAME})
add_executable(${PROJECT_NAME} src/main.cpp)
include(ExternalProject)
set(DEP_INSTALL_DIR ${PROJECT_BINARY_DIR}/install)
set(DEP_INCLUDE_DIR ${DEP_INSTALL_DIR}/include)
set(DEP_LIB_DIR ${DEP_INSTALL_DIR}/lib)
ExternalProject_Add(
dep-spdlog
GIT_REPOSITORY "https://github.com/gabime/spdlog.git"
GIT_TAG "v1.x"
GIT_SHALLOW 1
UPDATE_COMMAND ""
PATCH_COMMAND ""
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${DEP_INSTALL_DIR}
TEST_COMMAND ""
)
set(DEP_LIST ${DEP_LIST} dep-spdlog)
set(DEP_LIBS ${DEP_LIBS} spdlog$<$<CONFIG:Debug>:d>)
target_include_directories(${PROJECT_NAME} PUBLIC ${DEP_INCLUDE_DIR})
target_link_directories(${PROJECT_NAME} PUBLIC ${DEP_LIB_DIR})
target_link_libraries(${PROJECT_NAME} PUBLIC ${DEP_LIBS})
add_dependencies(${PROJECT_NAME} ${DEP_LIST})
main.cpp
#include <spdlog/spdlog.h>
int main(int argc, const char** argv) {
SPDLOG_INFO("Hello, world!");
return 0;
}
Heres the output:
build Output
[proc] Executing command: D:\Program\CMake\bin\cmake.EXE --build d:/Project/real_cmake/build --config Debug --target all -j 26 --
[build] [ 9%] Performing build step for 'dep-spdlog'
[build] [ 80%] Built target spdlog
[build] [ 90%] Building CXX object example/CMakeFiles/example.dir/example.cpp.obj
[build] In file included from D:/Project/real_cmake/build/dep-spdlog-prefix/src/dep-spdlog/include/spdlog/sinks/udp_sink.h:10,
[build] from D:\Project\real_cmake\build\dep-spdlog-prefix\src\dep-spdlog\example\example.cpp:243:
[build] D:/Project/real_cmake/build/dep-spdlog-prefix/src/dep-spdlog/include/spdlog/details/udp_client-windows.h: In constructor 'spdlog::details::udp_client::udp_client(const string&, uint16_t)':
# **[build] D:/Project/real_cmake/build/dep-spdlog-prefix/src/dep-spdlog/include/spdlog/details/udp_client-windows.h:67:13: error: 'InetPtonA' was not declared in this scope <<<<<< I think this error is critical
# **[build] if (InetPtonA(PF_INET, host.c_str(), &addr_.sin_addr.s_addr) != 1)
[build] ^~~~~~~~~
[build] D:/Project/real_cmake/build/dep-spdlog-prefix/src/dep-spdlog/include/spdlog/details/udp_client-windows.h:67:13: note: suggested alternative: 'GetPropA'
[build] if (InetPtonA(PF_INET, host.c_str(), &addr_.sin_addr.s_addr) != 1)
[build] ^~~~~~~~~
[build] GetPropA
[build] mingw32-make.exe[5]: *** [example\CMakeFiles\example.dir\build.make:76: example/CMakeFiles/example.dir/example.cpp.obj] Error 1
[build] mingw32-make.exe[4]: *** [CMakeFiles\Makefile2:125: example/CMakeFiles/example.dir/all] Error 2
[build] mingw32-make.exe[3]: *** [Makefile:155: all] Error 2
[build] mingw32-make.exe[2]: *** [CMakeFiles\dep-spdlog.dir\build.make:86: dep-spdlog-prefix/src/dep-spdlog-stamp/dep-spdlog-build] Error 2
[build] mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:110: CMakeFiles/dep-spdlog.dir/all] Error 2
[build] mingw32-make.exe: *** [Makefile:90: all] Error 2
[proc] The command: D:\Program\CMake\bin\cmake.EXE --build d:/Project/real_cmake/build --config Debug --target all -j 26 -- exited with code: 2
[build] Build finished with exit code 2
I tried searching the error on internet, but I can't find any information for this problem. I don't have any knowledge about CMake and spdlog.
So I have a directory that's formatted as follows:
Project:
- src
- a.cpp
- b.cpp
- c.cpp
- include
- h.cpp
- h.hpp
How would I get CMake to include h.hpp in the files in the source folder? I tried doing include_directories(include) but CMake is still unable to find the file. I also tried changing the include directive in a.cpp to #include "../include/h.hpp". However, none of these solutions have worked.
EDIT:
The output is:
[build] Consolidate compiler generated dependencies of target a
[build] Consolidate compiler generated dependencies of target c
[build] Consolidate compiler generated dependencies of target b
[build] [ 16%] Building CXX object CMakeFiles/b.dir/src/b.cpp.o
[build] [ 33%] Building CXX object CMakeFiles/c.dir/src/c.cpp.o
[build] [ 50%] Building CXX object CMakeFiles/a.dir/src/a.cpp.o
[build] [ 66%] Linking CXX executable a
[build] [ 83%] Linking CXX executable c
[build] [100%] Linking CXX executable b
[build] /usr/bin/ld: CMakeFiles/a.dir/src/a.cpp.o: in function `func(...)':
[build] ../a.cpp:55: undefined reference to `func(...)'
[build] /usr/bin/ld: a.cpp:58: undefined reference to `func(...)'
Note that func is a function with an implementation provided in h.cpp.
CMakeLists.txt:
cmake_minimum_required(VERSION 3.17)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake
CACHE STRING "Vcpkg toolchain file")
project(proj)
find_package(fmt CONFIG REQUIRED)
find_package(CUDAToolkit REQUIRED)
link_libraries(
fmt::fmt CUDA::nvrtc CUDA::cuda_driver CUDA::cudart
)
include_directories(include)
add_executable(a ${CMAKE_CURRENT_SOURCE_DIR}/src/a.cpp)
add_executable(b ${CMAKE_CURRENT_SOURCE_DIR}/src/b.cpp)
add_executable(c ${CMAKE_CURRENT_SOURCE_DIR}/src/c.cpp)
You should add h.cpp as a source for each executable that uses functions from h.hpp:
add_executable(a ${CMAKE_CURRENT_SOURCE_DIR}/src/a.cpp ${CMAKE_CURRENT_SOURCE_DIR}/include/h.cpp)
add_executable(b ${CMAKE_CURRENT_SOURCE_DIR}/src/b.cpp ${CMAKE_CURRENT_SOURCE_DIR}/include/h.cpp)
add_executable(c ${CMAKE_CURRENT_SOURCE_DIR}/src/c.cpp ${CMAKE_CURRENT_SOURCE_DIR}/include/h.cpp)
As you have said,
func is a function with an implementation provided in h.cpp
so you need to add that implementation to your executables
I have searched various forums and cannot find a solution to my problem.
I'm trying to write unit tests of a function in a C file. I'm using google test library.
Although I follow the guides, the project doesn't compile properly.
Tests written in C ++ do not see functions in C file. (undefined reference)
Below I am attaching my files, maybe someone will notice where I made a mistake. I'm out of ideas.
pir_driver.h
#ifndef PIR_DRIVER_H_
#define PIR_DRIVER_H_
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdint.h>
uint32_t xTaskGetTickCount();
#ifdef __cplusplus
} /* extern "C" */
#endif
pir_driver.c
#include "pir_driver.h"
uint32_t xTaskGetTickCount()
{
return 1000;
}
pir_test.cpp
#include <gtest/gtest.h>
#include "../pir_driver.h"
TEST(PIR_Timer_Test, Start)
{
uint32_t test = xTaskGetTickCount() * 2;
EXPECT_EQ(test, test);
}
Project root CMakeLists.txt
cmake_minimum_required(VERSION 3.8)
set(This pir_driver)
project(${This} C CXX)
include(Dart)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
enable_testing()
add_subdirectory(googletest)
set(Headers
pir_driver.h
)
set(Source
pir_driver.c
)
add_library(${This} STATIC ${Sources} ${Headers})
set_target_properties(${This} PROPERTIES LINKER_LANGUAGE C)
add_subdirectory(test)
test CMakeLists.txt
cmake_minimum_required(VERSION 3.8)
set(This pir_test)
set(Sources pir_test.cpp )
add_executable(${This} ${Sources})
set_target_properties(${This} PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(${This} PUBLIC pir_driver gtest_main )
add_test( NAME ${This} COMMAND ${This})
Compile log:
[proc] Wykonywanie polecenia: "C:\Program Files\CMake\bin\cmake.EXE" --build c:/Users/xxx/ansi_c_projects/pir_test/build --config Debug --target all -- -j 10
[build] [ 14%] Linking C static library libpir_driver.a
[build] [ 28%] Building CXX object googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.obj
[build] [ 28%] Built target pir_driver
[build] [ 42%] Linking CXX static library ..\lib\libgtestd.a
[build] [ 42%] Built target gtest
[build] [ 57%] Building CXX object googletest/CMakeFiles/gtest_main.dir/src/gtest_main.cc.obj
[build] [ 71%] Linking CXX static library ..\lib\libgtest_maind.a
[build] [ 71%] Built target gtest_main
[build] [ 85%] Building CXX object test/CMakeFiles/pir_test.dir/pir_test.cpp.obj
[build] [100%] Linking CXX executable pir_test.exe
[build] CMakeFiles\pir_test.dir/objects.a(pir_test.cpp.obj): In function `PIR_Timer_Test_Start_Test::TestBody()':
[build] C:/Users/xxx/ansi_c_projects/pir_test/test/pir_test.cpp:13: undefined reference to `xTaskGetTickCount'
[build] collect2.exe: error: ld returned 1 exit status
[build] mingw32-make.exe[2]: *** [test\CMakeFiles\pir_test.dir\build.make:108: test/pir_test.exe] Error 1
[build] mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:1004: test/CMakeFiles/pir_test.dir/all] Error 2
[build] mingw32-make.exe: *** [Makefile:113: all] Error 2
The reason it doesn't work is that you have a typo in the main CMakeLists.txt: You define the variable Source, but use the variable Sources when populating the sources of the pir_driver target. Consequently the .c file isn't compiled and the linker can't find the symbol defined within.
The missing .c file is also the reason why you needed to manually set the linker language in the first place. Once you add the source file you can remove the set_target_properties(${This} PROPERTIES LINKER_LANGUAGE C) line as CMake will figure it out itself based on the extensions of the source files.
To avoid such problems in the future you can use
add_library(pir_driver STATIC)
target_sources(pir_driver
PRIVATE
pir_driver.h
pir_driver.c
)
instead of CMake variables to collect sources and headers in CMake 3.11 and later.
I've been writing a compiler using LLVM as the backend. The CMake files I've written so far have worked on Linux, but I haven't had any luck on Windows. The project is split into a library and "driver" executable with their own CMakeLists.txt in separate subdirectories.
The top level CMakeLists.txt looks like this:
cmake_minimum_required (VERSION 3.7.0)
project (compiler)
set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_EXTENSIONS OFF)
find_package (LLVM REQUIRED CONFIG)
message (STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message (STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
include_directories (${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
add_subdirectory (Compiler_Lib)
add_subdirectory (Compiler_exe)
The CMakeLists.txt for the library:
cmake_minimum_required (VERSION 3.7.0)
add_library (compiler_lib
AST.cpp
AST.h
parser.cpp
parser.h
scanner.cpp
scanner.h
token.cpp
token.h
visualizer.cpp
visualizer.h
codegen.cpp
codegen.h)
target_include_directories (compiler_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(compiler_lib LLVM)
And the CMakeLists.txt for the executable (which is where linking to the libraries fails):
cmake_minimum_required (VERSION 3.7.0)
project (compiler_exe)
add_executable (compiler_exe Compiler_exe.cpp getopt.h getopt.cpp)
target_link_libraries (compiler_exe LINK_PUBLIC LLVM compiler_lib)
I run the command "c:\Program Files\CMake\bin\cmake.exe" .. -G"MinGW Makefiles" -DCMAKE_PREFIX_PATH=C:\Users\James\llvm+clang-7.0.0-win64-msvc-release where C:\Users\James\llvm+clang-7.0.0-win64-msvc-release is the path to prebuilt LLVM libraries. However, running mingw32-make afterwards fails with the output
Scanning dependencies of target compiler_lib
[ 10%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/AST.cpp.obj
[ 20%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/parser.cpp.obj
[ 30%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/scanner.cpp.obj
[ 40%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/token.cpp.obj
[ 50%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/visualizer.cpp.obj
[ 60%] Building CXX object Compiler_Lib/CMakeFiles/compiler_lib.dir/codegen.cpp.obj
[ 70%] Linking CXX static library libcompiler_lib.a
[ 70%] Built target compiler_lib
Scanning dependencies of target compiler_exe
[ 80%] Building CXX object Compiler_exe/CMakeFiles/compiler_exe.dir/Compiler_exe.cpp.obj
[ 90%] Building CXX object Compiler_exe/CMakeFiles/compiler_exe.dir/getopt.cpp.obj
[100%] Linking CXX executable compiler_exe.exe
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: cannot find -lLLVM
collect2.exe: error: ld returned 1 exit status
Compiler_exe\CMakeFiles\compiler_exe.dir\build.make:102: recipe for target 'Compiler_exe/compiler_exe.exe' failed
mingw32-make[2]: *** [Compiler_exe/compiler_exe.exe] Error 1
CMakeFiles\Makefile2:176: recipe for target 'Compiler_exe/CMakeFiles/compiler_exe.dir/all' failed
mingw32-make[1]: *** [Compiler_exe/CMakeFiles/compiler_exe.dir/all] Error 2
Makefile:82: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
This is the first time I've used CMake so I could have missed something obvious, but as I say it seems to work on Linux.
For the linking to succeed two things need to be true:
1) the file libLLVM.a needs to exist
2) that file has to be in a directory in the library search path
There should be a way to get cmake to tell you the list of places it searches for libraries, and you need to find a way to get wherever libLLVM.a exists into that list of dirs.
Apologies for the partial answer, but that's the troubleshooting path...