Find the answer to your Linux question:
Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By MikeTbob
I've been trying to get gcc to to create executables that don't link against the standard C library, but I haven't been able to. I'm trying to make my own ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! rm-rf's Avatar
    Join Date
    Mar 2011
    Posts
    84

    Is there a way to get gcc to NOT link to the standard C library?


    I've been trying to get gcc to to create executables that don't link against the standard C library, but I haven't been able to. I'm trying to make my own standard C library, and I'm trying to use test driven development. Does anyone know how to get gcc to do this?

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,512
    Use the -nodefaultlibs and/or -nostdlib options. From the gcc man page:
    Code:
           -nodefaultlibs
               Do not use the standard system libraries when linking.  Only the libraries you specify will be passed to
               the linker.  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.
    
           -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.  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.
    
               One of the standard libraries bypassed by -nostdlib and -nodefaultlibs is libgcc.a, a library of internal
               subroutines that GCC uses to overcome shortcomings of particular machines, or special needs for some
               languages.
    
               In most cases, you need libgcc.a even when you want to avoid other standard libraries.  In other words,
               when you specify -nostdlib or -nodefaultlibs you should usually specify -lgcc as well.  This ensures that
               you have no unresolved references to internal GCC library subroutines.  (For example, __main, used to
               ensure C++ constructors will be called.)
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined! rm-rf's Avatar
    Join Date
    Mar 2011
    Posts
    84
    I've already tried using -nostdlib and -nodefaultlibs. Whenever I compile it with those, they also leave out linux-gate.so, and then the program can't run.

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,512
    Quote Originally Posted by rm-rf View Post
    I've already tried using -nostdlib and -nodefaultlibs. Whenever I compile it with those, they also leave out linux-gate.so, and then the program can't run.
    Well, the point of the man page info is that you need to specifically link in the parts you need, such as the linux-gate.so library (or replacement).
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #5
    Just Joined! rm-rf's Avatar
    Join Date
    Mar 2011
    Posts
    84
    The problem is that linux-gate.so.1 doesn't actually exist. it is a psuedo library that the kernel uses to simplify system calls.

  6. #6
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,512
    Quote Originally Posted by rm-rf View Post
    The problem is that linux-gate.so.1 doesn't actually exist. it is a psuedo library that the kernel uses to simplify system calls.
    Don't know what more to tell you. On my system, there is no liblinux-gate.so... or linux-gate.so... If it is as you say, a "pseudo library", then there has to be some way to deal with that. Unfortunately, I don't know what that is. You might try contacting the kernel experts at The Linux Kernel Archives, or Linus himself at The Linux Foundation.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  7. #7
    Just Joined! rm-rf's Avatar
    Join Date
    Mar 2011
    Posts
    84
    Don't know what more to tell you. On my system, there is no liblinux-gate.so... or linux-gate.so...
    Really? What architecture is your machine using? If it's x86, then I can almost garuntee you that it is using linux-gate.so.1.

  8. #8
    Administrator MikeTbob's Avatar
    Join Date
    Apr 2006
    Location
    Texas
    Posts
    7,864
    There *shouldn't* be one anyway, I had some issues with Linux-gate.so.1 just this past week,,,had to do a little searching.
    What is linux-gate.so.1?

    From time to time this is a cause of befuddlement and frustration for users as they go searching for a non-existent system file. You can confidently tell users on this futile quest that there's not supposed to be a linux-gate.so.1 file present anywhere on the file system; it's a virtual DSO, a shared object exposed by the kernel at a fixed address in every process' memory:
    Last edited by MikeTbob; 09-25-2012 at 12:29 AM. Reason: typo
    drl likes this.
    I do not respond to private messages asking for Linux help, Please keep it on the forums only.
    All new users please read this.** Forum FAQS. ** Adopt an unanswered post.

    I'd rather be lost at the lake than found at home.

  9. #9
    Just Joined! rm-rf's Avatar
    Join Date
    Mar 2011
    Posts
    84
    Quote Originally Posted by MikeTbob View Post
    There *shouldn't* be one anyway, I had some issues with Linux-gate.so.1 just this past week,,,had to do a little searching.
    What is linux-gate.so.1?
    I'm sorry, but did you even READ my question? I said I was trying to do test-driven development on a standard C library. I NEED it to be able to NOT link against the standard c library. I honestly don't see why gcc should treat libc.so differently from any other library.

  10. #10
    Administrator MikeTbob's Avatar
    Join Date
    Apr 2006
    Location
    Texas
    Posts
    7,864
    Quote Originally Posted by rm-rf View Post
    I'm sorry, but did you even READ my question? I said I was trying to do test-driven development on a standard C library. I NEED it to be able to NOT link against the standard c library. I honestly don't see why gcc should treat libc.so differently from any other library.
    I was just trying to help with the linux-gate file, I do not know the answer to your original question. Sorry for the confusion.
    I do not respond to private messages asking for Linux help, Please keep it on the forums only.
    All new users please read this.** Forum FAQS. ** Adopt an unanswered post.

    I'd rather be lost at the lake than found at home.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •