본문 바로가기
Nightly/English

[ Visual Studio ] How to fix the unresolved external symbol error

by SteadyForDeep 2021. 4. 17.
반응형

A nasty situation.

LNK1120

LNK2019

 

Linker error is one of the most nervouse error in VS.

The Error message and results of googling always has not enough information.

Even official MicroSoft page does.

 

 

In this case, a madness point is

eventhough the source code doesn't have any error,

we can't build this code.

 

Additionally, because linker error occur at .dll or .obj file,

it is too hard to catch the bug.

 

Now, let me show how to fix it.

 

I can search many cases of linker error.

Most of them are categorized in 3 reasons.

 

1. the 'main' function is not defined.

2. undefined funtions or variables is used.

3. x86 and x64 is built at the same time. (my case)

 

Actually, 1 and 2 is the same with 2.

 

In case of 1,

when VS build your code, it find and run the main function.

So if main function is undefined, linker error is occured.

 

In case of 2,

if your compiler setting is different with dll or lib files,

the compiler can't read them.

So functions in the dll or lib can occur the undefined function error.

 

To sum up, linker error is

"I know there is no error in your code, but the compiler can't understand it."

 

let's read the outputs, not error lists.

In my case, a dll file compiled with x64 is used in x86 Debuger.

So you can read  config : Debug Win32 (upper red circle) and project : CoreEngine_x64.

 

Although I already switched the 'solution configuration' from x86 to x64,

the debuger configuration is not switched.

 

This is solution config page.

As you can see, my platform of solution config is x64.

 

 

But Build > configuration manager is Win32 yet.

So if change it to x64,

 

 

 

the error is fixed.

반응형

댓글