Stefan Keller
Stefan Keller

Reputation: 1943

How to fix linker error "cannot find crt1.o"?

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?

Upvotes: 194

Views: 389119

Answers (22)

pevik
pevik

Reputation: 4781

In my case on Debian stable bookworm removing libtirpc-dev caused removing build-essential and that in the end removed libc6-dev, which has /usr/lib/x86_64-linux-gnu/crti.o and /usr/lib/x86_64-linux-gnu/Scrt1.o.

I'm not sure why libtirpc-dev is so important for libc6-dev, but the biggest problem was that it was not intuitive to expect this.

Upvotes: 0

Dmitry Pavlenko
Dmitry Pavlenko

Reputation: 8958

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

Upvotes: 192

JamesThomasMoon
JamesThomasMoon

Reputation: 7124

On Alpine Linux you'll need package libc-dev

$ apk add libc-dev

Upvotes: 1

BubbleQuote
BubbleQuote

Reputation: 49

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

Upvotes: 0

Niklas Rosencrantz
Niklas Rosencrantz

Reputation: 26655

This worked for me with Ubuntu 16.04

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

Upvotes: 9

x-yuri
x-yuri

Reputation: 18823

On Alpine Linux that would mean that you need musl-dev:

apk add musl-dev

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.

Upvotes: 4

Alice Vixie
Alice Vixie

Reputation: 442

One magic command:

sudo apt install build-essential

Fixed everything for me even on Raspberry Pi.

Upvotes: 2

James Chan
James Chan

Reputation: 1

use gcc -B lib_path_containing_crt?.o

Upvotes: -1

Chunyang Kwok
Chunyang Kwok

Reputation: 31

./configure --disable-multilib

works for it

Upvotes: 3

krusty
krusty

Reputation: 350

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

Upvotes: 0

Eugen Konkov
Eugen Konkov

Reputation: 25113

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

Upvotes: -4

bulltorious
bulltorious

Reputation: 7887

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 : How to Compile 32-bit Apps on 64-bit RHEL? - I only had to do step 1.

Upvotes: 15

pac88
pac88

Reputation: 11

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

Upvotes: 0

Bhagavan
Bhagavan

Reputation: 9

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

Upvotes: 0

Umair R
Umair R

Reputation: 880

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

Upvotes: 39

Kuro
Kuro

Reputation: 1

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.

Upvotes: -1

Shrinivas
Shrinivas

Reputation: 64

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.

Upvotes: 1

tienping
tienping

Reputation: 89

As explained in 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

Upvotes: 8

alexm
alexm

Reputation: 714

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.

Upvotes: 19

jeremiah
jeremiah

Reputation: 841

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.

Upvotes: 17

Karel Lenc
Karel Lenc

Reputation: 830

What helped me is to create a symbolic link:

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

Upvotes: 65

Shinnok
Shinnok

Reputation: 6389

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.

Upvotes: 56

Related Questions