Compile Clang 4.0 from source using LLVM_CONFIG

I’m trying to compile clang from source without compiling all the llvm stack
but using a prebuild one and using LLVM_CONFIG to point to it.
I have llvm from http://releases.llvm.org/4.0.0/clang+llvm-4.0.0-debina8.tar.xz
and the clang source from http://releases.llvm.org/4.0.0/cfe-4.0.0.src.tar.xz

After unpacking everything I ran:

cmake -DLLVM_CONFIG=$PWD/../clang+llvm/bin/llvm-config ../clang-src
make -j8

The compilation process goes fine until the liking for clang itself.
Following the error that I got.
Do I miss something?

../../lib/libclangCodeGen.a(BackendUtil.cpp.o): In function (anonymous namespace)::EmitAssemblyHelper::EmitAssemblyWithNewPassManager(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_deletellvm::raw_pwrite_stream >)’: BackendUtil.cpp:(.text._ZN12_GLOBAL__N_118EmitAssemblyHelper30EmitAssemblyWithNewPassManagerEN5clang13BackendActionESt10unique_ptrIN4llvm17raw_pwrite_streamESt14default_deleteIS5_EE+0x12f): undefined reference to llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>::AnalysisManager(bool)'
BackendUtil.cpp:(.text._ZN12_GLOBAL__N_118EmitAssemblyHelper30EmitAssemblyWithNewPassManagerEN5clang13BackendActionESt10unique_ptrIN4llvm17raw_pwrite_streamESt14default_deleteIS5_EE+0x143): undefined reference to llvm::AnalysisManagerllvm::Function::AnalysisManager(bool)‘ BackendUtil.cpp:(.text._ZN12_GLOBAL__N_118EmitAssemblyHelper30EmitAssemblyWithNewPassManagerEN5clang13BackendActionESt10unique_ptrIN4llvm17raw_pwrite_streamESt14default_deleteIS5_EE+0x157): undefined reference to llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>::AnalysisManager(bool)'
BackendUtil.cpp:(.text._ZN12_GLOBAL__N_118EmitAssemblyHelper30EmitAssemblyWithNewPassManagerEN5clang13BackendActionESt10unique_ptrIN4llvm17raw_pwrite_streamESt14default_deleteIS5_EE+0x16b): undefined reference to llvm::AnalysisManagerllvm::Module::AnalysisManager(bool)‘ BackendUtil.cpp:(.text._ZN12_GLOBAL__N_118EmitAssemblyHelper30EmitAssemblyWithNewPassManagerEN5clang13BackendActionESt10unique_ptrIN4llvm17raw_pwrite_streamESt14default_deleteIS5_EE+0x1ab): undefined reference to llvm::PassBuilder::registerModuleAnalyses(llvm::AnalysisManager<llvm::Module>&)'
BackendUtil.cpp:(.text._ZN12_GLOBAL__N_118EmitAssemblyHelper30EmitAssemblyWithNewPassManagerEN5clang13BackendActionESt10unique_ptrIN4llvm17raw_pwrite_streamESt14default_deleteIS5_EE+0x1c4): undefined reference to llvm::PassBuilder::registerCGSCCAnalyses(llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&)‘ BackendUtil.cpp:(.text._ZN12_GLOBAL__N_118EmitAssemblyHelper30EmitAssemblyWithNewPassManagerEN5clang13BackendActionESt10unique_ptrIN4llvm17raw_pwrite_streamESt14default_deleteIS5_EE+0x1dd): undefined reference to llvm::PassBuilder::registerFunctionAnalyses(llvm::AnalysisManager<llvm::Function>&)'
BackendUtil.cpp:(.text._ZN12_GLOBAL__N_118EmitAssemblyHelper30EmitAssemblyWithNewPassManagerEN5clang13BackendActionESt10unique_ptrIN4llvm17raw_pwrite_streamESt14default_deleteIS5_EE+0x1f6): undefined reference to llvm::PassBuilder::registerLoopAnalyses(llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&)‘ BackendUtil.cpp:(.text._ZN12_GLOBAL__N_118EmitAssemblyHelper30EmitAssemblyWithNewPassManagerEN5clang13BackendActionESt10unique_ptrIN4llvm17raw_pwrite_streamESt14default_deleteIS5_EE+0x224): undefined reference to llvm::PassBuilder::crossRegisterProxies(llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::AnalysisManager<llvm::Function>&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::AnalysisManager<llvm::Module>&)'
BackendUtil.cpp:(.text._ZN12_GLOBAL__N_118EmitAssemblyHelper30EmitAssemblyWithNewPassManagerEN5clang13BackendActionESt10unique_ptrIN4llvm17raw_pwrite_streamESt14default_deleteIS5_EE+0x238): undefined reference to llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module<> >>::PassManager(bool)‘ BackendUtil.cpp:(.text._ZN12_GLOBAL__N_118EmitAssemblyHelper30EmitAssemblyWithNewPassManagerEN5clang13BackendActionESt10unique_ptrIN4llvm17raw_pwrite_streamESt14default_deleteIS5_EE+0x2d1): undefined reference to llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module<> >>::operator=(llvm::AnalysisManager<llvm::Module<> >&&)'
BackendUtil.cpp:(.text._ZN12_GLOBAL__N_118EmitAssemblyHelper30EmitAssemblyWithNewPassManagerEN5clang13BackendActionESt10unique_ptrIN4llvm17raw_pwrite_streamESt14default_deleteIS5_EE+0x553): undefined reference to llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module<> >>::run(llvm::Module&, llvm::Module<>&)’ …/…/lib/libclangCodeGen.a(BackendUtil.cpp.o): In function llvm::TargetLibraryAnalysis::Result& llvm::AnalysisManager<llvm::Function>::getResult<llvm::TargetLibraryAnalysis>(llvm::Function&)':
BackendUtil.cpp:(.text._ZN4llvm15AnalysisManagerINS_8FunctionEIEE9getResultINS_21TargetLibraryAnalysisEEERNT_6ResultERS1_[_ZN4llvm15AnalysisManagerINS_8FunctionEIEE9getResultINS_21TargetLibraryAnalysisEEERNT_6ResultERS1_]+0x6f): undefined reference to llvm::AnalysisManagerllvm::Function::getResultImpl(llvm::AnalysisKey*, llvm::Function&)’ …/…/lib/libclangCodeGen.a(BackendUtil.cpp.o): In function llvm::detail::PassModel<llvm::Module, llvm::PrintModulePass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module<> >>::run(llvm::Module&, llvm::Module<>&)':
BackendUtil.cpp:(.text._ZN4llvm6detail9PassModelINS_6ModuleENS_15PrintModulePassENS_17PreservedAnalysesENS_15AnalysisManagerIS2_IEEEIEE3runERS2_RS6_[_ZN4llvm6detail9PassModelINS_6ModuleENS_15PrintModulePassENS_17PreservedAnalysesENS_15AnalysisManagerIS2_IEEEIEE3runERS2_RS6_]+0x30): undefined reference to llvm::PrintModulePass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module<> >&)’ …/…/lib/libclangCodeGen.a(BackendUtil.cpp.o): In function llvm::detail::PassModel<llvm::Module, llvm::BitcodeWriterPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module<> >>::run(llvm::Module&, llvm::Module<>&)':
BackendUtil.cpp:(.text._ZN4llvm6detail9PassModelINS_6ModuleENS_17BitcodeWriterPassENS_17PreservedAnalysesENS_15AnalysisManagerIS2_IEEEIEE3runERS2_RS6_[_ZN4llvm6detail9PassModelINS_6ModuleENS_17BitcodeWriterPassENS_17PreservedAnalysesENS_15AnalysisManagerIS2_IEEEIEE3runERS2_RS6_]+0x30): undefined reference to llvm::BitcodeWriterPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module<> >&)’ …/…/lib/libclangCodeGen.a(BackendUtil.cpp.o): In function llvm::detail::PassModel<llvm::Module, llvm::AlwaysInlinerPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module<> >>::run(llvm::Module&, llvm::Module<>&)':
BackendUtil.cpp:(.text._ZN4llvm6detail9PassModelINS_6ModuleENS_17AlwaysInlinerPassENS_17PreservedAnalysesENS_15AnalysisManagerIS2_IEEEIEE3runERS2_RS6_[_ZN4llvm6detail9PassModelINS_6ModuleENS_17AlwaysInlinerPassENS_17PreservedAnalysesENS_15AnalysisManagerIS2_IEEEIEE3runERS2_RS6_]+0x30): undefined reference to llvm::AlwaysInlinerPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module<> >&)’ …/…/lib/libclangCodeGen.a(BackendUtil.cpp.o): In function llvm::detail::AnalysisResultModel<llvm::Function, llvm::AAManager, llvm::AAResults, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function<> >::Invalidator, true>::invalidate(llvm::Function&, llvm::PreservedAnalyses const&, llvm::AnalysisManager<llvm::Function<> >&)':
BackendUtil.cpp:(.text._ZN4llvm6detail19AnalysisResultModelINS_8FunctionENS_9AAManagerENS_9AAResultsENS_17PreservedAnalysesENS_15AnalysisManagerIS2_IEE11InvalidatorELb1EE10invalidateERS2_RKS5_RS8_[_ZN4llvm6detail19AnalysisResultModelINS_8FunctionENS_9AAManagerENS_9AAResultsENS_17PreservedAnalysesENS_15AnalysisManagerIS2_IEE11InvalidatorELb1EE10invalidateERS2_RKS5_RS8_]+0x30): undefined reference to llvm::AAResults::invalidate(llvm::Function&, llvm::PreservedAnalyses const&, llvm::AnalysisManager<llvm::Function<> >::Invalidator&)' collect2: error: ld returned 1 exit status`

I'm trying to compile clang from source without compiling all the llvm stack
but using a prebuild one and using LLVM_CONFIG to point to it.
I have llvm from http://releases.llvm.org/4.0.0/clang+llvm-4.0.0-debina8.tar.xz
and the clang source from http://releases.llvm.org/4.0.0/cfe-4.0.0.src.tar.xz

Hi,

I just ran into this same issue and posted about it on llvm-dev:

http://lists.llvm.org/pipermail/llvm-dev/2017-May/113313.html

Did you ever find a solution?

-Tom

I'm trying to compile clang from source without compiling all the llvm stack
but using a prebuild one and using LLVM_CONFIG to point to it.
I have llvm from http://releases.llvm.org/4.0.0/clang+llvm-4.0.0-debina8.tar.xz
and the clang source from http://releases.llvm.org/4.0.0/cfe-4.0.0.src.tar.xz

Hi,

I just ran into this same issue and posted about it on llvm-dev:

http://lists.llvm.org/pipermail/llvm-dev/2017-May/113313.html

Did you ever find a solution?

I filed a bug for this failure:

https://bugs.llvm.org/show_bug.cgi?id=33161

There are some work-arounds mentioned in the bug report.

-Tom