CImg库-链接错误

4
我尝试使用cimg库。我已经包含了CImg.h头文件。但是当我尝试编译时,会出现链接错误。
/tmp/cc2tvYsW.o: In function `cimg_library::cimg::Mutex_info::trylock(unsigned int)':
tafelbilder.cpp:(.text._ZN12cimg_library4cimg10Mutex_info7trylockEj[_ZN12cimg_library4cimg10Mutex_info7trylockEj]+0x2b): undefined reference to `pthread_mutex_trylock'
/tmp/cc2tvYsW.o: In function `cimg_library::CImgDisplay::screen_width()':
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay12screen_widthEv[_ZN12cimg_library11CImgDisplay12screen_widthEv]+0x2c): undefined reference to `XOpenDisplay'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay12screen_widthEv[_ZN12cimg_library11CImgDisplay12screen_widthEv]+0x98): undefined reference to `XCloseDisplay'
/tmp/cc2tvYsW.o: In function `cimg_library::CImgDisplay::screen_height()':
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay13screen_heightEv[_ZN12cimg_library11CImgDisplay13screen_heightEv]+0x2c): undefined reference to `XOpenDisplay'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay13screen_heightEv[_ZN12cimg_library11CImgDisplay13screen_heightEv]+0x98): undefined reference to `XCloseDisplay'
/tmp/cc2tvYsW.o: In function `cimg_library::CImgDisplay::_handle_events(_XEvent const*)':
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0xc7): undefined reference to `XUnmapWindow'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x12a): undefined reference to `XCheckWindowEvent'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x218): undefined reference to `XResizeWindow'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x2f5): undefined reference to `XCheckWindowEvent'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x348): undefined reference to `XGetWindowAttributes'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x35e): undefined reference to `XSync'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x390): undefined reference to `XSetInputFocus'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x4ce): undefined reference to `XCheckWindowEvent'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x64b): undefined reference to `XCheckWindowEvent'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x68f): undefined reference to `XLookupString'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x6cc): undefined reference to `XQueryKeymap'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x775): undefined reference to `XLookupString'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x7c6): undefined reference to `XCheckWindowEvent'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x8a9): undefined reference to `XCheckWindowEvent'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x922): undefined reference to `XCheckWindowEvent'
/tmp/cc2tvYsW.o: In function `cimg_library::CImgDisplay::_events_thread(void*)':
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay14_events_threadEPv[_ZN12cimg_library11CImgDisplay14_events_threadEPv]+0x84): undefined reference to `XCheckTypedEvent'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay14_events_threadEPv[_ZN12cimg_library11CImgDisplay14_events_threadEPv]+0xb8): undefined reference to `XCheckMaskEvent'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay14_events_threadEPv[_ZN12cimg_library11CImgDisplay14_events_threadEPv]+0x19d): undefined reference to `pthread_testcancel'
/tmp/cc2tvYsW.o: In function `cimg_library::CImgDisplay::_set_colormap(unsigned long&, unsigned int)':
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay13_set_colormapERmj[_ZN12cimg_library11CImgDisplay13_set_colormapERmj]+0x29d): undefined reference to `XStoreColors'
/tmp/cc2tvYsW.o: In function `cimg_library::CImgDisplay::_map_window()':
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay11_map_windowEv[_ZN12cimg_library11CImgDisplay11_map_windowEv]+0x5b): undefined reference to `XMapRaised'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay11_map_windowEv[_ZN12cimg_library11CImgDisplay11_map_windowEv]+0x87): undefined reference to `XWindowEvent'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay11_map_windowEv[_ZN12cimg_library11CImgDisplay11_map_windowEv]+0xeb): undefined reference to `XGetWindowAttributes'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay11_map_windowEv[_ZN12cimg_library11CImgDisplay11_map_windowEv]+0x10a): undefined reference to `XSync'
/tmp/cc2tvYsW.o: In function `cimg_library::CImgDisplay::_paint(bool)':
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay6_paintEb[_ZN12cimg_library11CImgDisplay6_paintEb]+0x124): undefined reference to `XSendEvent'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay6_paintEb[_ZN12cimg_library11CImgDisplay6_paintEb]+0x1b2): undefined reference to `XPutImage'
/tmp/cc2tvYsW.o: In function `cimg_library::CImgDisplay::_init_fullscreen()':
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x117): undefined reference to `XCreateWindow'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x20e): undefined reference to `XCreateImage'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x23e): undefined reference to `XSelectInput'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x25e): undefined reference to `XMapRaised'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x28a): undefined reference to `XWindowEvent'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x30d): undefined reference to `XPutImage'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x338): undefined reference to `XGetWindowAttributes'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x34e): undefined reference to `XSync'
/tmp/cc2tvYsW.o: In function `cimg_library::CImgDisplay::_desinit_fullscreen()':
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay19_desinit_fullscreenEv[_ZN12cimg_library11CImgDisplay19_desinit_fullscreenEv]+0x37): undefined reference to `XUngrabKeyboard'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay19_desinit_fullscreenEv[_ZN12cimg_library11CImgDisplay19_desinit_fullscreenEv]+0x61): undefined reference to `XDestroyWindow'
/tmp/cc2tvYsW.o: In function `cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)':
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x124): undefined reference to `XOpenDisplay'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x375): undefined reference to `XVisualIDFromVisual'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x3a1): undefined reference to `XGetVisualInfo'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x402): undefined reference to `XFree'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x447): undefined reference to `pthread_create'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x634): undefined reference to `XCreateWindow'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x6bc): undefined reference to `XCreateSimpleWindow'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x6f9): undefined reference to `XSelectInput'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x73e): undefined reference to `XStoreName'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x7a7): undefined reference to `XCreateColormap'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x80e): undefined reference to `XSetWindowColormap'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x813): undefined reference to `XAllocClassHint'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x861): undefined reference to `XSetClassHint'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x870): undefined reference to `XFree'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x98f): undefined reference to `XCreateImage'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x9c0): undefined reference to `XInternAtom'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x9ed): undefined reference to `XInternAtom'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0xa31): undefined reference to `XSetWMProtocols'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0xa76): undefined reference to `XGrabKeyboard'
/tmp/cc2tvYsW.o: In function `cimg_library::CImgDisplay::assign()':
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay6assignEv[_ZN12cimg_library11CImgDisplay6assignEv]+0x124): undefined reference to `XDestroyWindow'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay6assignEv[_ZN12cimg_library11CImgDisplay6assignEv]+0x19c): undefined reference to `XFreeColormap'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay6assignEv[_ZN12cimg_library11CImgDisplay6assignEv]+0x1bc): undefined reference to `XSync'
/tmp/cc2tvYsW.o: In function `cimg_library::CImgDisplay::resize(int, int, bool)':
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay6resizeEiib[_ZN12cimg_library11CImgDisplay6resizeEiib]+0x272): undefined reference to `XResizeWindow'
tafelbilder.cpp:(.text._ZN12cimg_library11CImgDisplay6resizeEiib[_ZN12cimg_library11CImgDisplay6resizeEiib]+0x299): undefined reference to `XGetWindowAttributes'
/tmp/cc2tvYsW.o: In function `cimg_l

不要在链接器命令行或makefiles中添加难以诊断的东西。 - πάντα ῥεῖ
2个回答

9

使用这些编译器选项可以使其正常工作

-L/usr/X11R6/lib -lm -lpthread -lX11

1
你介意解释一下吗? - Johiasburg Frowell
该库依赖于系统中的其他库。-lpthread告诉库链接pthread库,-L/usr/X11R6/lib告诉编译器还要在/usr/X11R6/lib中搜索库。 - Owen Delahoy

0
你还需要链接库。请查阅编译器说明以了解如何操作。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接