# Visual C++ include directories help

This topic is 3386 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi. I made some headers I want to include in every project from the include directories. So I'll be able to do #include <hello.h> instead of "hello.h", and I won't need to place them in the same directory every time. So I did this: but it doesn't work. I don't a get any compile errors; I get link error:
#include <iostream>

#include <palindrome.h>

using namespace std;

int main()
{
cout << palindrome(53);

cin.get();
return 0;
}


1>main.obj : error LNK2019: unresolved external symbol "int __cdecl palindrome(int)" (?palindrome@@YAHH@Z) referenced in function _main 1>C:\Users\User\Documents\Visual Studio 2008\Projects\Palindrome\Debug\Palindrome.exe : fatal error LNK1120: 1 unresolved externals [Edited by - sheep19 on November 16, 2008 12:44:40 PM]

##### Share on other sites
Where is the definition for palindrome()? If it's in another .cpp file, did you add that file to the project?

##### Share on other sites
Quote:
 Original post by Gage64Where is the definition for palindrome()? If it's in another .cpp file, did you add that file to the project?

int palindrome(int num){	int the_palindrome = 0,		power = get_power(num),		temp = power;		for(int i = 1; i <= power; i *= 10, temp /= 10)		the_palindrome += num / i % 10 * temp;	return the_palindrome;}

I haven't added it to the project. Do I have to? I don't add <string> or <vector> to my projects, I want this to be like that. Is that possible?

##### Share on other sites
Quote:
 Original post by sheep19I haven't added it to the project. Do I have to?

Yes, otherwise the linker won't be able to find the definition.

Quote:
 I don't add or to my projects, I want this to be like that. Is that possible?

As far as the standard library is concerned, I think there's some special setup where the appropriate libraries are linked without you having to specify them, but I don't know the details, and I'm not sure if it's possible to do something similar with custom libraries.

Also, a lot of those files contain template classes/functions and inline functions whose definitions are completely in the header files, so there's nothing to link.

##### Share on other sites
One VS specific option is as follows:

Set up a custom Lib directory somewhere and point VS at the directory via the Library Files section of the VC Directories dialog.

Create a new empty static library project.

Add the .h file and the .cpp file of your library code to this project and compile.

Find the resultant .lib file and put it in the Lib directory you set up earlier.

#pragma comment(lib,"name_of_the_lib.lib")

where name_of_the_lib is the name of your library file (obviously).

Now, in a fresh new project, you can just #include <name_of_the_lib.h> and you are good to go.

<string> and <vector> are all template code, so all the information the compiler needs is actually in those headers (or included in the headers via implementation files).

However, lots of the standard library is non-template and so is "magically" included by the compiler automatically linking against certain lib files in the background. The libraries linked by default are listed in an XML file somewhere deep in the bowels of your VS installation.

##### Share on other sites
Actually it is pretty easy in the drop down that has include files there is an entry where you can tell it where to find libraries.

##### Share on other sites
Quote:
 Original post by stonemetalActually it is pretty easy in the drop down that has include files there is an entry where you can tell it where to find libraries.

That tells VS which directories to search to find .lib files. To link against a specific .lib file, you have to specify the lib either with a #pragma, by adding the .lib to the project's additional dependencies or by adding the lib to the list of default libraries in the XML file somewhere in the VS installation.

##### Share on other sites
Quote:
 Original post by EasilyConfusedCreate a new empty static library project.

There is isn't such option. I'm using Visual C++ 2008 EE. Do you mean an empty project? (That's what I did)

Quote:
 Add the .h file and the .cpp file of your library code to this project and compile.Find the resultant .lib file and put it in the Lib directory you set up earlier.

How do I find it? it isn't in the folder of the project.

##### Share on other sites
Quote:
 Original post by sheep19There is isn't such option. I'm using Visual C++ 2008 EE. Do you mean an empty project? (That's what I did)

Just create either a console or Win32 app, then follow the wizard all the way through. On the last page, select Static Library and click the Empty Project option. Fully present in Express Edition.

Quote:
 Original post by sheep19How do I find it? it isn't in the folder of the project.

If you have compiled in debug, it is in the Debug folder in your project top directory. If release, it's in Release directory.

##### Share on other sites
I didn't do it correctly I think.

##### Share on other sites
Sorry - just unselect precompiled header to get an empty static lib project. My mistake.

Not sure it matters though - do you get a .lib file in your Debug or Release folder when you compile?

##### Share on other sites
in order to debug a library you need an test app that uses it then at the top you browse for that app

the second option is for server testing which isnt what you want in this case

##### Share on other sites
I got it working, thanks a lot!