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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:53:50+00:00 2026-05-15T06:53:50+00:00

How do I get the POSIX strerror_r instead of GNU version? I’m compiling with

  • 0

How do I get the POSIX strerror_r instead of GNU version?

I’m compiling with g++ on Ubuntu 8.04 with glibc version 2.7 ( based on what’s in ).

Edit

On the above man page it says:

Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

   The XSI-compliant version of strerror_r() is provided if:
   (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE
   Otherwise, the GNU-specific version is provided.

It then says in feature_test_macros(7):

   If no feature test macros are explicitly defined, then the following feature
   test macros are defined by default: _BSD_SOURCE, _SVID_SOURCE, _POSIX_SOURCE,
   and _POSIX_C_SOURCE=200809L (200112L in glibc versions before 2.10; 199506L in
   glibc versions before 2.4; 199309L in glibc versions before 2.1).

So I should be getting the POSIX version, but I’m getting the GNU one instead.

  • 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-15T06:53:51+00:00Added an answer on May 15, 2026 at 6:53 am

    From the header string.h:

    /* Reentrant version of `strerror'.
       There are 2 flavors of `strerror_r', GNU which returns the string
       and may or may not use the supplied temporary buffer and POSIX one
       which fills the string into the buffer.
       To use the POSIX version, -D_XOPEN_SOURCE=600 or -D_POSIX_C_SOURCE=200112L
       without -D_GNU_SOURCE is needed, otherwise the GNU version is
       preferred.  */
    

    Note, be careful when using GNU extensions, turn them on (_GNU_SOURCE) last, before including the headers that you want it to affect (or undefine it strategically). No need to worry if not using GNU extensions, though.

    Generally, if GNU deviates from POSIX in default behavior, you’ll see some comments in the header to indicate how you can get the POSIX behavior. Its also (usually) documented in the glibc manual, but that doesn’t always make it to the highly condensed man pages.

    Edit

    Try this simple test:

    #include <string.h>
    #ifdef _GNU_SOURCE
    #error "Something turned it on!"
    #endif
    

    Or more directly

    #ifdef _GNU_SOURCE
    #undef _GNU_SOURCE
    #endif
    #include <string.h>
    

    If _POSIX_C_SOURCE={version} is defined, you should have the POSIX version unless something else caused the GNU version to be favored.

    The only thing I can think of that would do that is _GNU_SOURCE. I’m sure this isn’t on your command line flags, you would have seen it. It could be that another library that is included has turned it on.

    That’s what I meant about the extensions being ‘tricky’ when requesting that POSIX implementations be favored, even if you aren’t the one turning them on.

    Edit

    If something is turning on _GNU_SOURCE (I can’t recall if boost does or not, I don’t use c++ nearly as much as I do C), you probably want to allow it to do so. You can use --undef "[macro]" -U[macro] from the command line. However, that won’t work if the library code looks like this:

    #ifndef _GNU_SOURCE
    #define _GNU_SOURCE
    #endif
    
    #include <stdio.h>
    #include <string.h>
    
    #ifdef _GNU_SOURCE
    #error "It didn't work"
    #endif
    
    int main(void)
    {
       return 0;
    }
    

    The issue is, by the time your code actually includes string.h, something else has already turned on extensions and included it. Include guards naturally prevent you from including it twice.

    Try explicitly turning off _GNU_SOURCE and including string.h prior to anything else. This prevents other libraries from turning those extensions on. However, those libraries might not work without them. Some code just ‘expects’ GNU behavior, and does not include fallback to POSIX.

    I’ve experienced similar frustration with library code that does not work without asprintf().

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

Sidebar

Ask A Question

Stats

  • Questions 486k
  • Answers 486k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer My original answer would only work if the window was… May 16, 2026 at 7:57 am
  • Editorial Team
    Editorial Team added an answer Are you running configure from the gcc source tree? If… May 16, 2026 at 7:57 am
  • Editorial Team
    Editorial Team added an answer Much easier than that, ever since Windows 2000 you can… May 16, 2026 at 7:57 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.