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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:57:52+00:00 2026-06-01T17:57:52+00:00

Compiling / linking with -nostdlib seems to prevent static initialization, even if I add

  • 0

Compiling / linking with -nostdlib seems to prevent static initialization, even if I add my own crti.s and crtn.s with .init/.fini sections.

Are there workarounds to make g++ generate static initialization code that is inserted in .init or that I can call manually?

This is what I tried:

g++ -o test.o -c -fno-use-cxa-atexit test.cc  # has _start (entry point) 
                                              #   that calls _init and _main
as -o crti.o crti.s      # has _init in section .init
as -o crtn.o crtn.s
g++ -o test ./crti.o test.o -nodefaultlibs -nostartfiles ./crtn.o

-nodefaultlibs alone includes static initialization code and call, but forces use of libc-_start/_init.

-nodefaultlibs -nostartfiles allows me to use my own _start / _init, but does not include code or call to static initialization.

  • 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-01T17:57:53+00:00Added an answer on June 1, 2026 at 5:57 pm

    From gcc linker docs,

    -nostdlib

    Do not use the standard system startup files or libraries when
    linking. No startup files and only the libraries you specify will be
    passed to the linker
    , and options specifying linkage of the system
    libraries, such as -static-libgcc or -shared-libgcc, are ignored.

    Hence use,

    -nodefaultlibs

    Do not use the standard system libraries when linking. Only the libraries you specify will be passed to the linker, options specifying linkage of the system libraries, such as -static-libgcc or -shared-libgcc, will be ignored. The standard startup files are used normally, unless -nostartfiles is used. The compiler may generate calls to memcmp, memset, memcpy and memmove. These entries are usually resolved by entries in libc. These entry points should be supplied through some other mechanism when this option is specified.

    Also try,

    g++ -Wl, -static
    
    -Wl      passes the next command on to the linker
    -static  On systems that support dynamic linking, this prevents linking with 
             the shared libraries. On other systems, this option has no effect.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After compiling/linking some .c .cpp and .h files, there are a couple of extra
I get an undefined reference to 'typeof'-error compiling and linking this: #include <stdio.h> #include
I am compiling my code to create a shared library and finally linking them
I am trying to compile a project by compiling object files and then linking
So my program is working fine. Compiling, linking, running, the works. Then, I decide
I'm having some trouble compiling/linking a set of classes, several of them dealing with
If compiling and linking with MinGW gcc v3 is painfully slow , and gcc
I'm using gcc for compiling and linking Objective-C programs, and I'm wondering if there
Hey there, I have a small problem with compiling and linking with the command
I was compiling/linking my program i386-gcc -o output.lnx func.opc mainc.opc and I kept getting

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.