xeus-cling icon indicating copy to clipboard operation
xeus-cling copied to clipboard

Compilation issues

Open ocaisa opened this issue 3 years ago • 5 comments

I just thought I would post here a patch I had to make to get the package to compile using Cling built with the instructions given at https://root.cern/cling/cling_build_instructions/

diff -Naur xeus-cling-0.12.1.orig/src/xmagics/executable.cpp xeus-cling-0.12.1/src/xmagics/executable.cpp
--- xeus-cling-0.12.1.orig/src/xmagics/executable.cpp   2021-03-16 14:48:10.000000000 +0000
+++ xeus-cling-0.12.1/src/xmagics/executable.cpp        2021-04-29 12:10:03.955599380 +0000
@@ -131,7 +131,7 @@
 
         // Generate relocations suitable for dynamic linking.
         auto CodeGenOpts = CI->getCodeGenOpts();
-        CodeGenOpts.RelocationModel = "pic";
+        CodeGenOpts.RelocationModel = llvm::Reloc::PIC_;
 
         // Enable debug information if requested.
         if (EnableDebugInfo)
@@ -187,7 +187,7 @@
         llvm::sys::path::append(Compiler, "bin", "clang++");
 
         // Construct arguments to linker command.
-        llvm::SmallVector<const char*, 16> Args;
+        llvm::SmallVector<llvm::StringRef, 16> Args;
         Args.push_back(Compiler.c_str());
         Args.push_back(ObjectFile.c_str());
         for (auto& O : LinkerOptions)
@@ -196,7 +196,7 @@
         }
         Args.push_back("-o");
         Args.push_back(ExeFile.c_str());
-        Args.push_back(NULL);
+        // Args.push_back(NULL);
 
         // Redirect output and error streams from linker.
         llvm::SmallString<64> OutputFile, ErrorFile;
@@ -207,11 +207,11 @@
 
         llvm::StringRef OutputFileStr(OutputFile);
         llvm::StringRef ErrorFileStr(ErrorFile);
-        const llvm::StringRef* Redirects[] = {nullptr, &OutputFileStr,
-                                              &ErrorFileStr};
-
+        //const llvm::StringRef* Redirects[] = {nullptr, &OutputFileStr,
+        //                                      &ErrorFileStr};
+        const clang::Optional<llvm::StringRef> Redirects[] = {llvm::NoneType::None, OutputFileStr, ErrorFileStr};
         // Finally run the linker.
