How to build Clang? - clang

I want to build a program (YCM for VIM) which needs compiled Clang binaries to be linked with. For a reason, I can't use precompiled version which llvm itself offers for download (I've tested it, it doesn't work), so I want to build Clang and then build YCM, both with gcc.
For YCM to be built, I need compiled Clang files in the same way that they are in the precompiled package that llvm offers, that is there should be these folders:
bin docs include lib share
with corresponding files in them.
Now, I can build llvm and Clang with these commands:
mkdir llvm && cd llvm
svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
cd llvm/tools
svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
cd ..
cd ..
mkdir llvm-build && cd llvm-build
../llvm/configure --prefix=/usr/clang_3_4 --enable-optimized --enable-targets=host --disable-compiler-version-checks
make -j 8
after these, I get these folders in my llvm-build folder:
bindings config.log docs include LLVMBuild.cmake Makefile Makefile.config projects test unittests
cmake config.status examples lib llvm.spec Makefile.common Makefile.llvmbuild Release+Asserts tools utils
How can I create the files in the aforementioned way?

I think you should then run sudo make install.
You can also set the configure prefix to a local dir (e.g. somewhere in $HOME) if you don't want it to get copied into the system dirs and needing root access.

Related

How do I install clang-format without root privileges and without installing LLVM?

