Clion or cmake does not see environment variable

[亡魂溺海] 提交于 2019-11-29 09:26:00

From CLion developers FAQ:

Q: How to pass environment variables and parameters to CMake in CLion?

A: The best way is to use Preferences/Settings | Build, Execution, Deployment | CMake dialog.

As for .bashrc file, it is only used by bash. CLion doesn't need to use bash for run configuration process.

Go to File -> Settings -> Build,Execution,Deployment

Click Pass system and...

For old Clion

For Clion 2017.2

Variables from .bashrc aren't passed

On Ubuntu 17.04, you can set a permanent environment variable by modifying

    /etc/enviornment

[I assume you can do this in other versions of Linux, but I provide the version of the system that I am using.]

For example, I am compiling test cases that assume that ${GOOGLE_MOCK} has been set. I added the following to my /etc/environment file, and now I don't have to rewrite all of my CMakeLists.txt files:

    GOOGLE_MOCK=/usr/local/src/googletest/googlemock
    GOOGLE_TEST_HOME=/usr/local/src/googletest/googletest

Clion just became much more useable. Hope this helps someone else!

One thing you can check is the .gdbinit. Clion on Linux will invoke the gdb, which will read in the .gdbinit. I happen to have set environment LD_LIBRARY_PATH xxx in my .gdbinit file, which will override whatever you set LD_LIBRARY_PATH from shell, whether through direct export or through .bashrc, or from CLion environment variable panel.

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!