问题
I was looking at the source code for ncmpcpp, and I saw this.
#include <mpd/client.h>
Inside that file are functions which are used by ncmpcpp. But those are just the headers. Don't the cpp files have to exist somewhere as well? I couldn't find them in the same directory. Where are they?
Also, when something that's included is surrounded by < and >, how do I know where to look?
回答1:
If it's a third-party library, most likely the source code won't be included. Nor is it needed. All symbols declared in the headers (which are meant to be used) should be exported in the .lib
file which was probably shipped with the headers.
Unless you have template
s, which could be inline.
You only need the cpp
files, or, more generally, the implementation files, if you want to compile the code yourself. Which you don't. You can use the module having just headers and binaries.
Of course, the example of open-source projects comes to mind, where all files are generally included, but if it's a commercial product, why release the source code? What's keeping any competitors from just copying it and resell it under a new name?
There's no standard rule that tells where to look for headers that are delimited by <>
or ""
, but the general consensus is that <>
are to be used for system headers (like string
or iostream
) and ""
for own headers (myclass.h
). It just tells the compiler where to look first.
回答2:
The source files aren't needed if there is a library (static or dynamically linked) with it that the compiler can link to, these are generally .a
or .lib
files (though very rarely you might need a .def
file).
For search paths, see this for MSVC and this for GCC.
来源:https://stackoverflow.com/questions/9687541/including-header-files-when-theres-no-implementation-file