[cfe-dev] How to link against lib/libclang in developing a clang-tools-extra project?

Lou Wynn via cfe-dev cfe-dev at lists.llvm.org
Wed Oct 24 20:13:18 PDT 2018


Hi,

I'm writing a small clang tool in the clang-tools-extra directory by 
using the monorepo. My CMakeList.txt files is as follows:

set(LLVM_LINK_COMPONENTS Support)

add_clang_executable(loop-convert
   LoopConvert.cpp
   )

target_link_libraries(loop-convert
   PRIVATE
   clang
   clangAST
   clangASTMatchers
   clangBasic
   clangFrontend
   clangTooling
   )


When I ran the build command, I got a linker error complaining that 
functions in lib/libclang.so cannot be found:

$ ninja loop-convert
[1/1] Linking CXX executable bin/loop-convert
FAILED: : && /usr/bin/clang++-6.0   -fPIC -fvisibility-inlines-hidden 
-Werror=date-time -Werror=unguarded-availability-new -std=c++11 -Wall 
-Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual 
-Wmissing-field-initializers -pedantic -Wno-long-long 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color 
-fno-common -Woverloaded-virtual -Wno-nested-anon-types -g  
-fuse-ld=lld-6.0 -Wl,--color-diagnostics -Wl,-allow-shlib-undefined 
tools/clang/tools/extra/loop-convert/CMakeFiles/loop-convert.dir/LoopConvert.cpp.o 
-o bin/loop-convert  lib/libLLVMSupport.so.8svn -lpthread 
lib/libclangAST.so.8svn lib/libclangASTMatchers.so.8svn 
lib/libclangBasic.so.8svn lib/libclangFrontend.so.8svn 
lib/libclangTooling.so.8svn -Wl,-rpath,"\$ORIGIN/../lib" && :
/usr/bin/ld.lld-6.0: error: undefined symbol: clang_getCString
 >>> referenced by LoopConvert.cpp:7 
(/home/lu/work/git-repos/llvm-mono/llvm-project/clang-tools-extra/loop-convert/LoopConvert.cpp:7)
 >>> 
tools/clang/tools/extra/loop-convert/CMakeFiles/loop-convert.dir/LoopConvert.cpp.o:(operator<<(std::ostream&, 
CXString const&))

...


It is clear that the lib/libclang.so.8svn is missing from the command 
line invoked by ninja. How can I add it into the build command? The 
"clang" line in the CMakeList.txt file doesn't work.

Thanks.

-- 
Love,
Lou

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181025/1c92c4a3/attachment.html>


More information about the cfe-dev mailing list