-4

I've made a static library with some .h files and need to include that library into my second project, which will also be output as a library. After copying first .lib file into the current project source folder, adding it (maybe redundantly) as an Additional Dependencies Directory and adding the .lib file itself as an Additional Dependency, I get

cannot open source file "Person.h"

error output when I try to compile it, despite having

#include "Person.h"

in my current .h file I've started working on. What have I missed?

Edit: I've added the original project's source folder under Additional Include Directories and it seems to work, but I'm confused - how does that help me with using the pre-made .lib file if I'm just referencing the headers from another project anyway?

Edit: I'd appreciate it if negative feedback is followed by at least a short comment so I can know what to improve. Thanks.

Stefan Stanković
  • 628
  • 2
  • 6
  • 17
  • 3
    And did you also set up the "Additional Include directories"? – UnholySheep Dec 11 '18 at 23:29
  • @UnholySheep I've just tried that, but nothing's really changed. I'm pretty sure I'm missing something obvious, but can't tell what, since this is my first time making libraries for myself... – Stefan Stanković Dec 11 '18 at 23:33
  • 1
    The error is definitely unrelated to your library binary. If the compiler can't find the header file the include directories are not set up properly – UnholySheep Dec 11 '18 at 23:34
  • @UnholySheep Should I change the tags, then? – Stefan Stanković Dec 11 '18 at 23:41
  • 2
    I believe this is a question that you will likely have to solve on your own. We don't know where your headers are located on your hard drive and we don't know what you typed into `Additional Include directories` and if you applied that setting to all configurations and not just the active one. Its very difficult to remotely debug with little info.. – drescherjm Dec 11 '18 at 23:43
  • 1
    Negative feedback likely due to lack of a reproducible example. Note: This is exceedingly hard to do with an IDE question, leading back to @drescherjm 's comment. – user4581301 Dec 11 '18 at 23:52
  • @user4581301 Thanks! The problem is that I don't really understand what *drescherjm* is trying to say... – Stefan Stanković Dec 11 '18 at 23:55
  • In the second project the compiler can not find your headers from the first project (library) so in that second project you must add the location of the headers from that first project the `Additional Include directories` setting for all configurations in that second project. – drescherjm Dec 11 '18 at 23:58
  • @drescherjm Thanks, I just did that before you commented, and have updated the question with the following point that confuses me. – Stefan Stanković Dec 12 '18 at 00:00
  • 1
    A lib file itself does not provide headers to the compiler. To use a library in your code in some other project you normally have to install the binary (.lib file also .dll if dynamically linking) and headers somewhere and tell the compiler where to look for the headers and library. – drescherjm Dec 12 '18 at 00:00
  • @drescherjm Thanks! That answers my stupid question... So `.lib`s are not independent modules, and I still have to reference the original source code... WIll you add this as your answer, so I can accept it? – Stefan Stanković Dec 12 '18 at 00:05
  • One benefit of the library is you don't have to install the source code for the .cpp files used in the library to use the library in some other project. – drescherjm Dec 12 '18 at 00:05

1 Answers1

0

As @drescherjm and @UnholySheep explained in the comments, .libs are not independent modules.

The problem is solved by adding the folder containing the original .h files under Additional Include Directories.

Stefan Stanković
  • 628
  • 2
  • 6
  • 17