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:

[IMG][/IMG]
[IMG][/IMG]

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()
{
	int j = palindrome(53);
	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

Dani AI

Generated

Unresolved externals (LNK2019) mean the compiler found the header but the linker could not find a compiled definition. As suggested, a declaration in a header is not enough; ’s later post shows an implementation, but Visual Studio will only link that code if the corresponding .cpp is actually built into the project or a library containing it is linked.

Most direct fixes:

  • Add the implementation file to the project (Solution Explorer → right‑click the project → Add → Existing Item → select palindrome.cpp) and rebuild. Verify the file is not marked "Excluded From Build" for the current configuration.
  • If the code lives in a separate static library, make sure the library is built for the same configuration (Debug/Release and platform) and that the main project has the library path (Project Properties → Linker → General → Additional Library Directories) and the .lib listed under Linker → Input → Additional Dependencies.
  • For multi‑project solutions, set project dependencies or link the producing .lib so the linker can pull the object with the symbol.

Checklist of common causes and gotchas:

  • Prototype/definition mismatch (return type, parameter types, calling convention, or extern "C") will change the symbol name. Ensure the header signature exactly matches the implementation.
  • Don’t use static in a header to "fix" this (see ’s suggestion): static gives internal linkage and either hides the symbol from the linker or creates per‑TU copies—neither solves a missing external. Use inline for header definitions or keep the definition in a .cpp.
  • Clean and then Rebuild; if needed inspect the link line or use dumpbin /symbols on the .obj/.lib to confirm the symbol is present.

Example header prototype (keeps linkage simple):

// palindrome.h
int palindrome(int num);

Note: adding a folder to the compiler’s include directories only helps the preprocessor find headers; it does nothing for the linker.

Recommended Answers

All 6 Replies

Try this..

// ... palindrome.h
static void palindrome(int i_var)
{
    // your code
}
// ...

hi minas1 !
Have you implemented the function 'palindrome' in a c/c++ file?

Yep :)

#include <palindrome.h>

int get_power(int num)
{
	int power = 1;
	while(num != 0)
	{
		num /= 10;
		power *= 10;
	}
	power /= 10;
	return power;
}

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;
}

bool is_palindrome(int num)
{
	return num == palindrome(num);
}

Add your lib. path as additional include directory..

Add your lib. path as additional include directory..

I don't have one..

Yes you have..On compiler properties/settings page..Sorry for my bad English..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.