0

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})
Jl arto
  • 1
  • 1
  • It's Visual Studio, not VSCode. And I've had this problem with multiple projects spread over years. I've closed and opened the IDE many times while working on these projects. – Jl arto Nov 15 '21 at 14:57
  • Have you closed and opened the project this specific time? Do you have any other programs with files open? Totally sounds like another program has a file open. – JohnFilleau Nov 15 '21 at 14:58
  • @JohnFilleau I get what you mean. I closed all programs, restarted my computer and tried again. Still the same problem. I just don't think that's it for me, but could be useful for others reading this. Remember that bin/x64/Debug/ALL_BUILD is empty (except for .tlog and .log), so it's weird that VS is trying to access it at all. – Jl arto Nov 15 '21 at 15:34
  • @vre, changing the startup project worked indeed (thanks!). For others: you can also change the startup project in Visual Studio by right-clicking the solution > Properties > Startup Project – Jl arto Nov 15 '21 at 15:41

0 Answers0