getenv()表示只有在Eclipse中运行时才定义一个已定义的环境变量

时间:2011-12-03 21:27:04

标签: c++ eclipse ubuntu environment-variables

更新: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()将其定义为未定义?

1 个答案:

答案 0 :(得分:1)

检查Eclipse“运行配置”中的“环境”选项卡以查找您的程序。该列表应为空,并且应检查“将环境附加到本地环境”。

编辑如果这没有帮助,那么很可能Eclipse还没有使用缺失的变量启动。通过使用/usr/bin/printenv作为程序创建新的“外部工具配置”来检查这一点。启动此外部工具并检查输出。如果未提及缺失的变量,则必须指定完全

  

我在一个文件(.configuration或类似的东西)中添加了定义和导出。

部分来自您的评论: - )