1

I am writing C++ codes and wanted to link an external library, matplot++, with my project. I haven't got used to CMake so I write commands in Makefile. I am confused for the errors I have encoutered so far, finally laying on LNK2019. Most of LNK2019 answers don't fit me and the situation so far. I don't think it's a problem of the library. Could the experts on MSVC help me out?
Btw I tried to link the .lib static, only to produce more errors so I have to use /MD to bypass half of the errors. I have checked that both my cl.exe and .lib are 32-bit (x86). The environment variable INCLUDE and LIB link paths are set.

# Command:
cl /MD test.cpp matplot.lib /std:c++17 /Fe:test.exe /FI xxx.hpp /FI xxx.cpp

Platform: Win10

Compiler: MSVC from VS2019 (cl.exe x86)

Lib: matplot.lib (x86)

matplot.lib(common.cpp.obj) : error LNK2019: unresolved external symbol __imp__SetDIBitsToDevice@48 referenced in function "public: struct cimg_library::CImgDisplay & __thiscall cimg_library::CImgDisplay::paint(void)" (?paint@CImgDisplay@cimg_library@@QAEAAU12@XZ)
matplot.lib(common.cpp.obj) : error LNK2019: unresolved external symbol __imp__TrackMouseEvent@4 referenced in function "public: static long __stdcall cimg_library::CImgDisplay::_handle_events(struct HWND__ *,unsigned int,unsigned int,long)" (?_handle_events@CImgDisplay@cimg_library@@SGJPAUHWND__@@IIJ@Z)
matplot.lib(common.cpp.obj) : error LNK2019: unresolved external symbol __imp__GetMessageA@16 referenced in function "public: static unsigned long __stdcall 
cimg_library::CImgDisplay::_events_thread(void *)" (?_events_thread@CImgDisplay@cimg_library@@SGKPAX@Z)
matplot.lib(common.cpp.obj) : error LNK2019: unresolved external symbol __imp__DispatchMessageA@4 referenced in function "public: static unsigned long __stdcall cimg_library::CImgDisplay::_events_thread(void *)" (?_events_thread@CImgDisplay@cimg_library@@SGKPAX@Z)
matplot.lib(common.cpp.obj) : error LNK2019: unresolved external symbol __imp__PeekMessageA@20 referenced in function "public: static long __stdcall cimg_library::CImgDisplay::_handle_events(struct HWND__ *,unsigned int,unsigned int,long)" (?_handle_events@CImgDisplay@cimg_library@@SGJPAUHWND__@@IIJ@Z)
matplot.lib(common.cpp.obj) : error LNK2019: unresolved external symbol __imp__DefWindowProcA@16 referenced in function "public: static long __stdcall cimg_library::CImgDisplay::_handle_events(struct HWND__ *,unsigned int,unsigned int,long)" (?_handle_events@CImgDisplay@cimg_library@@SGJPAUHWND__@@IIJ@Z)
matplot.lib(common.cpp.obj) : error LNK2019: unresolved external symbol __imp__CreateWindowExA@48 referenced in function "public: static unsigned long __stdcall cimg_library::CImgDisplay::_events_thread(void *)" (?_events_thread@CImgDisplay@cimg_library@@SGKPAX@Z)
matplot.lib(common.cpp.obj) : error LNK2019: unresolved external symbol __imp__DestroyWindow@4 referenced in function "public: void __thiscall cimg_library::CImgDisplay::_desinit_fullscreen(void)" (?_desinit_fullscreen@CImgDisplay@cimg_library@@QAEXXZ)
matplot.lib(common.cpp.obj) : error LNK2019: unresolved external symbol __imp__ShowWindow@8 referenced in function "public: static long __stdcall cimg_library::CImgDisplay::_handle_events(struct HWND__ *,unsigned int,unsigned int,long)" (?_handle_events@CImgDisplay@cimg_library@@SGJPAUHWND__@@IIJ@Z)
matplot.lib(common.cpp.obj) : error LNK2019: unresolved external symbol __imp__SetWindowPos@28 referenced in function "int __cdecl cimg_library::cimg::dialog<unsigned char>(char const * const,char const * const,char const * const,char const * const,char const * const,char const * const,char const * const,char const * const,struct cimg_library::CImg<unsigned char> const &,bool)" (??$dialog@E@cimg@cimg_library@@YAHQBD0000000ABU?$CImg@E@1@_N@Z)
matplot.lib(common.cpp.obj) : error LNK2019: unresolved external symbol __imp__SetForegroundWindow@4 referenced in function "public: static unsigned long __stdcall cimg_library::CImgDisplay::_events_thread(void *)" (?_events_thread@CImgDisplay@cimg_library@@SGKPAX@Z)
matplot.lib(common.cpp.obj) : error LNK2019: unresolved external symbol __imp__GetDC@4 referenced in function "public: static unsigned long __stdcall cimg_library::CImgDisplay::_events_thread(void *)" (?_events_thread@CImgDisplay@cimg_library@@SGKPAX@Z)
matplot.lib(common.cpp.obj) : error LNK2019: unresolved external symbol __imp__GetWindowRect@8 referenced in function "public: static unsigned long __stdcall cimg_library::CImgDisplay::_events_thread(void *)" (?_events_thread@CImgDisplay@cimg_library@@SGKPAX@Z)
matplot.lib(common.cpp.obj) : error LNK2019: unresolved external symbol __imp__AdjustWindowRect@12 referenced in function "public: static unsigned long __stdcall cimg_library::CImgDisplay::_events_thread(void *)" (?_events_thread@CImgDisplay@cimg_library@@SGKPAX@Z)
matplot.lib(common.cpp.obj) : error LNK2019: unresolved external symbol __imp__ShowCursor@4 referenced in function "public: static long __stdcall cimg_library::CImgDisplay::_handle_events(struct HWND__ *,unsigned int,unsigned int,long)" (?_handle_events@CImgDisplay@cimg_library@@SGJPAUHWND__@@IIJ@Z)
matplot.lib(common.cpp.obj) : error LNK2019: unresolved external symbol __imp__GetWindowLongA@8 referenced in function "public: static long __stdcall cimg_library::CImgDisplay::_handle_events(struct HWND__ *,unsigned int,unsigned int,long)" (?_handle_events@CImgDisplay@cimg_library@@SGJPAUHWND__@@IIJ@Z)
matplot.lib(common.cpp.obj) : error LNK2019: unresolved external symbol __imp__SetWindowLongA@12 referenced in function "public: static unsigned long __stdcall cimg_library::CImgDisplay::_events_thread(void *)" (?_events_thread@CImgDisplay@cimg_library@@SGKPAX@Z)
matplot.lib(common.cpp.obj) : error LNK2019: unresolved external symbol __imp__ChangeDisplaySettingsA@8 referenced in function "public: void __thiscall cimg_library::CImgDisplay::_desinit_fullscreen(void)" (?_desinit_fullscreen@CImgDisplay@cimg_library@@QAEXXZ)
matplot.lib(common.cpp.obj) : error LNK2019: unresolved external symbol __imp__EnumDisplaySettingsA@12 referenced in function "int __cdecl cimg_library::cimg::dialog<unsigned char>(char const * const,char const * const,char const * const,char const * const,char const * const,char const * const,char const * const,char const * const,struct cimg_library::CImg<unsigned char> const &,bool)" (??$dialog@E@cimg@cimg_library@@YAHQBD0000000ABU?$CImg@E@1@_N@Z)
matplot.lib(common.cpp.obj) : error LNK2019: unresolved external symbol __imp__SHGetSpecialFolderPathA@16 referenced in function "char const * __cdecl cimg_library::cimg::win_programfiles_path(char const * const,bool)" (?win_programfiles_path@cimg@cimg_library@@YAPBDQBD_N@Z)
test.exe : fatal error LNK1120: 20 unresolved externals
Jack Lee
  • 73
  • 5
  • All of the unresolved external symbol are Microsoft functions. – drescherjm Apr 27 '22 at 13:11
  • 1
    You'll have to link user32.lib and shell32.lib – Hans Passant Apr 27 '22 at 13:35
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?: Failure to link against appropriate libraries/object files or compile implementation files](https://stackoverflow.com/a/12574400). – Raymond Chen Apr 27 '22 at 14:16

0 Answers0