1

On my Raspberry PI computer I have compiled the tcc compiler from source (in /usr/local/src). When I link with a library in /usr/lib, tcc cannot find it so I need to add -L/usr/lib to the tcc command. How do I configure and make tcc to include /usr/lib in its library path?

pi@raspberrypi /usr/local/src/tcc-0.9.26 $ tcc -vv
tcc version 0.9.26 (ARM Hard Float Linux)
install: /usr/local/lib/tcc/
crt:
  /usr/lib/arm-linux-gnueabihf
libraries:
  /usr/lib/arm-linux-gnueabihf
  /lib/arm-linux-gnueabihf
  /usr/local/lib/arm-linux-gnueabihf
include:
  /usr/local/include
  /usr/local/include/arm-linux-gnueabihf
  /usr/include
  /usr/include/arm-linux-gnueabihf
  /usr/local/lib/tcc/include
elfinterp:
  /lib/ld-linux-armhf.so.3
August Karlstrom
  • 10,773
  • 7
  • 38
  • 60

2 Answers2

2

This is a configuration option when compiling tcc itself. If you want to use binary tcc distribution, you will have to continue using the -L option.

However, compiling tcc yourself should be very easy. These are the rough steps:

% git clone git://repo.or.cz/tinycc.git 
% cd tinycc 
% ./configure --libpaths=/usr/lib
% make

There are more options. See:

% ./configure --help
Usage: configure [options]
Options: [defaults in brackets after descriptions]

Standard options:
  --help                   print this message
  --prefix=PREFIX          install in PREFIX [/usr/local]
  --exec-prefix=EPREFIX    install architecture-dependent files in EPREFIX
                           [same as prefix]
  --bindir=DIR             user executables in DIR [EPREFIX/bin]
  --libdir=DIR             object code libraries in DIR [EPREFIX/lib]
  --tccdir=DIR             installation directory [EPREFIX/lib/tcc]
  --includedir=DIR         C header files in DIR [PREFIX/include]
  --sharedir=DIR           documentation root DIR [PREFIX/share]
  --docdir=DIR             documentation in DIR [SHAREDIR/doc/tcc]
  --mandir=DIR             man documentation in DIR [SHAREDIR/man]
  --infodir=DIR            info documentation in DIR [SHAREDIR/info]

Advanced options (experts only):
  --source-path=PATH       path of source code [/Users/miki/projects/tinycc-so]
  --cross-prefix=PREFIX    use PREFIX for compile tools []
  --sysroot=PREFIX         prepend PREFIX to library/include paths []
  --cc=CC                  use C compiler CC [gcc]
  --extra-cflags=          specify compiler flags [-Wall -g -O2]
  --extra-ldflags=         specify linker options []
  --strip-binaries         strip symbol tables from resulting binaries
  --disable-static         make libtcc.so instead of libtcc.a
  --disable-rpath          disable use of -rpath with the above
  --with-libgcc            use /lib/libgcc_s.so.1 instead of libtcc.a
  --enable-mingw32         build windows version on linux with mingw32
  --enable-cygwin          build windows version on windows with cygwin
  --enable-cross           build cross compilers
  --enable-assert          enable debug assertions
  --with-selinux           use mmap for exec mem [needs writable /tmp]
  --sysincludepaths=...    specify system include paths, colon separated
  --libpaths=...           specify system library paths, colon separated
  --crtprefix=...          specify locations of crt?.o, colon separated
  --elfinterp=...          specify elf interpreter

You will probably also want to install tcc into the configured directories.

% make install
mikijov
  • 1,552
  • 24
  • 37
  • As far as I know setting `--libdir` this way will replace /usr/local/lib with /usr/lib. What I would like to do is to add /usr/lib to the library search path. – August Karlstrom Sep 05 '13 at 08:57
  • Even if I configure with `--libdir=/usr/lib` I still need the -L option and I get the same output from `tcc -vv`. – August Karlstrom Sep 05 '13 at 09:16
  • My apologies. The parameter should be --libpaths and not --libdir. They indeed have different meaning. I have corrected my answer accordingly. – mikijov Sep 05 '13 at 12:51
  • Unfortunately, setting libpaths doesn't work either. When I run `make test` the first test fails with "undefined symbol '__libc_csu_fini'". – August Karlstrom Sep 05 '13 at 19:35
0

It turns out that we need to use the libpaths option and also specify the default library directories (output from tcc -vv). We can also add the standard directories /lib and /usr/local/lib:

# ./configure --libpaths=/usr/local/lib/arm-linux-gnueabihf:/lib/arm-linux-gnueabihf:/usr/lib/arm-linux-gnueabihf:/usr/local/lib:/lib:/usr/lib
August Karlstrom
  • 10,773
  • 7
  • 38
  • 60