I'm working with VC++ 7, but I think this rather dumb question is C++
related rather than Vis Studio related.

I am trying to use log4cpp, and I downloaded the zip files. When I wish to
use it in my code I can #include the required header file. However, when I
build I get link problems. This is because the cpp files are not being found
or compiled. I can tell VS to look in the correct folder for the cpp, but
that's not enough (C++ Directories).
Am I missing something here? I don't see why I should expect the compiler to
compile these library files but I do. Should I compile them as a separate
project do you think? I must say that I don't understand pre-compiled
headers either - is this something I should be looking at!

I know this is Vis Studio biased, but the problem is that there's a general
principle I don't understand.
Can you help?
Please excuse the extreme stupidity of this post.

Thanks very much.

john


--
---
If you need to reply personally, append "text" to the domain name in my
email adr.
Thanks

Re: How can VC build a cpp file not in a project? by Sven

Sven
Tue May 11 18:07:14 CDT 2004

jr wrote:
> I'm working with VC++ 7, but I think this rather dumb question is C++
> related rather than Vis Studio related.
>
> I am trying to use log4cpp, and I downloaded the zip files. When I
> wish to use it in my code I can #include the required header file.
> However, when I build I get link problems. This is because the cpp
> files are not being found or compiled. I can tell VS to look in the
> correct folder for the cpp, but that's not enough (C++ Directories).
> Am I missing something here? I don't see why I should expect the
> compiler to compile these library files but I do. Should I compile
> them as a separate project do you think? I must say that I don't
> understand pre-compiled headers either - is this something I should
> be looking at!

Visual C++ cannot compile files that aren't in a project (unless you invoke
the compiler manually from the command line, but that's not what you're
after here). You must either include the cpp files from log4cpp in your
project, or build them as a lib file in a separate project and link your
project with that.

Pre-compiled header files have nothing to with this. They are a construct
purely meant to reduce compile time. It is born out of the fact that certain
standard includes (most notably windows.h, and MFC related headers) are
rather large. Windows.h and all the files it includes come to several tens
of thousands of lines of code. If you just put #include <windows.h> at the
top of every file that needs it, parsing these huge include files becomes a
big slowdown in compilation. A pre-compiled header file (pch file) is
created by parsing the header files and saving the compiler state at that
point. This means that instead of having the parse the headers again, it can
simply load the pch file and parse the source file. This saves a lot of
time. Files that use a pre-compiled header must include a pre-compiled
header directive, which is just the #include statement for whatever header
was pre-compiled. Since a source file can only have one pre-compiled header
directive, you will generally create a single header file (by default named
"stdafx.h" in Visual Studio) that includes all the header files you want to
have pre-compiled. Because of the nature of pre-compiled header files, these
must be headers that rarely change, so they're usually not headers in your
project, but system headers like those from the standard C/C++ library or
the Windows Platform SDK or MFC or whatever other library you might be
using.

--
Sven Groot

http://unforgiven.bloghorn.com