-        int ret = llvm::sys::ExecuteAndWait(Compiler, Args.data(), nullptr,
+        int ret = llvm::sys::ExecuteAndWait(Compiler, Args, llvm::NoneType::None,
                                             Redirects);
 
         // Read back output and error streams.

Hopefully this is useful for someone who runs into the problems I did. Feel free to close to issue, I just put it here to document this.

ocaisa avatar Apr 29 '21 12:04 ocaisa

Thank you @ocaisa. For version 0.12.0 I ended up doing this:

diff --git a/src/xmagics/executable.cpp b/src/xmagics/executable.cpp
index d63a024..db358f4 100644
--- a/src/xmagics/executable.cpp
+++ b/src/xmagics/executable.cpp
@@ -131,7 +131,7 @@ namespace xcpp
 
         // Generate relocations suitable for dynamic linking.
         auto CodeGenOpts = CI->getCodeGenOpts();
-        CodeGenOpts.RelocationModel = "pic";
+        CodeGenOpts.RelocationModel = llvm::Reloc::PIC_;
 
         // Enable debug information if requested.
         if (EnableDebugInfo)
@@ -187,16 +187,15 @@ namespace xcpp
         llvm::sys::path::append(Compiler, "bin", "clang++");
 
         // Construct arguments to linker command.
-        llvm::SmallVector<const char*, 16> Args;
-        Args.push_back(Compiler.c_str());
-        Args.push_back(ObjectFile.c_str());
+        llvm::SmallVector<llvm::StringRef, 16> Args;
+        Args.push_back(Compiler);
+        Args.push_back(ObjectFile);
         for (auto& O : LinkerOptions)
         {
-            Args.push_back(O.c_str());
+            Args.push_back(O);
         }
         Args.push_back("-o");
-        Args.push_back(ExeFile.c_str());
-        Args.push_back(NULL);
+        Args.push_back(ExeFile);
 
         // Redirect output and error streams from linker.
         llvm::SmallString<64> OutputFile, ErrorFile;
@@ -207,11 +206,11 @@ namespace xcpp
 
         llvm::StringRef OutputFileStr(OutputFile);
         llvm::StringRef ErrorFileStr(ErrorFile);
-        const llvm::StringRef* Redirects[] = {nullptr, &OutputFileStr,
-                                              &ErrorFileStr};
+        const llvm::Optional<llvm::StringRef> Redirects[] = {llvm::None, OutputFileStr,
+                                                             ErrorFileStr};
 
         // Finally run the linker.
-        int ret = llvm::sys::ExecuteAndWait(Compiler, Args.data(), nullptr,
+        int ret = llvm::sys::ExecuteAndWait(Compiler, Args, llvm::None,
                                             Redirects);
 
         // Read back output and error streams.

dimitry-ishenko avatar Oct 12 '21 19:10 dimitry-ishenko

I too experience this issue here on NixOS and I can confirm that @dimitry-ishenko's patch partially fixes the build for me with xeus-cling version 0.13.0. But I the compilation still fails for me with:

xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Code
Generator::forgetGlobal(llvm::GlobalValue*)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Comp
oundStmt::CompoundStmt(clang::ASTContext const&, llvm::ArrayRef<clang::Stmt*>, clang::SourceLocation, clang::SourceLocation)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Code
Generator::StartModule(llvm::StringRef, llvm::LLVMContext&, clang::CodeGenOptions const&)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Stmt
::printPretty(llvm::raw_ostream&, clang::PrinterHelper*, clang::PrintingPolicy const&, unsigned int) const'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Decl
RefExpr::getLocStart() const'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Crea
teASTDumper(llvm::StringRef, bool, bool, bool)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Pars
er::ParseTypeName(clang::SourceRange*, clang::Declarator::TheContext, clang::AccessSpecifier, clang::Decl**, clang::ParsedAttributes*)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Sema
::LookupTemplateName(clang::LookupResult&, clang::Scope*, clang::CXXScopeSpec&, clang::QualType, bool, bool&)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Stmt
::getLocEnd() const'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Comp
oundStmt::setStmts(clang::ASTContext const&, llvm::ArrayRef<clang::Stmt*>)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Sour
ceManager::invalidateCache(clang::FileID)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `llvm::opt::
OptTable::PrintHelp(llvm::raw_ostream&, char const*, char const*, bool) const'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `llvm::Memor
yBuffer::getNewUninitMemBuffer(unsigned long, llvm::Twine const&)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::File
Manager::getBufferForFile(llvm::StringRef)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Prep
rocessor::removeMacro(clang::IdentifierInfo*, clang::MacroDirective*)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `llvm::raw_o
stream::handle()'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Code
Generator::forgetDecl(clang::GlobalDecl const&, llvm::StringRef)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Sour
ceManager::createMemBufferContentCache(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `llvm::sys::
fs::createUniqueFile(llvm::Twine const&, llvm::SmallVectorImpl<char>&)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Diag
nosticsEngine::Reset(bool)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Attr
ibuteFactory::reclaimPool(clang::AttributeList*)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Qual
Type::getAsString[abi:cxx11](clang::Type const*, clang::Qualifiers)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Prep
rocessor::printMacros(llvm::raw_ostream&) const'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Prep
rocessor::LookupFile(clang::SourceLocation, llvm::StringRef, bool, clang::DirectoryLookup const*, clang::FileEntry const*, clang::DirectoryL
ookup const*&, llvm::SmallVectorImpl<char>*, llvm::SmallVectorImpl<char>*, clang::ModuleMap::KnownHeader*, bool*, bool, bool, bool)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Stmt
::getLocStart() const'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Prep
rocessor::printMacro(clang::IdentifierInfo const*, clang::MacroDirective const*, llvm::raw_ostream&) const'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Pars
er::ParseUnqualifiedId(clang::CXXScopeSpec&, bool, bool, bool, bool, clang::OpaquePtr<clang::QualType>, clang::SourceLocation&, clang::Unqua
lifiedId&)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Pars
er::Parser(clang::Preprocessor&, clang::Sema&, bool, bool)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Over
loadCandidateSet::BestViableFunction(clang::Sema&, clang::SourceLocation, clang::OverloadCandidate*&, bool)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Temp
lateSpecializationType::PrintTemplateArgumentList(llvm::raw_ostream&, llvm::ArrayRef<clang::TemplateArgumentLoc>, clang::PrintingPolicy cons
t&)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Code
Generator::print(llvm::raw_ostream&)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Sema
::PushExpressionEvaluationContext(clang::Sema::ExpressionEvaluationContext, clang::Decl*, bool)'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::ASTC
ontext::getElaboratedType(clang::ElaboratedTypeKeyword, clang::NestedNameSpecifier*, clang::QualType) const'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Decl
RefExpr::getLocEnd() const'
xeus-cling> /nix/store/lbxfixyw1yk099pjyaiy3xj5dl7kxm1g-binutils-2.35.2/bin/ld: libxeus-cling.so.0.13.0: undefined reference to `clang::Diag
nosticsEngine::DiagnosticsEngine(llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs>, clang::DiagnosticOptions*, clang::DiagnosticConsumer*, bool
xeus-cling> clang-7: error: linker command failed with exit code 1 (use -v to see invocation)

doronbehar avatar Dec 15 '21 21:12 doronbehar

@doronbehar in case you are interested, I do have .deb packages for xeus-cling here:

https://launchpad.net/~ppa-verse/+archive/ubuntu/cling

and Debian source with patches here:

https://salsa.debian.org/dimitry-ishenko/xeus-cling

dimitry-ishenko avatar Dec 15 '21 23:12 dimitry-ishenko

Thanks for the links @dimitry-ishenko, we have issues updating cling from 0.7 to 0.9 here on NixOS so that holds us from compiling xeus-cling as well.

doronbehar avatar Dec 16 '21 07:12 doronbehar

@doronbehar I understand. It's a slippery slope. 😅 I had to patch LLVM/Clang 9 first, then cling, then xeus-cling to make them all play nicely with each other.

Patched LLVM/Clang 9: https://salsa.debian.org/dimitry-ishenko/llvm-toolchain-9 Patched cling: https://github.com/dimitry-ishenko-cpp/cling Patched xeus-cling: https://salsa.debian.org/dimitry-ishenko/xeus-cling

Good luck.

dimitry-ishenko avatar Dec 16 '21 16:12 dimitry-ishenko