How do I change GCC's default search directory for crti.o?
Asked Answered
J

2

6

I'd like to specify GCC's search directory for the startfile and endfile: crt1.o, crti.o and crtn.o. Passing -B on the command line to the GCC driver works, but is inconvenient. How do I modify the specs file (lib/gcc/x86_64-unknown-linux-gnu/4.9.2/specs) to specify the search path for startfile?

I tried adding the -B option to the startfile spec and got the error: ld: unrecognized option '-B/gsc/btl/linuxbrew/lib'

I then tried adding the -B option to the cc1 spec and got the error: cc1: error: command line option '-B/gsc/btl/linuxbrew/lib' is valid for the driver but not for C

If it's not possible to do this via the specs file, is there an environment variable or a configure option to GCC that accomplishes the same goal?

I've installed a recent version of glibc in my home directory. Everything's working great. I've modified the specs file to link against the new version of glibc, but it's still linking against the old system version in /usr of startfile and endfile.

Here's a the unanswered question on the gcc-help mailing list. Here's a related Linuxbrew bug, gfortran is broken with stand alone Linuxbrew, and a proposed fix, gcc, binutils: link to Cellar instead of system libs.

Thanks,
Shaun

Jerrold answered 6/3, 2015 at 18:6 Comment(0)
J
1

You can use an absolute path in the *startfile: and *endfile: sections in the specs file, instead of the default relative paths. This will override GCC's choice of the default location.

Jonquil answered 9/2, 2019 at 17:29 Comment(0)
G
1

As per https://wiki.debian.org/Multiarch/LibraryPathOverview, gcc will look for startup files such as crt1.o in $(sysroot)/lib, so you can specify the --sysroot option when running gcc, or compile gcc with --with-sysroot.

Grizzly answered 15/11, 2018 at 22:7 Comment(1)
Unfortunately when I tried --sysroot with a custom built glibc it failed with another error: cannot find libgcc_s.so.1 and it still seemed to use the host ones: stackoverflow.com/questions/10412684/…Ulrika
J
1

You can use an absolute path in the *startfile: and *endfile: sections in the specs file, instead of the default relative paths. This will override GCC's choice of the default location.

Jonquil answered 9/2, 2019 at 17:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.