GreycLab / CImg

The CImg Library is a small and open-source C++ toolkit for image processing
http://cimg.eu
Other
1.48k stars 282 forks source link

png file not reading and returning error: in function `cimg_library::cimg::Mutex_static::trylock(unsigned int)': #354

Open bipul-mohanto opened 2 years ago

bipul-mohanto commented 2 years ago

I was trying to read and show .png image, Ubuntu 22.04. I simply added the CImg.h to my C++ project. Tried with g++ compiler, as well as CLion CMake Project. I tried in all possible way to read and show the image. But each time it is generating error in function cimg_library::cimg::Mutex_static::trylock(unsigned int):. What I am doing wrong?

//#define cimg_use_png
#include "CImg.h"
using namespace cimg_library;

int main()
{
CImg<unsigned char> image("images.png");
//CImg<unsigned char> image2 = (image/=(image.max()>255?257:1));
//image2.display();

CImgDisplay dispWindow(image, "window name");
  while (!dispWindow.is_closed())
  {
    dispWindow.wait();
  }

return 0;
}
dtschump commented 2 years ago

Hello. Your example works perfectly for me (Ubuntu 20.04). I compile with:

g++ -o foo foo.cpp -lX11 -lpthread

When you say it is generating an error, what kind of error ? Does it display something in the console?

zoldaten commented 10 months ago

i have the same issue in CodeBlocks raspberry pi Raspbian bullseye. cant compile code with line CImgDisplay dispWindow(img, "window name");

2 ways here :

dtschump commented 10 months ago

But what error does it raise in CodeBlocks? Still interested to know!

zoldaten commented 10 months ago

code in CodeBlocks:

#include "CImg.h"
using namespace cimg_library;

int main() {
  CImg<unsigned char> img("test.bmp");
  CImgDisplay dispWindow(img, "window name");
  while (!dispWindow.is_closed())
  {
    dispWindow.wait();
  }

  return 0;
}

here`s build log:

