以下是Linux平台的,windows平台对应的是 _putenv_s(name, value);
windows上自己实现一个类似setenv的函数:
int setenv(const char *name, const char *value, int overwrite) { int errcode = 0; if(!overwrite) { size_t envsize = 0; errcode = getenv_s(&envsize, NULL, 0, name); if(errcode || envsize) return errcode; } return _putenv_s(name, value); }
原文:http://stackoverflow.com/questions/17929414/how-to-use-setenv-to-export-a-variable-in-c
From the setenv()
manual entry:
SYNOPSIS
#include <stdlib.h>
int setenv(const char *envname, const char *envval, int overwrite);
DESCRIPTION
The setenv() function shall update or add a variable in the environment of the calling process. The envname argument points to a string containing the name of an environment variable to be added or altered. The environment variable shall be set to the value to which envval points. The function shall fail if envname points to a string which contains an '=' character. If the environment variable named by envname already exists and the value of overwrite is non-zero, the function shall return success and the environment shall be updated. If the environment variable named by envname already exists and the value of overwrite is zero, the function shall return success and the environment shall remain unchanged.If the application modifies environ or the pointers to which it points, the behavior of setenv() is undefined. The setenv() function shall update the list of pointers to which environ points.
The strings described by envname and envval are copied by this function.
The setenv() function need not be reentrant. A function that is not required to be reentrant is not required to be thread-safe.
RETURN VALUE
Upon successful completion, zero shall be returned. Otherwise, -1 shall be returned, errno set to indicate the error, and the environment shall be unchanged.
So you should call
setenv("ROS_HOSTNAME","xxx",1);
or
setenv("ROS_HOSTNAME","xxx",0);
相关推荐
# 安装Clang编译器并完成配置(用于编译方舟编译器代码) 下载**clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04** LLVM下载地址:http://releases.llvm.org/download.html#8.0.0 放置到`openarkcompiler/tools`...
clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04,官网下载实在是太慢了!!!
clang+llvm-13.0.1-x86_64-linux-gnu-ubuntu-18.04 llvm 13.0.1 在 18.04系统下的安装包
OpenArkCompiler所需clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz,上传大小限制,压缩包1。
clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz llvm 10.0 在 18.04系统下的安装包
LLVM是构架编译器(compiler)的框架系统,以C++编写而成,用于优化以任意程序语言编写的程序的编译时间(compile-time)、链接时间(link-time)、运行时间(run-time)以及空闲时间(idle-time),对开发者保持开放,并兼容...
# 安装Clang编译器并完成配置(用于编译方舟编译器代码) 下载**clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04** LLVM下载地址:http://releases.llvm.org/download.html#8.0.0 放置到`openarkcompiler/tools`...
clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-14.04.tarclang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-14.04.tarclang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-14.04.tar
方舟编译器ubuntu16.04开发环境配置。 Clang编译器下载包,clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz。供大家学习下载O(∩_∩)
# 安装Clang编译器并完成配置(用于编译方舟编译器代码) 下载**clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04** LLVM下载地址:http://releases.llvm.org/download.html#8.0.0 放置到`openarkcompiler/tools`...
10_Seattle_Update_1_C++_Clang_FR_DE_JA_Hotfix.exe
Vim 插件 clang-format 是一个为 Vim 编辑器设计的强大工具,旨在提升程序员在处理 C、C++、Objective-C、Java 和 JavaScript 等语言时的代码格式化体验。Clang-format 是一个由 LLVM 项目维护的开源工具,它能够...
clang llvm资源 clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-14.04.tar clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-14.04.tar
clang+llvm-12.0.0-x86_64-linux-gnu-ubuntu-16.04
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
OpenArkCompiler所需clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.zip.002,上传限制,压缩包2
《深入理解Clang与LLVM:构建现代C++工具链》 ...在Ubuntu 18.04上使用"clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz" 包,可以极大地提升开发效率和代码质量,对于任何C++项目来说都是一个宝贵的资源。
clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-14.04.tar
官网编译好的clang版本,可以直接运行,特地上传。
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装