I have clang-format version 3.8.0 (tags/RELEASE_380/final) in my ~/bin folder on a Fedora machine with no root privileges. It works, but it is very old and I'd like to upgrade. I just want the clang-format tool, so I would like to avoid going through the full installation process for LLVM or clang if I can avoid it. I assume I can avoid it, since my old clang-format works without either of those installed. I don't remember how clang-format got in my ~/bin directory, and I can't figure out how to update it.
The first thing I tried was following this post which said I should be able to download a prebuilt binary from this page (I tried http://releases.llvm.org/6.0.0/clang+llvm-6.0.0-x86_64-linux-gnu-Fedora27.tar.xz), then just set up a symlink to bin/clang-format. This did not work for me. When I type /path/to/bin/clang-format --help I get the error error while loading shared libraries: libtinfo.so.6: cannot open shared object file: No such file or directory.
The next thing I tried is downloading the clang source code and compiling that with
mkdir build && cd build && CC=$(which gcc) CXX=$(which g++) cmake ..
but when I did I got the error
CMake Error at CMakeLists.txt:36 (message):
llvm-config not found -- LLVM_CONFIG-NOTFOUND
Which I guess means I'd need to install the LLVM to go this route?
Any help getting an updated clang-format (vesion 5.0 at minimum) without root access would be appreciated. Bonus points for minimal installation (i.e. no clang or llvm).
=== EDIT ===
By downloading a bunch of different versions of prebuilt binaries, I've discovered that older versions (<4.0) have clang-formats that work out of the box, but at 4.0 and up give the same error about libtinfo. I guess that means I'll have to live with older versions unless I want to go through a painful installation process.
When you download llvm 6.0, make sure the directory structure is as follows:
llvm
|-->tools
|----->clang
|----> tools
|----> extra
If you just want to build clang-format, then you can cd into
llvm-build-dir/tools/clang/tools/extra/clang-format and then execute make -j8 all
later you can make a symbolic link in your /bin folder

run configure to generate shared libraries [Ubuntu]

I'm running a ./configure script and make to build a library. However, only .a libraries are generated. Is there an option to generate shared libs?
It's going to depend on the project you're trying to build. Run
./configure --help
to get a list of all options you can pass to ./configure, there may be a --shared option or something similar.

Issue in installing clang

I'm trying to install clang and llvm as mentioned in this link
http://clang.llvm.org/get_started.html. However I require llvm-config in one of my code. I cannot find llvm-config in /usr/bin directory which has other llvm commands. Does this mean llvm/clang installation is corrupted?
Thanks
svn co http://llvm.org/svn/llvm-project/llvm/branches/release_31/ llvm31
cd llvm31
cd tools
svn co http://llvm.org/svn/llvm-project/cfe/branches/release_31/ clang
cd ..
./configure --enable-optimized --disable-doxygen --prefix=~/llvm31
make
make install

How do you build Xalan-C with Visual Studio 2010?

I can not find proof that it's possible. After 40 hours of driving myself to insanity, I'm left with a situation where I cannot build the Localization project that supposedly builds a header file needed by the poorly named AllInOne project (which builds Xalan-C.lib, natch).
This library is software malpractice writ-large, I am desperate for an answer because it is a dependency in another library that I have no alternative to using.
I have managed to build Xalan-C version 1.11, compatible with the latest version of Xerces-C (v3.1.1), in Visual Studio 2010. I don't know if it is possible with earlier versions, however these are the steps I followed in order to build with version 1.11:
Xerces-C has to be built as a dynamic library to obtain the xerces-c_3_1D.dll file which MsgCreator.exe is dependent on.
Clone the github repository to obtain the source code of Xalan-C version 1.11.
Set the environment variables XERCESCROOT and XALANCROOT in windows (not in Visual Studio).
XERCESCROOT The Xerces-C/C++ installation directory
XALANCROOT The Xalan-C/C++ source directory
Open the Xalan-C solution in VS2010 and build the MsgCreator project.
Copy the xerces-c_3_1D.dll file from the Xerces-C build and place it in the Xalan-C build folder, the same folder where MsgCreator.exe is located.
Now it is possible to generate the "missing" header files (LocalMsgIndex.hpp and LocalMsgData.hpp) that are needed to build the "AllInOne" project.
Run MsgCreator.exe in cmd with the provided path to XalanMsg_en_US.xlf which is located in $(XALANCROOT)\src\xalanc\NLS\en_US and what method to use when building the locale messages.
MsgCreator.exe $(XALANCROOT)\src\xalanc\NLS\en_US\XalanMsg_en_US.xlf -TYPE=inmem
(I used -TYPE=inmem, but check to see what method is best suited for your solution)
The header files are now generated and located in the build directory (where MsgCreator.exe resides). Copy or move them to $(XALANCROOT)\src and they should now be able to be located.
Now build the XalanMsgLib project.
And the last thing to do before the final build is to handle the including of afxres.h in the AllInOne.rc file (located in $(XALANCROOT)\Projects\Win32\Res\AllInOne). Visual Studio Express edition does not contain the MFC library which contains the afxres.h header. I simply changed it to #include "windows.h" instead.
And now it should be possible to build "AllInOne" successfully.
I struggled with this also and this is my recipe (VS2015 but look up the cmake docs for other IDEs)
Note I was specifically targeting xerces 3.2.3 and xalan 1.12. Use git tag to get the versions you need
git clone https://github.com/apache/xerces-c.git
cd xerces-c
git checkout v3.2.3
mkdir build
cd build
cmake .. -BVS2015 -G "Visual Studio 14 2015" -A x64 -DCMAKE_BUILD_TYPE=Debug
cd VS2015
devenv xerces-c.sln /Build Debug /Project ALL_BUILD
Because I use this with another build process that expects things in a certain way:
(assume you set up a target dir env called XERCESBUILD with bin/lib child dirs)
copy src\Debug\*.dll %XERCESBUILD%\bin
copy src\Debug\*.lib %XERCESBUILD%\lib
Then for xalan
git clone https://github.com/apache/xalan-c
cd xalan-c
git checkout Xalan-C_1_12_0
mkdir build
cd build
set PATH=%PATH%;%XERCESBUILD%\bin
cmake .. -BVS2015 -G "Visual Studio 14 2015" -A x64 -DCMAKE_PREFIX_PATH=%JBCRELEASEDIR% -DXALAN_DEBUG=1 -DCMAKE_BUILD_TYPE=Debug -DXerce
sC_LIBRARY_DEBUG=%XERCESBUILD%\lib\xerces-c_3D.lib
cd VS2015
devenv xalan-c.sln /Build Debug /Project ALL_BUILD
Note the xerces-c_3D.lib is specifically the Debug build so remove the D when doing the Release build.

OpenSSL error building Erlang OTP from source

Trying to build a completely self-contained OTP that can be moved around independently of libs installed on a system.
Build OpenSSL 1.0.0d from source as follows:
./config --prefix=<open-ssl-dir>
make
make install
Then OTP R14B03:
./configure --prefix=<erlang-dir> --with-ssl=<open-ssl-dir> --without-termcap
Make of Erlang then fails as follows:
relocation R_X86_64_32 against `OPENSSL_ia32cap_P' can not be used when making a shared object; recompile with -fPIC
We're talking Ubuntu 10.04. Any help greatly appreciated - thanks!
The "can not be used when making a shared object; recompile with -fPIC" would mean SSL is not build with the Position Independent Code flag. This is needed for building it as a Dynamic Shared Object (DSO). This is probably needed by Erlang build process. Example build:
$ tar zxvf openssl-0.x.tar.gz
$ cd openssl-x
$ sh config shared -fPIC
$ make
$ sudo make install
For ppc64le:
./configure --prefix=/home/huaxin/huaxin/toolsInstalled/ --build=ppc64le CFLAGS="-D_GNU_SOURCE -DOPENSSL_NO_EC=1"
I suggest that you build on a VM where you have sudo permissions. Then build libraries like OpenSSL using --prefix=/usr so that make install puts them in the usual system library.
Then build your tool, in this case Erlang, using -rpath. Then use ldd to find all library dependencies for Erlang and any ports (C extensions) and copy those into Erlangs lib directory. Check all binaries and libraries with readelf -d to make sure that RPATH is set to $ORIGIN or $ORIGIN/../lib as needed. Use patchelf to fix these things if the linking process is not quite right (or you copied in secondary dependencies of system libraries).
Then use patchelf to set the interpreter for your binaries (not libraries) to point to ld-linux.so.2 in Erlang's lib directory. And then run a test suite using
strace -e open erl ... to make sure that your build is not opening anything in /lib or /usr/lib.
At this point tar it up and it will run on any Linux.
See this question Compiling Python 2.6.6 and need for external packages wxPython, setuptools, etc... in Ubuntu for far more detail on how I built Python in this fashion.

Resources