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

21

181

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?

Sharma answered 13/6, 2011 at 11:35 Comment(4)
Try install libc0.1-dev.Alfredalfreda
For Mac, see: stackoverflow.com/questions/1365211/…Ignite
possible duplicate of Missing crt1 and crti when crosscompilingMuscadel
This is a BUG reported in launchpad, byt there is a workaround : askubuntu.com/questions/251978/…Fragile
D
174

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
Decreasing answered 15/4, 2013 at 13:44 Comment(4)
On Ubuntu this worked sudo apt-get install gcc-multilib and it fixed my error from gfortran -m32 ...Magnum
More specific question that mentions 64 vs 32 cause: stackoverflow.com/questions/21724540/…Valid
On Fedora this worked sudo dnf install glibc-devel.i686 and it fixed my problem as well.Eminent
2023 and this answer still works.Vostok
W
65

What helped me is to create a symbolic link:

sudo ln -s /usr/lib/x86_64-linux-gnu /usr/lib64
Witless answered 25/1, 2012 at 14:8 Comment(2)
This does work, however it gives you effectively just one arch on Debian multiarch.Hoodmanblind
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.Ranie
T
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.

Tami answered 11/7, 2011 at 15:42 Comment(3)
Not that debian's multiarch stuff break a lot of build, often with this error. export LD_LIBRARY_PATH can do the trick.Ruttger
this helps, for alpine linux apk add libc-dev=0.7.1-r0Replicate
For Photon OS, tdnf install glibc-devel worked for me. This might also work for CBL Mariner.Cytology
B
37

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
Brendon answered 17/5, 2013 at 9:13 Comment(2)
Works on 14.04. This is the preferred route if you don't want to mangle your system's librariesWhisker
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!Quoin
R
19

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.

Roxannaroxanne answered 12/9, 2012 at 9:49 Comment(1)
@DjDac you shouldn't need any flag in Ubuntu 16.04, AFAICT.Roxannaroxanne
H
17

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.

Hoodmanblind answered 19/6, 2012 at 12:56 Comment(2)
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.Lafond
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/lib64Hoodmanblind
C
15

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.

Cheviot answered 15/8, 2016 at 22:39 Comment(0)
A
8

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

Antilles answered 22/1, 2013 at 5:48 Comment(0)
U
8

This worked for me with Ubuntu 16.04

$ export LIBRARY_PATH=/usr/lib/x86_64-linux-gnu
Unscramble answered 31/3, 2017 at 7:7 Comment(0)
T
3

./configure --disable-multilib

works for it

Transcend answered 18/12, 2017 at 11:34 Comment(0)
D
3

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.

Darmit answered 3/7, 2022 at 12:38 Comment(1)
Worked for me, when trying to build httpbox in Alpine.Nickolasnickolaus
S
1

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.

Sudd answered 20/3, 2013 at 6:49 Comment(0)
N
1

One magic command:

sudo apt install build-essential

Fixed everything for me even on Raspberry Pi.

Ngo answered 27/12, 2021 at 5:16 Comment(0)
W
1

On Alpine Linux you'll need package libc-dev

$ apk add libc-dev
Weed answered 16/4, 2023 at 7:36 Comment(0)
F
0

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

Furniture answered 28/8, 2013 at 9:12 Comment(0)
B
0

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
Bochum answered 5/4, 2015 at 22:44 Comment(1)
To avoid confussions , the line $PATH=/usr/lib/i386-linux/gnu:$PATH $export PATH is really:Bochum
O
0

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
Overture answered 11/10, 2017 at 19:20 Comment(0)
D
0

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
Dictatorship answered 11/4, 2023 at 9:0 Comment(0)
S
-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.

Szechwan answered 11/4, 2013 at 15:35 Comment(0)
C
-1

use gcc -B lib_path_containing_crt?.o

Coot answered 29/7, 2013 at 9:5 Comment(0)
V
-4

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
Vidal answered 19/10, 2016 at 11:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.