13

I have access to a shell account at University as a user but with no root privileges. The server is running Ubuntu 8.04 - Hardy. I wish to use Clang as my C compiler for next semester's Unix programming course. GCC is installed but not Clang, and the University's IT dept has, as expected, declined to install Clang on the system.

Is it possible to run Clang from my home directory as user? Presumably I would need to compile from source. I need it to compile only C. I don't need C++ or Obj C for this course.

haziz
  • 12,994
  • 16
  • 54
  • 75

3 Answers3

12

You can use the autotools installation method by running ./configure --prefix=$HOME (or some subdirectory of your home directory if you prefer) or by using the CMake build and installation with the CMAKE_INSTALL_PREFIX set to some directory under your home. The former is documented here, merely add the --prefix flag to the configure step, and run 'make install' at the end.

Once installed, put the bin subdirectory of whatever prefix you used into your PATH environment variable, and you should be good-to-go. This is actually the way I use Clang regularly as a developer of Clang and LLVM.

For reference, this is definitely a mode of installation and use that we (Clang developers) want to support. If you run into issues, don't hesitate to file bugs or reach out for support on our email lists or IRC channel (#llvm on irc.oftc.net).

Chandler Carruth
  • 3,011
  • 1
  • 18
  • 26
  • Thanks. Will try it on my home machine just for kicks (I already have Clang 2.9 installed on that machine). My attempt to try it on my user account at the University failed quickly by exceeding my home directory quota on their system. – haziz Jan 02 '12 at 15:13
  • 1
    A good way to dodge that is to do the build in a tmp directory on the machine, and only install into your home directory. The build process for LLVM and Clang produces lots of data. Also, make sure you're doing a release build w/o debug symbols. Otherwise the binaries will be *huge*. Using autotools, `./configure --enable-optimized` should do the trick. – Chandler Carruth Jan 02 '12 at 19:01
  • Thanks. I did install my Clang 3.1/LLVM 3.0 on my Home machine. The resulting directory (including compiler-rt) for the whole build directory is still 500 megs, my limit at the University is 150 megs with 30 megs already full. The package you download from Debian/Ubuntu is still sig smaller (assuming I can trust apt-get's estimate of expanded size) so some of the build is probably unneeded. Not sure which however. BTW, with my home machine how do I get the Clang man pages, they were removed when I uninstalled the 2.9 version of Clang. – haziz Jan 03 '12 at 10:06
  • Would the the bin directory of Release+Asserts be enough or do I need the whole Release+Asserts directory or what? – haziz Jan 03 '12 at 10:18
  • 1
    The problem is almost certainly that you're installing statically linked tools you don't actually need. We should probably move this discussion the the Clang & LLVM bug tracker: http://llvm.org/bugs I would file a bug asking for an install target in the build system which only installs a more minimal set of tools (install-clang or something). You don't want to try copying part of the build tree, that's easy to get wrong. =] – Chandler Carruth Jan 06 '12 at 02:46
  • If you get an error because it is still trying to install stuff in /usr/lib/ocaml/llvm although you have given an install prefix in your home folder, you can get rid of it by disabling the ocaml bindings with "-DLLVM_ENABLE_BINDINGS=OFF". If you actually need the bindings, I don't know what to do. – Wilhem Meignan Sep 16 '20 at 15:11
3

With free software, you can always configure it and (if needed) patch and improve it to suit your needs. However, building a compiler (be it GCC or Clang) requires a lot of resources (disk space, several gigabytes, and also RAM & CPU time), and some of your time and efforts.

Clang building and installation is documented here. I guess that its configure script -assuming it is similar to GCC's one- accepts arguments like --prefix (which you could e.g. set to $HOME/pub). You might need to build also the required dependencies.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
2

As the project appears to use autotools you can alter the installation destination with command line parameters to the configure program (e.g. --prefix=$HOME/clang). Running ./configure --help and reading the INSTALL text file will give you more details.

If not already installed, you also need to build LLVM, which is the parent project (Low Level Virtual Machine) as well. Installation instructions for both are available at the clang website.

mctylr
  • 5,159
  • 20
  • 32