Undefined symbols for architecture x86_64 when compile newFrontendActionFactory with clang 5.0.

My Code is :

My Code is :

void *threadRun(void *arg)
{
struct threadParam *param = (struct threadParam *) arg;
ClangTool clangTool(*param->cdb, param->taskList);
pthread_mutex_lock(&Global::actionMutex);
unique_ptr factory = newFrontendActionFactory(); // Error happens here
ToolAction
action;
if (factory != NULL) {
action = factory.get();
}
pthread_mutex_unlock(&Global::actionMutex);
if (factory != NULL) {
clangTool.run(action);

}
return (void*)1;
}

===============================================================================================
it can compile and link well in clang 3.7, but when I upgrade clang to 5.0 , it link fails. I don’t know what’s wrong with this;
Please help me out here.Any idea will be appreciated! thanks!!!

ERROR Message :

Undefined symbols for architecture x86_64:
“typeinfo for clang::ASTConsumer”, referenced from:
typeinfo for GodEyesASTConsumer in GodEyes.cpp.o
“typeinfo for clang::ASTFrontendAction”, referenced from:
typeinfo for GodEyesFrontendAction in GodEyes.cpp.o
“typeinfo for clang::tooling::FrontendActionFactory”, referenced from:
typeinfo for std::__1::unique_ptr<clang::tooling::FrontendActionFactory, std::__1::default_deleteclang::tooling::FrontendActionFactory > clang::tooling::newFrontendActionFactory ()::SimpleFrontendActionFactory in GodEyes.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

My CMakeLists.txt is as below:

cmake_minimum_required (VERSION 2.8)

project(main)
set(main_VERSION 3.1)

configure_file (
“${PROJECT_SOURCE_DIR}/config.h.in”
“${PROJECT_SOURCE_DIR}/config.h”
)

set(CMAKE_C_COMPILER “/usr/bin/clang”)
set(CMAKE_CXX_COMPILER “/usr/bin/clang++”)
set(CMAKE_AR “/usr/bin/llvm-ar”)
set(CMAKE_LINKER “/usr/bin/llvm-ld”)
set(CMAKE_NM “/usr/bin/llvm-nm”)
set(CMAKE_OBJDUMP “/usr/bin/llvm-objdump”)
set(CMAKE_RANLIB “/usr/bin/llvm-ranlib”)
set(CLANG_ROOT “/Users/baixx/clang-llvm/build/lib/clang/3.9.0/include”)
set(LLVM_LINK_COMPONENTS support)
set(LLVM_USED_LIBS clangTooling clangBasic clangAST)

Looks like you need to be linking against clangFrontend.

John.