C , C++, C#

[Visual Studio] LNK2019: unresolved external symbol

vhxpffltm 2022. 9. 8. 22:56
반응형

링크 에러... 왜 못찾는 것일까..

 

라이브러리를 덤프했을때 외부 기호가 extenral로 함수 이름이 정확히 있었다...

 

그러면 보통 라이브러리만 링크해도 문제가 없어야 하는데..

 

도저히 못할줄 알았지만

 

다행히 공식 문서와 stackoverflow를 통해 해결할 수 있었다.

 

원인은 함수 기호 이름의 문제였다.

내가 작업하는 솔루션은 cpp이지만, 라이브러리로 만들어 사용하려는 솔루션은 모두 C 파일이다...

 

여기서 아는 사람은 cpp의 name mangling에 대해 알고 있을것이다.

C 언어와 cpp 언어는 다르며 해당 규약들과 이름에 대해 다르기때문에 똑같이 맞춰줄 필요가 있다...

 

 C++ 프로그램에서 런타임 라이브러리 함수를 사용할 수 있도록 하는 구문인 extern "C" 를 사용해서 간단히 해결할 수 있었다. C로 컴파일된 파일에 정의된 기호는 extern "C" 수식어 를 사용하지 않는 한 C++ 파일에 선언된 기호와 데코레이팅된 이름이 다르니 주의하자.

 

그래서 C 헤더파일의 내용에 extern "C" 를 사용하여 c++ 파일에 선언된 기호와 맞춰주면 해결된다.

 

 

https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-error-lnk2019?view=msvc-170 

 

Linker Tools Error LNK2019

All about the Microsoft Visual Studio Linker error LNK2019 and how to diagnose and correct it in C and C++ code.

docs.microsoft.com

 

https://stackoverflow.com/questions/19886397/how-can-i-solve-the-error-lnk2019-unresolved-external-symbol-function

 

How can I solve the error LNK2019: unresolved external symbol - function?

I get this error, but I don't know how to fix it. I'm using Visual Studio 2013. I made the solution name MyProjectTest This is the structure of my test solution: -function.h #ifndef MY_FUNCTION_H #

stackoverflow.com

 

 

반응형