C++, multiple definition

后端 未结 2 1842
粉色の甜心
粉色の甜心 2020-12-22 07:47

I need to define a constant containing an environment variable (Linux, g++). I would prefer to use string, but std::getenv needs *char

2条回答
  •  独厮守ぢ
    2020-12-22 08:20

    Use

    extern const char* ENV_APPL_ROOT;
    

    in the header file, and place

    const char* ENV_APPL_ROOT = "APPL_ROOT";
    

    in one particular translation unit (e.g. DataLocation.cpp).

    This should fix it.

提交回复
热议问题