#include <(class name).h> without being in project?

Started by
7 comments, last by DanG 21 years, 8 months ago
I''m writing a few utility classes using MSVC6. In all of my projects I want to be able to write #include <(the class name).h> and thats all. The prblem is that if I just put the .h and .cpp in MSVC include directory. It doesn''t work. I get unresolved external symbols errors. To make it work I have to bring it into the project, where it is compiled and clutters the workspace. All the standard headers, like iostream and mfc stuff, you can just write #include on the .h and all the classes work just fine, without being compiled or borught into the workspace. How do I do this?
Ambassador: Mr. Bush are you stoned or just really, REALLY dumb?Pres. Bush - I assure you I am not stoned.
Advertisement
use " " instead

.lick
Tried using quotes instead of angle brackets?

[twitter]warrenm[/twitter]

You need to compile the class into a library, link to that library (in the project settings) then you can simply #include the .h file and use the class as you wish.

Obviously it pays to group code together into utility libraries instead of just putting one class into one library, but there''s no reason why you can''t do that - it''s just a pain to link to them.

Cheers

Matt

Then how does this program work?

#include <iostream.h>
#include <fstream.h>

int main(int argc, char * argv[])
{
cout << "Hello World" << endl;
ofstream Text_File("Hello.txt");
Text_File << "Hello WOrld" << endl;
return 0;
}

That will compile. Notice it uses the classes ostream and ofstream, predefined instance cout and endl. I never brought any library into the project, just included the headers, yet they work just fine. How can I do that?
Ambassador: Mr. Bush are you stoned or just really, REALLY dumb?Pres. Bush - I assure you I am not stoned.
JUST DO THIS:

#include "(class header file).h"

DONE!

.lick
quote:Original post by DanG
I never brought any library into the project ...

Ah, but you did. There are a number of libraries which are linked by default - including libc and msvcrt, depending on your project settings. You need to follow 3dModelMan''s advice, and create a library. Then you just have to #include the library''s header, and link to the library. No need to bring the individual source files into the project.
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
Alright, I made a libary of the source i wanted put the .h where it goes. It works, but I still have to add the library manually. I found that if I write

#pragma comment(lib, "(class name).lib")

In the .h I don''t have to manually add the library. Is this OK coding style?
Ambassador: Mr. Bush are you stoned or just really, REALLY dumb?Pres. Bush - I assure you I am not stoned.
If you go to Project, then Settings, then the C/C++ tab, and choose Preprocessor in the Category dialog box, you''ll get a field where you can enter include directories. Is that what you''re looking for?

This topic is closed to new replies.

Advertisement