Whenever I am working on a project in Visual Studio 16 2019 of which the Visual Studio Solution (.sln) was created with CMake (more specifically cmake-gui), and I try to run the project through F5 or Ctrl+F5, I get the error: "Access is Denied" (example code added below). Release and Debug mode, same problem. I tried running Visual Studio as administrator, same problem.
After I succesfully compile, the solution directory (bin) looks like this (I left out some details like .vs, CMakeFiles and .vcxproj-like files for clarity):
main.cpp
CmakeLists.txt
bin
| ALL_BUILD.vcxproj
| helloworld.sln
| ZERO_CHECK.vcxproj
└──Debug
helloworld.exe
└──x64
└──Debug
└── ALL_BUILD
└── ZERO_CHECK
So, an executable is put in bin/Debug, which works perfectly when called from a command line. It seems like, when asked to run the program through (Ctrl+)F5, Visual Studio tries to look in bin/x64/Debug/ALL_BUILD while not having the access priviliges (how is that even possible?) but the folder is empty anyway (except for a .tlog and .log).
I tried copying helloworld.exe in bin/x64/Debug and bin/x64/Debug/ALL_BUILD, but nothing changes, which seems logical.
I also looked into changing the build output directory. However, my configuration manager looks like this and is therefor pretty useless.
Any help would be greatly appreciated. I can still run the executable through the command line, but I would like to use Visual Studio for debugging, which is currently impossible with this error.
Minimal example to try and replicate the problem. Use cmake-gui to create a Visual Studio 16 2019 solution. Open the .sln and build project helloworld or ALL_BUILD, then press F5 or Ctrl+F5.
#include <iostream>
int main(){
std::cout << "Hello World" << std::endl;
return 0;
}
cmake_minimum_required(VERSION 2.6)
project(helloworld)
set(ROOT "${CMAKE_CURRENT_LIST_DIR}")
# create executable
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
list(APPEND SRCFILES ${ROOT}/main.cpp)
add_executable(${PROJECT_NAME} ${SRCFILES})