Access denied to run the program in Visual Studio

So far, I have used Linux to write C ++ code, but I want to learn how to do it on Windows, and also use CMake for simplification.

To get started, I wrote the following CMakeLists.txt file:

cmake_minimum_required(VERSION 2.8) PROJECT( CMakeWin ) SET(CMAKE_BUILD_TYPE Release) # find opencv and set variables Set(OpenCV_DIR C:/Users/Erik/Documents/Libraries/opencv/build) FIND_PACKAGE(OpenCV REQUIRED) #set the default path for built executables to the "bin" directory set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) ADD_EXECUTABLE( ${PROJECT_NAME} src/main.cpp ) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${OpenCV_LIBS}) 

When I start CMake (using Visual Studio 11 configuration), it works fine, but when I open the CMakeWin.sln project and build and then run it, I get

 Unable to start program C:\..... The system cannot find the file specified. 

But I also got

 access denied. 

When I go directly to the Release or Debug folder and run

 CMakeWin.exe 

it works as it should. What is the problem?

EDIT:

To avoid creating a visual studio trying to start ALL_BUILD, I had to install CMakeWin as a StartUp project. See https://simtk.org/forums/viewtopic.php?f=91&t=3676 and comments below.

+6
source share
2 answers

In Visual Studio, open the project properties dialog box (right-click on the project in the solution explorer pane and select properties). Go to the "Debugging" section and see what the command line for launching the application is. Most likely, this is not so.

+4
source

CMake uses the same configuration as Linux. The general structure of simple projects is to have source files, compiled files, and executable files in the same directory. This way you can compile and run from the same directory.

The default MSVC configuration (I donโ€™t know how to change this, and I wouldnโ€™t risk it) uses one folder for each configuration. You can have as many as you need, DebugUnicode, ReleaseUnicode, DebugAnsi and ReleaseAnsi will be common.

General structure:

  • top level folder: solution
    • one folder for each project in the solution (one solution can contain several projects): source files
      • a res (optional) for resource files (icons, etc.).
      • folder for each configuration, Debug + Release: object and executables

So, by design, executable files are not in the same folder as the solution. You can execute them from there by specifying their relative path: Debug\project.exe

+2
source

All Articles