Sirmyself
Sirmyself

Reputation: 1564

c++ - How to add header and cpp files in a library project

Long story short : I had some functions I thought could be useful in a library instead of just copying the functions from one project to the next one. So I created a library project and put my header file and cpp file in the project, referenced it with my second project (in the same solution) and everything is working fine.

Here's my problem. I want to add an other set of functions in different files. So I created a new header file and a new cpp file, but now I don't seem to be able to include the new header file. the other one works fine, but the new one can't be included and VS gives me these error codes :

E1696   cannot open source file "2ndFunctionSet.h"                  [2ndProjectName]        [FileNameA]
C1083   include : '2ndFunctionSet.h' : No such file or directory    [2ndProjectName]        [FileNameA]

Here's a summary of the current structure of the solution :

SolutionName
|---project > CommonLibraries
|   |---{header files}
|   |   |---baseFunctions.h
|   |   |---2ndFunctionSet.h
|   |---{source files}
|       |---baseFunctions.cpp
|       |---2ndFunctionSet.cpp
|
|---project > 2ndProjectName
    |---{header files}
    |   |---someClass.h
    |   |---mainCode.h
    |---{source files}
        |---someClass.cpp
        |---mainCode.cpp

both cpp files from the common libray include their header files and the stdafx.h default precompilation file and both seem to be constructed similarly.

Can you please help me understand what I have done wrong? I haven't been doing c++ for a while, so it is likely I did a procedure error when creating my library project or when I created the new function set file.

Upvotes: 1

Views: 18957

Answers (1)

Sirmyself
Sirmyself

Reputation: 1564

The files are not in the same folder.

You should also check if the files that are "working" are in the proper folder :

  • Go on your file explorer
  • Check the library project's folder
  • If the files are in the wrong folder
    • Move them in the correct project folder
    • Add reference to the new files' location

Now on "How to include those files in a project of the same solution" :

  • Go in your "2ndProjectName" project's properties
  • "Configuration Properties" > "c/c++" > "General"
  • In "Additional include directory" : click > edit and go reach for the library project folder.
  • In the Solution Explorer, go in your "2ndProjectName" project
  • Right click on "References" > "Add Reference"
  • Make sure your library project is checked

Upvotes: 1

Related Questions