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 9155781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:39:20+00:00 2026-06-17T12:39:20+00:00

Consider the hello world C program: hello.c : #include stdio.h int main() { printf(Hello,

  • 0

Consider the hello world C program:

hello.c:

#include "stdio.h"

int main()
{
        printf("Hello, World!\n");
}

If I call:

$ gcc -c hello.c -o hello.o

It will produce an ELF Relocatable File hello.o

If I then call:

$ gcc hello.o -o hello            [1]

It will link hello.o with ld and produce an ELF Executable File hello

However if I call ld directly [2] instead of [1]:

$ ld hello.o -o hello             [2]

I get these errors:

/usr/bin/ld.bfd.real: warning: cannot find entry symbol _start
test.c:(.text+0xa): undefined reference to `puts'

gcc must be passing other options to ld (to link the C library for example).

Is there anyway to determine exactly what the command-line gcc is passing through to ld in command [1] ?

  • 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-06-17T12:39:20+00:00Added an answer on June 17, 2026 at 12:39 pm

    Yes, you can use gcc -v hello.o -o hello to get the link line. For your example on my ubuntu machine, I get this link line (edited to be multiline for readability):

    /usr/lib/gcc/x86_64-linux-gnu/4.4.5/collect2
    --build-id
    --eh-frame-hdr
    -m elf_x86_64
    --hash-style=gnu
    -dynamic-linker
    /lib64/ld-linux-x86-64.so.2
    -o hello
    -z relro
    /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crt1.o
    /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crti.o
    /usr/lib/gcc/x86_64-linux-gnu/4.4.5/crtbegin.o
    -L/usr/lib/gcc/x86_64-linux-gnu/4.4.5
    -L/usr/lib/gcc/x86_64-linux-gnu/4.4.5
    -L/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib
    -L/lib/../lib
    -L/usr/lib/../lib
    -L/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../.. -L/usr/lib/x86_64-linux-gnu
    hello.o
    -lgcc
    --as-needed -lgcc_s --no-as-needed 
    -lc
    -lgcc
    --as-needed -lgcc_s --no-as-needed
    /usr/lib/gcc/x86_64-linux-gnu/4.4.5/crtend.o
    /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crtn.o
    

    Note that collect2 is just an alias for ld.

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

Sidebar

Related Questions

Let's consider this simple test program: #include <stdio.h> #include <string.h> int main(int argc, char
Consider standard hello world program in C compiled using GCC without any switches. As
Consider this pointless program: /* main.c */ #include <stdlib.h> #include <unistd.h> int main(int argc,
Consider this line: std::wcout << Hello World!; Is it OK to pass char* or
Consider the following HTML: <div> <p>Hello</p> World </div> Why $(div).append($(p)); first removes the <p>
Consider this code: #include <iostream> using namespace std; class hello{ public: void f(){ cout<<f<<endl;
Is there the equivalent of the Hello World program for GIS applications? I am
Consider the case where I want every occurrence of the phrase hello world in
Consider the following code: char* str = Hello World; memcpy(str, Copy\0, 5); A segmentation
Consider the following snippet: var t = <span>Hello world</span>; var range = window.getSelection().getRangeAt(0); range.deleteContents();

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.