Issue
I'm following this guide on how to make a front end action for clang, working on a Fedora 38 system.
After some trial and error I arrived at this cmake file for the example (the one provided in the guide doesn't work for me as-is). I'm not an expert on cmake so there could be some mistakes or redundancies in there of course.
cmake_minimum_required(VERSION 3.3.0)
project(clang-test VERSION 0.1.0 LANGUAGES C CXX)
find_package(Clang REQUIRED HINTS "${CLANG_CMAKE_PATH}")
include(AddLLVM)
find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_PATH}")
include("/usr/lib64/cmake/clang/AddClang.cmake")
include_directories(SYSTEM "${LLVM_INCLUDE_DIRS};${CLANG_INCLUDE_DIRS}")
set(LLVM_LINK_COMPONENTS
Support
)
add_clang_executable(clang-test clang-test.cpp)
target_link_libraries(clang-test
PRIVATE
clangAST
clangBasic
clangFrontend
clangSerialization
clangTooling
)
set(CMAKE_VERBOSE_MAKEFILE on)
clang-test.cpp
just contains the source from the guide.
Now my problem is this, when I call make
I get the following output:
[ 50%] Linking CXX executable clang-test
/usr/bin/cmake -E cmake_link_script CMakeFiles/clang-test.dir/link.txt --verbose=1
/usr/bin/clang++ -g -rdynamic -Wl,-rpath-link, -Wl,--gc-sections "CMakeFiles/clang-test.dir/clang-test.cpp.o" -o clang-test -Wl,-rpath,"\$ORIGIN/../lib64:/usr/lib64" /usr/lib64/libLLVM-16.so -lclangAST -lclangBasic -lclangFrontend -lclangSerialization -lclangTooling
/usr/bin/ld: cannot find -lclangAST: No such file or directory
/usr/bin/ld: cannot find -lclangBasic: No such file or directory
/usr/bin/ld: cannot find -lclangFrontend: No such file or directory
/usr/bin/ld: cannot find -lclangSerialization: No such file or directory
/usr/bin/ld: cannot find -lclangTooling: No such file or directory
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [CMakeFiles/clang-test.dir/build.make:101: clang-test] Error 1
make[2]: Leaving directory '/home/xxx/projects/clang-test/build'
make[1]: *** [CMakeFiles/Makefile2:221: CMakeFiles/clang-test.dir/all] Error 2
make[1]: Leaving directory '/home/xxx/projects/clang-test/build'
make: *** [Makefile:114: all] Error 2
Using dnf
I have installed clang
, clang-devel
, clang-libs
, clang-tools-extra
and clang-tools-extra-devel
. I have tried variants of find / -print | grep -i libClang
to see if the libraries exist, but either I'm searching for the wrong thing or they don't exist on my system.
Which package should I install to get the correct libraries on my system? Or do I need to build clang from source if I want to build a front end action or plugin on Fedora? Or did I just go "blind" and I'm missing something trivial?
Solution
It turns out that on my Fedora system the library is called /usr/lib64/libclang-cpp.so
, so changing the link target in the makefile as follows solves the issue.
target_link_libraries(clang-test PRIVATE clang-cpp)
Answered By - AntimatterHedgehog Answer Checked By - Terry (WPSolving Volunteer)