[英]stdlib.h doesn't have declaration for putenv
I've tried compiling the following code with gcc 4.7.3
and clang 3.2.1
on Ubuntu 13.04 (64-bit): 我尝试在Ubuntu 13.04(64位)上使用gcc 4.7.3
和clang 3.2.1
编译以下代码:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main() {
putenv("SDL_VIDEO_CENTERED=1");
return 0;
}
I expected putenv
to be declared in the stdlib.h
header, but I get the following warning: 我预计putenv
在声明stdlib.h
头部,但我得到以下警告:
test.c: In function ‘main’:
test.c:6:5: warning: implicit declaration of function ‘putenv’ [-Wimplicit-function-declaration]
Why is the declaration for this function missing in my header? 为什么我的标题中缺少此函数的声明?
You have to define certain macros. 您必须定义某些宏。 Look at man 3 putenv
: 看看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
Try defining either _SVID_SOURCE
or _XOPEN_SOURCE
before including stdlib.h
, like so: 在包含stdlib.h
之前尝试定义_SVID_SOURCE
或_XOPEN_SOURCE
,如下所示:
#define _XOPEN_SOURCE
#include <stdlib.h>
Or when compiling (with -D
), like: 或者在编译时(使用-D
),例如:
gcc -o output file.c -D_XOPEN_SOURCE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.