0

I have read Microsoft's tutorial "Creating and Using a Static Library (C++)", and successfully follow it.

Here is the dummy project :-

  • B : name of a static library project
  • C : name of a project that uses B

Here is what Microsoft guides :-

  1. click "Add references" in C, then click B (easy)
  2. add "Additional Include Directories" of C to point to B's code folder

Why do I have to do the second (redundant) step?
It causes some maintainability issue & tedious, especially if I have a lot of projects.

Is it what experts do?
I believed just the 1st step should be enough, but after testing it doesn't.

Question:

  • Are there any better workflow? What is it?
  • If no, how to maintain the include directory (if I move B's folder around)?

After searching SO, I come to believe that there are no better way and I have to maintain it manually.

javaLover
  • 6,347
  • 2
  • 22
  • 67

1 Answers1

1

Step 1 ("Add references") is for the linker, Step 2 ("Additional Include Directories") is for the compiler.

It's true that the IDE could be smart enough to operate step 2 automatically. However, you may not add the whole B's code folder to be seen by C. Most likely you meant to only point to a folder listing B interfaces (public header files), C should not see B private/internal headers nor B source code: it's surely too difficult for the IDE to figure out where it is exactly, that's why the user should do it manually.

For your last questions: what "experts" do is that they commonly don't edit/maintain IDE files by hand, they have them be generated by a tool, like CMake. Then, when structure changes, they just re-generate the project (sln/vcproj) files (run CMake again).

jpo38
  • 20,821
  • 10
  • 70
  • 151
  • Do you have more must-read about workflow of cMake+VS in your mind? (besides the link) Thank. – javaLover Mar 27 '17 at 12:18
  • @javaLover: CMake is a great tool, once it's in place, it will help you managing all your libraries/programs/tests compilation steps smartly. – jpo38 Mar 27 '17 at 12:20
  • I believe so (heard a lot of good rumor around it). How should I learn it? Is googling "visual studio cmake tutorial" sound OK? – javaLover Mar 27 '17 at 12:22
  • 1
    @javaLover: Check https://cmake.org/cmake-tutorial/ and http://stackoverflow.com/questions/395169/using-cmake-to-generate-visual-studio-c-project-files – jpo38 Mar 27 '17 at 13:14