0

I wrote a small image processing algorithm using the CImg library and bundled it in a command line application using Visual C++ Express. Everything compiled error free and ran well, until the engineer in charge of the project decided he wanted a GUI. So I went to Qt and Qt creator. The GUI functioned fine by itself, but all hell breaks loose when I move my image processing algorithm over.

mainwindow.obj : error LNK2019: unresolved external 
symbol__imp__SHGetSpecialFolderPathA@16 referenced in function "char const * __cdecl 
cimg_library::cimg::programfiles_path(char const * const,bool)" 
(?programfiles_path@cimg@cimg_library@@YAPBDQBD_N@Z)

mainwindow.obj : error LNK2019: unresolved external symbol 
__imp__EnumDisplaySettingsW@12 referenced in function "public: static int __cdecl  
cimg_library::CImgDisplay::screen_width(void)" 
(?screen_width@CImgDisplay@cimg_library@@SAHXZ)

mainwindow.obj : error LNK2019: unresolved external symbol __imp__DestroyWindow@4    
referenced in function "public: struct cimg_library::CImgDisplay & __thiscall  
cimg_library::CImgDisplay::assign(void)" 
(?assign@CImgDisplay@cimg_library@@QAEAAU12@XZ)

mainwindow.obj : error LNK2019: unresolved external symbol   
__imp__ChangeDisplaySettingsW@8 referenced in function "public: void __thiscall 
cimg_library::CImgDisplay::_desinit_fullscreen(void)" 
(?_desinit_fullscreen@CImgDisplay@cimg_library@@QAEXXZ)

mainwindow.obj : error LNK2019: unresolved external symbol __imp__SetWindowPos@28 
referenced in function "public: struct cimg_library::CImgDisplay & __thiscall 
cimg_library::CImgDisplay::resize(int,int,bool)" 
(?resize@CImgDisplay@cimg_library@@QAEAAU12@HH_N@Z)

mainwindow.obj : error LNK2019: unresolved external symbol __imp__AdjustWindowRect@12 
referenced in function "public: struct cimg_library::CImgDisplay & __thiscall 
cimg_library::CImgDisplay::resize(int,int,bool)" 
(?resize@CImgDisplay@cimg_library@@QAEAAU12@HH_N@Z)

mainwindow.obj : error LNK2019: unresolved external symbol __imp__DispatchMessageW@4 
referenced in function "public: static unsigned long __stdcall 
cimg_library::CImgDisplay::_events_thread(void *)" 
(?_events_thread@CImgDisplay@cimg_library@@SGKPAX@Z)

mainwindow.obj : error LNK2019: unresolved external symbol __imp__GetMessageW@16 
referenced in function "public: static unsigned long __stdcall 
cimg_library::CImgDisplay::_events_thread(void *)" 
(?_events_thread@CImgDisplay@cimg_library@@SGKPAX@Z)

mainwindow.obj : error LNK2019: unresolved external symbol __imp__SetWindowLongW@12 
referenced in function "public: static unsigned long __stdcall 
cimg_library::CImgDisplay::_events_thread(void *)" 
(?_events_thread@CImgDisplay@cimg_library@@SGKPAX@Z)

mainwindow.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)

mainwindow.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)

mainwindow.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)

mainwindow.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)

mainwindow.obj : error LNK2019: unresolved external symbol __imp__DefWindowProcW@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)

mainwindow.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)

mainwindow.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)

mainwindow.obj : error LNK2019: unresolved external symbol __imp__PeekMessageW@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)

mainwindow.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)

mainwindow.obj : error LNK2019: unresolved external symbol __imp__GetWindowLongW@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)

mainwindow.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)

debug\final.exe : fatal error LNK1120: 20 unresolved externals

NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC  
\BIN\link.EXE"' : return code '0x460'

Stop.

NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC  
\BIN\nmake.exe"' : return code '0x2'

Stop.

My problem now, is I have no idea why I'm having linker trouble. The CImg library is a single H file. It's part of the project and included. I know Qt Creator needs libraries added to the project file, but what is there to add? My library is already listed under headers.

Here is the project file.

QT       += core gui

TARGET = final
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h \
    C:/includes/CImg.h

FORMS    += mainwindow.ui

INCLUDEPATH += C:\includes\

Thanks for the assistance, I'm primarily an embedded systems programmer, and working out of my C and assembly element is getting very frustrating.

Mat
  • 202,337
  • 40
  • 393
  • 406
Matt Young
  • 360
  • 1
  • 3
  • 11

2 Answers2

0

You need to link the Cimg library to you GUI program. Add the library in your .pro file.

LIBS += -L$PATH_TO_CIMG_LIB -l$CIMG_LIB
liuyi.luo
  • 1,219
  • 7
  • 11
  • When I add that line, it tries to add CIMG_LIB.lib, which doesn't exist. The reason I'm so confused by this is the fact CImg is contained in a single H file. Including it should be enough. It's making it through the preprocessor, compiler, and assembler. Why is it throwing up the flag at the linker? – Matt Young Jul 26 '12 at 14:04
  • 1
    I'am sorry. I don't know Cimg is compiled with your source code, instead as a static library by linked. The unresolved symbol are in windows SDK library. Retry this `LIBS += -lAdvapi32 -lgdi32 -luser32 -lshell32`. – liuyi.luo Jul 27 '12 at 07:08
0

try compiling the cimg header file to a static library and use (libs+=...youtstaticlibrary) i use visual studio so i cant help you how to add library's to qt , figure that out your self.

steps to compile to static library eg. create CIMG_LIB project(console project) (or any name you like) and in your source file include cimg header. use namespace cimg_library in source code ( dont add anything else here ) compile the project to static library

--> create GUI project with qt include header file in your project add library that you previously created.. and ur good to go.

Serak Shiferaw
  • 993
  • 2
  • 11
  • 32