2013-05-31 3 views
6

के लिए घोषणा नहीं है मैं उबंटू 13.04 (64-बिट) पर gcc 4.7.3 और clang 3.2.1 साथ निम्नलिखित कोड संकलन की कोशिश की है:stdlib.h putenv

#include <stdio.h> 
#include <stdlib.h> 
#include <stdbool.h> 

int main() { 
    putenv("SDL_VIDEO_CENTERED=1"); 

    return 0; 
} 

मैं उम्मीद putenvstdlib.h में घोषित किए जाने की हेडर, लेकिन मुझे निम्न चेतावनी मिलती है:

test.c: In function ‘main’: 
test.c:6:5: warning: implicit declaration of function ‘putenv’ [-Wimplicit-function-declaration] 

मेरे कार्य में इस फ़ंक्शन के लिए घोषणा क्यों अनुपलब्ध है?

उत्तर

8

आपको कुछ मैक्रोज़ को परिभाषित करना होगा। man 3 putenv को देखो:

NAME 
    putenv - change or add an environment variable 

SYNOPSIS 
    #include <stdlib.h> 

    int putenv(char *string); 

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

    putenv(): _SVID_SOURCE || _XOPEN_SOURCE 

तो जैसे stdlib.h सहित, से पहले या तो _SVID_SOURCE या _XOPEN_SOURCE को परिभाषित करने का प्रयास करें:

#define _XOPEN_SOURCE 
#include <stdlib.h> 

या (-D के साथ) जब संकलन, जैसे:

gcc -o output file.c -D_XOPEN_SOURCE 
संबंधित मुद्दे