getenv()表示定义的环境变量只有在Eclipse中运行时才未定义
getenv() says a defined environment variable is undefined only when running in Eclipse
UPDATE: Eclipse是问题所在——它在控制台工作。但是我仍然希望它能在Eclipse中工作。
我的printenv输出包含以下行:
PROTCAD3DIR=/home/brent/Desktop/protCAD
但是从我试图运行的程序(在Eclipse中),我得到输出:
Environment variable PROTCAD3DIR undefined.
Please set it properly and re-execute the program.
我在源代码中搜索此消息并找到1个结果:
string PCGeneralIO::getEnvironmentVariable(const string& _evname)
{
const char* convEVName = _evname.c_str();
char* pEVString = getenv(convEVName);
if (pEVString == 0)
{ cout << "Environment variable " << _evname << " undefined." << endl;
cout << "Please set it properly and re-execute the program." << endl;
exit(1);
}
string EVstring = charToString(pEVString);
return EVstring;
}
我很确定这是在调用上面的函数:
string evname = "PROTCAD3DIR";
string path = PCGeneralIO::getEnvironmentVariable(evname);
那么是什么导致getenv()发现它是未定义的呢?
检查您的程序的Eclipse "Run Configuration"中的"Environment"选项卡。该列表应为空,并选中"追加环境到本机环境"。
Edit如果没有帮助,那么很可能Eclipse没有使用丢失的变量启动。通过使用/usr/bin/printenv
作为程序创建新的"外部工具配置"来检查这一点。启动这个外部工具并检查输出。如果没有提到缺少的变量,那么您必须精确地指定
我在一个文件中添加了定义和导出。配置或类似的东西)。
摘自你的评论:-)
相关文章:
- CMake-按正确顺序将项目与C运行时对象文件链接
- 我在c++代码中生成了一个运行时#3异常
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 删除指向指针的指针是运行时错误吗
- 如何用参数值调用函数(仅在运行时已知)
- 为什么即使使用-cudart-static进行编译,库用户仍然需要链接到cuda运行时
- 是否可以在编译时初始化数组,以便在运行时不会花费时间?
- c++中的指针和运行时错误
- 在运行时处理类型擦除的数据-如何不重新发明轮子
- 有没有一种方法可以测量c++程序的运行时内存使用情况
- 建议在运行时将带有类实例的列表从c++导入qml
- C++ 运行时链接器错误 (liblog4cpp.so.5) Eclipse
- C++ - 调试和运行时 Eclipse 行为不同
- 从 eclipse IDE 运行工作正常,但在从终端运行时终止
- 调试运行时出现奇怪的崩溃程序(Eclipse C++)
- "Cannot execute binary file"在 Ubuntu for Windows 平台上使用 Eclipse 运行编译的 c++ 程序时
- "control reaches end of non-void function" Eclipse C++ 中的警告,但没有编译或运行时错误
- getenv()表示定义的环境变量只有在Eclipse中运行时才未定义
- 在 Eclipse 中运行时C++程序的输入提示不出现
- java.lang.UnsisfiedLinkError:运行时调用本地方法Eclipse时未找到该本地方法