<div dir="ltr"><div><div><div><div><div>Hi,<br><br></div>I am trying to build clang++ 3.5 on a CentOS 5.10 machine.  The system installed gcc is 4.1.2.  I do not have root access on this machine and have therefore built and installed gcc 4.8.2 into a non-system location (/users/sim/packages).  I used the following command to configure clang:<br><br>cmake -DCMAKE_C_COMPILER=/users/sim/packages/gcc/4.8.2/bin/gcc -DCMAKE_CXX_COMPILER=/users/sim/packages/gcc/4.8.2/bin/g++ -DGCC_INSTALL_PREFIX=/users/sim/packages/gcc/4.8.2 -DCMAKE_CXX_LINK_FLAGS="-L/users/sim/packages/gcc/4.8.2/lib64 -Wl,-rpath,/users/sim/packages/gcc/4.8.2/lib64" -DCMAKE_INSTALL_PREFIX=/users/sim/packages/gcc/4.8.2 -DLLVM_ENABLE_ASSERTIONS=ON -DCMAKE_BUILD_TYPE="Release" -DLLVM_TARGETS_TO_BUILD="X86" ../llvm-3.5.0.src/<br><br></div>That worked fine and it created a working clang++ binary.  However, when I use that to compile a C++ program the executable does not have an rpath entry pointing to /users/sim/packages/gcc/4.8.2/lib64:<br><br></div>% clang++ test.cpp<br></div>% ldd a.out<br>        linux-vdso.so.1 =>  (0x00007fffd49fd000)<br>        libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000003577e00000)<br>        libm.so.6 => /lib64/libm.so.6 (0x0000003571600000)<br>        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003577600000)<br>        libc.so.6 => /lib64/libc.so.6 (0x0000003571200000)<br>        /lib64/ld-linux-x86-64.so.2 (0x0000003570e00000)<br><br></div>I want to use C++11 features so presumably I do need to use the newer libstdc++.so library that is installed with gcc 4.8.2.  I know I can fix this by adding -Wl,-rpath,/users/sim/packages/gcc/4.8.2/lib64 to my clang++ command but this shouldn't be necessary.  I would like to know if there is a way to get clang to automatically add these extra linker options when compiled against a version of gcc installed in a non system location.<br><div><br></div><div>I thought this is what the <span>--with-gcc-toolchain</span> option would do (when using configure rather than cmake) but that didn't seem to work.  So far, the only way I have been able to get it to work is by patching Tools.cpp at line 7413 in the function gnutools::Link::ConstructJob:<br><br><div style="margin-left:40px">  Args.AddAllArgs(CmdArgs, options::OPT_L);<br></div><div style="margin-left:40px">  Args.AddAllArgs(CmdArgs, options::OPT_u);<br><br>  const ToolChain::path_list Paths = ToolChain.getFilePaths();<br><br>  for (const auto &Path : Paths)<br>    CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + Path));<br></div><br></div><div>#if USE_MY_PATCH<br></div><div><div style="margin-left:40px">CmdArgs.push_back("-rpath");<br>if (ToolChain.getArch() == llvm::Triple::x86_64)<br>  CmdArgs.push_back("/users/sim/packages/gcc/4.8.2/lib64");<br>else<br>  CmdArgs.push_back("/users/sim/packages/gcc/4.8.2/lib");<br></div>#endif<br></div><div><div style="margin-left:40px"><br>  if (D.IsUsingLTO(Args))<br>    AddGoldPlugin(ToolChain, Args, CmdArgs);<br><br>  if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))<br>    CmdArgs.push_back("--no-demangle");<br><br>  AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs);<br></div><br></div><div>but I can't believe there isn't an easier way.  If clang is built using a non-system libstdc++.so library then shouldn't it automatically add the required -rpath option to use that same library at runtime ?<br><br>--<br></div><div>Glenn Coombs<br><br><br></div><div>P.S.  Please reply to my email address as well as the mailing list as I am not subscribed to this list.<br><br></div></div>