Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6107903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:14:21+00:00 2026-05-23T14:14:21+00:00

Running Debian/Linux x86_64 with GNU ld 2.21. Quite simply, if I link with ld

  • 0

Running Debian/Linux x86_64 with GNU ld 2.21.

Quite simply, if I link with

ld -o main main.o /usr/lib/crti.o /usr/lib/crt1.o /usr/lib/crtn.o -lc -lm

It works, but when I link with

ld -r -o main1.o main.o /usr/lib/crti.o /usr/lib/crt1.o /usr/lib/crtn.o -lc -lm

It complains

ld: cannot find -lc
ld: cannot find -lm

I’m not actually trying to compile code this way, but rather I’m trying to figure out why someone else’s test to see if a library exists is not working. (Thus I don’t really understand what’s going on with ld… usually I just use GCC to link)

Why would telling ld to link in a relocatable fashion make it suddenly unable to find libraries? If I just want to test that -lm exists, what should I do besides

ld -r -lm

so that it will find the library?

If you want to see the source that I’m dealing with, you can download it here: https://github.com/jeremysalwen/ESPS (note, that the first commit is the original source code, and the subsequent ones are changes I have personally made.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:14:22+00:00Added an answer on May 23, 2026 at 2:14 pm

    MacOS X

    On MacOS X, the man page for ld is quite explicit about the -r option:

    -r Merges object files to produce another mach-o object file with file type MH_OBJECT.

    So, if you are on MacOS X, the trouble is that -lm is not a Mach-O object file, and neither is -lc. However, in theory, if you have object files main.o, obj1.o and obj2.o and you do:

    cp obj1.o ./-lm
    cp obj2.o ./-lc
    ld -r -o main1.o main.o -lm -lc
    

    then it might work. In practice, it doesn’t, and amongst the errors you get:

    ld: warning: unexpected dylib (/usr/lib/libm.dylib) on link line
    ld: warning: unexpected dylib (/usr/lib/libc.dylib) on link line
    

    However, running:

    ld -r -o main1.o -arch x86_64 main.o obj1.o obj2.o
    

    worked without any whingeing from the loader.

    Linux

    On Linux the man page for ld is less explicit, but says:

    -i Perform an incremental link (same as option -r).

    -r
    --relocatable

    Generate relocatable output—i.e., generate an output file that can in turn serve as input to ld. This is often called partial linking. As a side effect, in environments that support standard Unix magic numbers, this option also sets the output file’s magic number to "OMAGIC". If this option is not specified, an absolute file is produced. When linking C++ programs, this option will not resolve references to constructors; to do that, use -Ur.

    When an input file does not have the same format as the output file, partial linking is only supported if that input file does not contain any relocations. Different output formats can have further restrictions; for example some "a.out"-based formats do not support partial linking with input files in other formats at all.

    This option does the same thing as -i.

    Reading between the lines, this also takes object files and converts them to object files; it does not add libraries into the mix. If you think about it, object files are not created containing references to libraries.

    So, although there might be platforms where it is possible to specify libraries to the linker (loader) when using the -r option, there are others where it is not.

    Workarounds

    The original problem is to establish whether the libraries are present. Why not mimic what autoconf does, and create a main.c that would, for preference, contain a reference to a symbol defined in the library, but which could simply contain:

    int main(void){return 0;}
    

    and compile and link it with the C compiler:

    cc -o main main.c -lm -lc
    

    If it doesn’t work, then one of the libraries is missing. If you’ve already checked that -lc is present, then you can infer that -lm is missing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried running gdb to disassemble the kernel and tried running: root@debian:/home/jestinjoy# gdb /usr/src/linux-2.6.38.8/vmlinux
I build an application on a machine running Linux (Debian) with kernel 2.6.26-2-amd64 and
I'm a new Linode/Linux user running Debian 6. I'm trying to get my Unicorn
i have a problem with my server which is running ubuntu (debian) linux and
With VMWare Server running under Linux (Debain), I would like to have the following
I have Apache 2 running on a VPS server (running Debian). I recently changed
I'm putting a crontab job for updating with apt-get once a day (running Debian
We're running a Debian with a 2.6.16 kernel, with iptables enabled. The system is
I'm developing a web app on Yaws 1.65 (installed through apt) running on Debian
Greetings! I'd like to build an apache web server, running on debian lenny. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.