加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

stdlib.h没有putenv的声明

发布时间:2020-12-16 05:00:55 所属栏目:百科 来源:网络整理
导读:我尝试在Ubuntu 13.04(64位)上使用 gcc 4.7.3和clang 3.2.1编译以下代码: #include stdio.h#include stdlib.h#include stdbool.hint main() { putenv("SDL_VIDEO_CENTERED=1"); return 0;} 我期望在stdlib.h头文件中声明putenv,但是我得到以下警告: test.c
我尝试在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;
}

我期望在stdlib.h头文件中声明putenv,但是我得到以下警告:

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

为什么我的标题中缺少此函数的声明?

解决方法

您必须定义某些宏.看看男人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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读