简体   繁体   中英

Add folder with subfolders hierarchy to visual studio c++ 2015 project

I have a folder with the following hierarchy (this is just an example):

  • folder1
    • file1
    • file2
    • folder2
      • file3
      • file4

If i drag and drop the folder to the project explorer all the files are added to the project without folder hierarchy, like so:

  • file1
  • file2
  • file3
  • file4

Is it even possible to add entire library (a folder hierarchy) to visual studio or is the only way to do it is manually?

You can use CMake tool to do your build configurations. For example in CMakeLists.txt file, you can write as follows:

cmake_minimum_required (VERSION 3.1.1)

project(name_of_your_project)

add_executable(name_of_your_project 
    src/main.cpp
    src/folder1/file1.h
    src/folder1/file1.cpp
    src/folder1/folder2/file2.h
    src/folder1/folder2/file2.cpp
 )

After you write above, you can use CMake tool and give your visual studio compiler configuration options. It will generate a solution file with correct folder hierarchy.

This assumes that you have a folder hierarchy as follows:

src
  main.cpp
  folder1
     file1.h
     file1.cpp
     folder2
       file2.h
       file2.cpp

For details of using CMake, see https://cmake.org/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM