How do I change the working directory for my program

后端 未结 3 967
孤城傲影
孤城傲影 2020-11-29 11:26

Trying out the Clion EAP on the Mac. How does one change the current working directory for a launched program? It appears to be set to the output directory of the binaries.

3条回答
  •  -上瘾入骨i
    2020-11-29 11:30

    The "Working Directory" is where the executable starts. Modifying the "Working Directory" in the Configurations setting tells Clion to change to the "Working Directory" after the executable starts execution.

    If you want to change where the executable starts execution you will need to add a line to the CMakesLists.txt file.

    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

    add_executable(TimeServer ${SOURCE_FILES})

    Position in the cmakes file is important. If you add the set command after the add_executable it will not work. It must come before.

提交回复
热议问题