0

我使用 CImg 库编写了一个小型图像处理算法,并使用 Visual C++ Express 将其捆绑在命令行应用程序中。一切编译都没有错误并且运行良好,直到负责该项目的工程师决定他想要一个 GUI。所以我去了Qt和Qt creator。GUI 本身运行良好,但是当我将图像处理算法移过来时,一切都崩溃了。

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.

我现在的问题是,我不知道为什么我遇到了链接器问题。CImg 库是单个 H 文件。它是项目的一部分并包含在内。我知道 Qt Creator 需要将库添加到项目文件中,但是要添加什么?我的图书馆已经列在标题下。

这是项目文件。

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\

感谢您的帮助,我主要是一名嵌入式系统程序员,处理我的 C 和汇编元素变得非常令人沮丧。

4

2 回答 2

0

您需要将 Cimg 库链接到您的 GUI 程序。在 .pro 文件中添加库。

LIBS += -L$PATH_TO_CIMG_LIB -l$CIMG_LIB
于 2012-07-26T02:00:25.560 回答
0

尝试将 cimg 头文件编译为静态库并使用 (libs+=...youtstaticlibrary) 我使用 Visual Studio,所以我无法帮助您如何将库添加到 qt 中,请自行解决。

编译为静态库的步骤,例如。创建 CIMG_LIB 项目(控制台项目)(或您喜欢的任何名称)并在您的源文件中包含 cimg 标头。在源代码中使用命名空间 cimg_library(不要在此处添加任何其他内容)将项目编译为静态库

--> 在您的项目中使用 qt 包含头文件创建 GUI 项目添加您之前创建的库.. 并且您很好。

于 2013-01-29T09:24:58.227 回答