Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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?

This is a BUG reported in launchpad, byt there is a workaround : askubuntu.com/questions/251978/… – Roman Nov 2, 2015 at 16:17

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

Debian / Ubuntu

sudo apt install gcc-multilib

Alpine

apk add musl-dev
                On Ubuntu this worked sudo apt-get install gcc-multilib and it fixed my error from gfortran -m32 ...
– randwa1k
                Sep 10, 2014 at 1:11
                More specific question that mentions 64 vs 32 cause: stackoverflow.com/questions/21724540/…
– Ciro Santilli OurBigBook.com
                Apr 24, 2015 at 13:39
                I had the same problem trying to setup a cross-compiling toolchain someone gave me as a tar bundle. I had to use strace (ie "strace gcc <all my arguments> 2>&1 | grep crt1.o") to see where gcc was looking for crt1.o, so I could figure out what symbolic link to create.
– Andrew Bainbridge
                Dec 6, 2016 at 11:56

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.

Not that debian's multiarch stuff break a lot of build, often with this error. export LD_LIBRARY_PATH can do the trick. – deadalnix Sep 15, 2011 at 9:27 For Photon OS, tdnf install glibc-devel worked for me. This might also work for CBL Mariner. – CNad May 24 at 19:51

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
                Works on 14.04. This is the preferred route if you don't want to mangle your system's libraries
– BobTuckerman
                May 9, 2017 at 20:11
                worked for me. I had this issue on my Alpine image since it contained both musl-gcc and native gcc and the paths were all messed up, so I had to add the musl-gcc one to my lib path. Thanks!
– Magmus
                Apr 13, 2022 at 8:14

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.

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.

A bit more on how to to "tell your toolchain about that" would be fantastic, as this is exactly the situation I am in. Thanks. – SullX Aug 2, 2013 at 2:56 Firstly, you'll need to know which architecture you're building for. Are you building an AMD64 based application? If so, you'll need to tell 'ld' where the AMD64 based shared object files are, i.e. the .o files you need. If you're working on an AMD64 they should be in /usr/lib64 – jeremiah Aug 3, 2013 at 13:58
  • 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
    
  • Compile programs using the -m32 flag

    gcc pgm.c -m32 -o pgm
    

    stolen from here : How to Compile 32-bit Apps on 64-bit RHEL? - I only had to do step 1.

    Although in my case the messages were:

    /usr/lib/gcc/x86_64-alpine-linux-musl/11.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find Scrt1.o: No such file or directory
    /usr/lib/gcc/x86_64-alpine-linux-musl/11.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find crti.o: No such file or directory
    /usr/lib/gcc/x86_64-alpine-linux-musl/11.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lssp_nonshared: No such file or directory
    collect2: error: ld returned 1 exit status
    

    Which are also caused by missing musl-dev.

    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

    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

    2) 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
                    To avoid confussions , the line $PATH=/usr/lib/i386-linux/gnu:$PATH $export PATH  is really:
    – pac88
                    Apr 5, 2015 at 22:46
    

    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
    

    Seems you have installed cross compiler by package manager with --no-install-recommends option, and as a result, some packages (required for cross compiling) are not installed. To fix your problem, search missing files in https://packages.debian.org/ to find out which package provide them.

    sudo apt install libc6-dev-arm64-cross libc6-arm64-cross
    

    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.

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.

  •