Compiling problems: cannot find crt1.o

GccClangLd

Gcc Problem Overview


I have a virtual Debian system which I use to develop.

Today I wanted to try llvm/clang.

After installing clang I can't compile my old c-projects (with gcc). This is the error:

...
/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
collect2: ld returned 1 exit status
...

I uninstalled clang and it still did not work.

Does anyone have any idea how I can fix this?

Gcc Solutions


Solution 1 - Gcc

Debian / Ubuntu

The problem is you likely only have the gcc for your current architecture and that's 64bit. You need the 32bit support files. For that, you need to install them

sudo apt install gcc-multilib

Solution 2 - Gcc

What helped me is to create a symbolic link:

sudo ln -s /usr/lib/x86_64-linux-gnu /usr/lib64

Solution 3 - Gcc

It seems that while you were playing with llvm/clang you(or the package manager) removed previously existing standard C library development package(eglibc on Debian) or maybe you didn't have it installed in the first place, thus you need to reinstall it, now that you reverted back to gcc.

You can do so like this on Debian:

aptitude show libc-dev

Ubuntu:

apt-get install libc-dev

On Ubuntu, if you don't have libc-dev, since I cannot find it on packages.ubuntu.com, you can try installing libc6-dev directly.

Or on Redhat like systems:

> yum install glibc-devel

NB: Although you were briefly answered in the comments, here is an answer just so there is one on record in case someone encounters this one and might be looking for an answer, but not in the comments or the comment is not explicit enough for them.

Solution 4 - Gcc

This is a BUG reported in launchpad, but there is a workaround :

Run this to see where these files are located

$ find /usr/ -name crti*
/usr/lib/x86_64-linux-gnu/crti.o

then add this path to LIBRARY_PATH variable

$ export LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LIBRARY_PATH

Solution 5 - Gcc

After reading the http://wiki.debian.org/Multiarch/LibraryPathOverview that jeremiah posted, i found the gcc flag that works without the symlink:

gcc -B/usr/lib/x86_64-linux-gnu hello.c

So, you can just add -B/usr/lib/x86_64-linux-gnu to the CFLAGS variable in your Makefile.

Solution 6 - Gcc

If you're using Debian's Testing version, called 'wheezy', then you may have been bitten by the move to multiarch. More about Debian's multiarch here: http://wiki.debian.org/Multiarch

Basically, what is happening is various architecture specific libraries are being moved from traditional places in the file system to new architecture specific places. This is why /usr/bin/ld is confused.

You will find crt1.o in both /usr/lib64/ and /usr/lib/i386-linux-gnu/ now and you'll need to tell your toolchain about that. Here is some documentation on how to do that; http://wiki.debian.org/Multiarch/LibraryPathOverview

Note that merely creating a symlink will only give you one architecture and you'd be essentially disabling multiarch. While this may be what you want it might not be the optimal solution.

Solution 7 - Gcc

To get RHEL 7 64-bit to compile gcc 4.8 32-bit programs, you'll need to do two things.

  1. Make sure all the 32-bit gcc 4.8 development tools are completely installed:

     sudo yum install glibc-devel.i686 libgcc.i686 libstdc++-devel.i686 ncurses-devel.i686
    
  2. Compile programs using the -m32 flag

     gcc pgm.c -m32 -o pgm
    

stolen from here : https://stackoverflow.com/questions/23638271/how-to-compile-32-bit-apps-on-64-bit-rhel - I only had to do step 1.

Solution 8 - Gcc

As explained in https://stackoverflow.com/questions/91576/crti-o-file-missing , it's better to use "gcc -print-search-dirs" to find out all the search path. Then create a link as explain above "sudo ln -s" to point to the location of crt1.o

Solution 9 - Gcc

This worked for me with Ubuntu 16.04

$ LIBRARY_PATH=/usr/lib/x86_64-linux-gnu
$ export LIBRARY_PATH

Solution 10 - Gcc

./configure --disable-multilib

works for it

Solution 11 - Gcc

Ran into this on CentOs 5.4. Noticed that lib64 contained the crt*.o files, but lib did not. Installed glibc-devel through yum which installed the i386 bits and this resolved my issue.

Solution 12 - Gcc

Even I got the same compilation error when I was cross compiling i686-cm-linux-gcc.

The below compilation option solved my problem

$ i686-cm-linux-gcc a.c --sysroot=/opt/toolchain/i686-cm-linux-gcc

Note: The sysroot should point to compiler directory where usr/include available

In my case the toolchain is installed at /opt/toolchain/i686-cm-linux-gcc directory and usr/include is also available in the same directory

Solution 13 - Gcc

I solved it as follows:

  1. try to locate ctr1.o and ctri.o files by using find -name ctr1.o

I got the following in my computer: $/usr/lib/i386-linux/gnu

  1. Add that path to PATH (also LIBRARY_PATH) environment variable (in order to see which is the name: type env command in the Terminal):

    $PATH=/usr/lib/i386-linux/gnu:$PATH $export PATH

Solution 14 - Gcc

I had the same problem today, I solved it by installing recommended packages: libc6-dev-mipsel-cross libc6-dev-mipsel-cross, libc-dev-mipsel-cross

This worked:

sudo apt-get install libc6-dev-mipsel-cross

Solution 15 - Gcc

One magic command:

sudo apt install build-essential

Fixed everything for me even on Raspberry Pi.

Solution 16 - Gcc

In my case, the crti.o error was entailed by the execution path configuration from Matlab. For instance, you cannot perform a file if you have not set the path of your execution directory earlier. To do this: File > setPath, add your directory and save.

Solution 17 - Gcc

use gcc -B lib_path_containing_crt?.o

Solution 18 - Gcc

In my case Ubuntu 16.04 I have no crti.o at all:

$ find /usr/ -name crti*

So I install developer libc6-dev package:

sudo apt-get install libc6-dev

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionStefan KellerView Question on Stackoverflow
Solution 1 - GccDmitry PavlenkoView Answer on Stackoverflow
Solution 2 - GccKarel LencView Answer on Stackoverflow
Solution 3 - GccShinnokView Answer on Stackoverflow
Solution 4 - GccUmair RView Answer on Stackoverflow
Solution 5 - GccalexmView Answer on Stackoverflow
Solution 6 - GccjeremiahView Answer on Stackoverflow
Solution 7 - GccbulltoriousView Answer on Stackoverflow
Solution 8 - GcctienpingView Answer on Stackoverflow
Solution 9 - GccNiklas RosencrantzView Answer on Stackoverflow
Solution 10 - GccChunyang KwokView Answer on Stackoverflow
Solution 11 - GccShrinivasView Answer on Stackoverflow
Solution 12 - GccBhagavanView Answer on Stackoverflow
Solution 13 - Gccpac88View Answer on Stackoverflow
Solution 14 - GcckrustyView Answer on Stackoverflow
Solution 15 - GccAlice VixieView Answer on Stackoverflow
Solution 16 - GccKuroView Answer on Stackoverflow
Solution 17 - GccJames ChanView Answer on Stackoverflow
Solution 18 - GccEugen KonkovView Answer on Stackoverflow