g++   -c /home/pi/CImg_sources/Chapter2/my/2_1.cpp -o /home/pi/CImg_sources/Chapter2/my/2_1.o
g++  -o /home/pi/CImg_sources/Chapter2/my/2_1 /home/pi/CImg_sources/Chapter2/my/2_1.o   
/usr/bin/ld: /home/pi/CImg_sources/Chapter2/my/2_1.o: in function `cimg_library::cimg::Mutex_static::trylock(unsigned int)':
2_1.cpp:(.text._ZN12cimg_library4cimg12Mutex_static7trylockEj[_ZN12cimg_library4cimg12Mutex_static7trylockEj]+0x2c): undefined reference to `pthread_mutex_trylock'
/usr/bin/ld: /home/pi/CImg_sources/Chapter2/my/2_1.o: in function `cimg_library::CImgDisplay::screen_width()':
2_1.cpp:(.text._ZN12cimg_library11CImgDisplay12screen_widthEv[_ZN12cimg_library11CImgDisplay12screen_widthEv]+0x2c): undefined reference to `XOpenDisplay'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay12screen_widthEv[_ZN12cimg_library11CImgDisplay12screen_widthEv]+0x9c): undefined reference to `XCloseDisplay'
/usr/bin/ld: /home/pi/CImg_sources/Chapter2/my/2_1.o: in function `cimg_library::CImgDisplay::screen_height()':
2_1.cpp:(.text._ZN12cimg_library11CImgDisplay13screen_heightEv[_ZN12cimg_library11CImgDisplay13screen_heightEv]+0x2c): undefined reference to `XOpenDisplay'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay13screen_heightEv[_ZN12cimg_library11CImgDisplay13screen_heightEv]+0x9c): undefined reference to `XCloseDisplay'
/usr/bin/ld: /home/pi/CImg_sources/Chapter2/my/2_1.o: in function `cimg_library::CImgDisplay::_handle_events(_XEvent const*)':
2_1.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x11c): undefined reference to `XUnmapWindow'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x168): undefined reference to `XCheckWindowEvent'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x238): undefined reference to `XResizeWindow'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x2ec): undefined reference to `XCheckWindowEvent'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x33c): undefined reference to `XGetWindowAttributes'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x354): undefined reference to `XSync'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x388): undefined reference to `XSetInputFocus'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x4a8): undefined reference to `XCheckWindowEvent'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x61c): undefined reference to `XCheckWindowEvent'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x654): undefined reference to `XLookupString'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x67c): undefined reference to `XQueryKeymap'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x70c): undefined reference to `XLookupString'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x744): undefined reference to `XCheckWindowEvent'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x818): undefined reference to `XCheckWindowEvent'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent[_ZN12cimg_library11CImgDisplay14_handle_eventsEPK7_XEvent]+0x888): undefined reference to `XCheckWindowEvent'
/usr/bin/ld: /home/pi/CImg_sources/Chapter2/my/2_1.o: in function `cimg_library::CImgDisplay::_events_thread(void*)':
2_1.cpp:(.text._ZN12cimg_library11CImgDisplay14_events_threadEPv[_ZN12cimg_library11CImgDisplay14_events_threadEPv]+0x5c): undefined reference to `XCheckTypedEvent'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay14_events_threadEPv[_ZN12cimg_library11CImgDisplay14_events_threadEPv]+0x94): undefined reference to `XCheckMaskEvent'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay14_events_threadEPv[_ZN12cimg_library11CImgDisplay14_events_threadEPv]+0x178): undefined reference to `pthread_testcancel'
/usr/bin/ld: /home/pi/CImg_sources/Chapter2/my/2_1.o: in function `cimg_library::CImgDisplay::_set_colormap(unsigned long&, unsigned int)':
2_1.cpp:(.text._ZN12cimg_library11CImgDisplay13_set_colormapERmj[_ZN12cimg_library11CImgDisplay13_set_colormapERmj]+0x30c): undefined reference to `XStoreColors'
/usr/bin/ld: /home/pi/CImg_sources/Chapter2/my/2_1.o: in function `cimg_library::CImgDisplay::_map_window()':
2_1.cpp:(.text._ZN12cimg_library11CImgDisplay11_map_windowEv[_ZN12cimg_library11CImgDisplay11_map_windowEv]+0x30): undefined reference to `XMapRaised'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay11_map_windowEv[_ZN12cimg_library11CImgDisplay11_map_windowEv]+0x54): undefined reference to `XWindowEvent'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay11_map_windowEv[_ZN12cimg_library11CImgDisplay11_map_windowEv]+0xb8): undefined reference to `XGetWindowAttributes'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay11_map_windowEv[_ZN12cimg_library11CImgDisplay11_map_windowEv]+0xd0): undefined reference to `XSync'
/usr/bin/ld: /home/pi/CImg_sources/Chapter2/my/2_1.o: in function `cimg_library::CImgDisplay::_paint(bool)':
2_1.cpp:(.text._ZN12cimg_library11CImgDisplay6_paintEb[_ZN12cimg_library11CImgDisplay6_paintEb]+0xb8): undefined reference to `XSendEvent'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay6_paintEb[_ZN12cimg_library11CImgDisplay6_paintEb]+0x12c): undefined reference to `XPutImage'
/usr/bin/ld: /home/pi/CImg_sources/Chapter2/my/2_1.o: in function `cimg_library::CImgDisplay::_init_fullscreen()':
2_1.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x88): undefined reference to `XDefaultScreen'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x94): undefined reference to `XBlackPixel'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0xfc): undefined reference to `XCreateWindow'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x120): undefined reference to `XSelectInput'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x134): undefined reference to `XMapRaised'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x154): undefined reference to `XWindowEvent'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x180): undefined reference to `XGetWindowAttributes'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay16_init_fullscreenEv[_ZN12cimg_library11CImgDisplay16_init_fullscreenEv]+0x198): undefined reference to `XSync'
/usr/bin/ld: /home/pi/CImg_sources/Chapter2/my/2_1.o: in function `cimg_library::CImgDisplay::_desinit_fullscreen()':
2_1.cpp:(.text._ZN12cimg_library11CImgDisplay19_desinit_fullscreenEv[_ZN12cimg_library11CImgDisplay19_desinit_fullscreenEv]+0x38): undefined reference to `XUngrabKeyboard'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay19_desinit_fullscreenEv[_ZN12cimg_library11CImgDisplay19_desinit_fullscreenEv]+0x5c): undefined reference to `XDestroyWindow'
/usr/bin/ld: /home/pi/CImg_sources/Chapter2/my/2_1.o: in function `cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)':
2_1.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0xf8): undefined reference to `XOpenDisplay'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x34c): undefined reference to `XVisualIDFromVisual'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x370): undefined reference to `XGetVisualInfo'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x3d0): undefined reference to `XFree'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x410): undefined reference to `pthread_create'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x5bc): undefined reference to `XCreateWindow'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x630): undefined reference to `XCreateSimpleWindow'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x660): undefined reference to `XSelectInput'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x6a0): undefined reference to `XStoreName'
/usr/bin/ld: 2_1.cpp:(.text._ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb[_ZN12cimg_library11CImgDisplay7_assignEjjPKcjbb]+0x708): undefined reference to `XCreateColormap'
Process terminated with status 1 (0 minute(s), 16 second(s))
50 error(s), 0 warning(s) (0 minute(s), 16 second(s))