# Cimg sous Mac



## neax (22 Mars 2009)

Bonjour,


J'ai besoin d'utiliser la librairie Cimg en C++ pour divers projets.

Lorsque que je rajoute le fchier Cimg.h à mon projet, et que je compile, il trouve bien le fichier Cimg.h (si je change son nom, il m'affiche clairement une erreur), mais j'obtiens diverses erreurs. J'ai essayé de compiler sous eclipse (sous windows avec eclipse, je n'ai pas de pb) mais j'ai les mêmes erreurs. Le code est celui du tuto de Cimg


```
//============================================================================
// Name        : test.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>


#include "CImg.h"
  using namespace cimg_library;

  int main(int argc, char *argv[]) {
    CImg<unsigned char> image("lena.jpg"), visu(500,400,1,3,0);
    const unsigned char red[] = { 255,0,0 }, green[] = { 0,255,0 }, blue[] = { 0,0,255 };
    image.blur(2.5);
    CImgDisplay main_disp(image,"Click a point"), draw_disp(visu,"Intensity profile");
    while (!main_disp.is_closed && !draw_disp.is_closed) {
      main_disp.wait();
      if (main_disp.button && main_disp.mouse_y>=0) {
        const int y = main_disp.mouse_y;
        visu.fill(0).draw_graph(image.get_crop(0,y,0,0,image.dimx()-1,y,0,0),red,1,1,0,255,0);
        visu.draw_graph(image.get_crop(0,y,0,1,image.dimx()-1,y,0,1),green,1,1,0,255,0);
        visu.draw_graph(image.get_crop(0,y,0,2,image.dimx()-1,y,0,2),blue,1,1,0,255,0).display(draw_disp);
        }
      }
    return 0;
  }
```




```
**** Build of configuration Debug for project test ****

make all 
Building target: test
Invoking: MacOS X C++ Linker
g++  -o "test"  ./src/test.o   
Undefined symbols:
  "_XUnlockDisplay", referenced from:
      cimg_library::CImgDisplay::_events_thread(void*)   in test.o
      cimg_library::CImgDisplay::wait_all()      in test.o
      cimg_library::CImgDisplay::assign()      in test.o
      cimg_library::CImgDisplay::paint(bool)  in test.o
      cimg_library::CImgDisplay::show()      in test.o
      cimg_library::CImgDisplay::move(int, int)in test.o
      cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)in test.o
      cimg_library::CImgDisplay::resize(int, int, bool)in test.o
      cimg_library::CImgDisplay& cimg_library::CImgDisplay::render<unsigned char>(cimg_library::CImg<unsigned char> const&, bool)in test.o
  "_XGetVisualInfo", referenced from:
      cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)in test.o
  "_XStoreColors", referenced from:
      cimg_library::CImgDisplay::_set_colormap(unsigned long&, unsigned int)in test.o
  "_XCheckWindowEvent", referenced from:
      cimg_library::CImgDisplay::_handle_events(_XEvent const*)  in test.o
      cimg_library::CImgDisplay::_handle_events(_XEvent const*)  in test.o
      cimg_library::CImgDisplay::_handle_events(_XEvent const*)  in test.o
      cimg_library::CImgDisplay::_handle_events(_XEvent const*)  in test.o
      cimg_library::CImgDisplay::_handle_events(_XEvent const*)  in test.o
      cimg_library::CImgDisplay::_handle_events(_XEvent const*)  in test.o
      cimg_library::CImgDisplay::_handle_events(_XEvent const*)  in test.o
  "_XCheckMaskEvent", referenced from:
      cimg_library::CImgDisplay::_events_thread(void*)   in test.o
  "_XSync", referenced from:
      cimg_library::CImgDisplay::_map_window()       in test.o
      cimg_library::CImgDisplay::_map_window()       in test.o
      cimg_library::CImgDisplay::_map_window()       in test.o
      cimg_library::CImgDisplay::_paint(bool)  in test.o
      cimg_library::CImgDisplay::_handle_events(_XEvent const*)  in test.o
      cimg_library::CImgDisplay::assign()      in test.o
      cimg_library::CImgDisplay::_init_fullscreen()       in test.o
  "_XSetWindowColormap", referenced from:
      cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)in test.o
  "_XSelectInput", referenced from:
      cimg_library::CImgDisplay::_init_fullscreen()       in test.o
      cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)in test.o
  "_XGetWindowAttributes", referenced from:
      cimg_library::CImgDisplay::_map_window()       in test.o
      cimg_library::CImgDisplay::_handle_events(_XEvent const*)  in test.o
      cimg_library::CImgDisplay::_init_fullscreen()       in test.o
  "_XLookupString", referenced from:
      cimg_library::CImgDisplay::_handle_events(_XEvent const*)  in test.o
      cimg_library::CImgDisplay::_handle_events(_XEvent const*)  in test.o
  "_XVisualIDFromVisual", referenced from:
      cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)in test.o
  "_XPutImage", referenced from:
      cimg_library::CImgDisplay::_paint(bool)  in test.o
      cimg_library::CImgDisplay::_init_fullscreen()       in test.o
  "_XGrabKeyboard", referenced from:
      cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)in test.o
  "_XInternAtom", referenced from:
      cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)in test.o
      cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)in test.o
  "_XStoreName", referenced from:
      cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)in test.o
  "_XWindowEvent", referenced from:
      cimg_library::CImgDisplay::_map_window()       in test.o
      cimg_library::CImgDisplay::_init_fullscreen()       in test.o
  "_XOpenDisplay", referenced from:
      cimg_library::CImgDisplay::screen_dimy()       in test.o
      cimg_library::CImgDisplay::screen_dimx()       in test.o
      cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)in test.o
  "_XLockDisplay", referenced from:
      cimg_library::CImgDisplay::_events_thread(void*)   in test.o
      cimg_library::CImgDisplay::wait_all()      in test.o
      cimg_library::CImgDisplay::assign()      in test.o
      cimg_library::CImgDisplay::paint(bool)  in test.o
      cimg_library::CImgDisplay::show()      in test.o
      cimg_library::CImgDisplay::move(int, int)in test.o
      cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)in test.o
      cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)in test.o
      cimg_library::CImgDisplay::resize(int, int, bool)in test.o
      cimg_library::CImgDisplay& cimg_library::CImgDisplay::render<unsigned char>(cimg_library::CImg<unsigned char> const&, bool)in test.o
  "_XCreateColormap", referenced from:
      cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)in test.o
  "_XCreateImage", referenced from:
      void cimg_library::CImgDisplay::_resize<unsigned char>(unsigned char, unsigned int, unsigned int, bool)in test.o
      void cimg_library::CImgDisplay::_resize<unsigned short>(unsigned short, unsigned int, unsigned int, bool)in test.o
      void cimg_library::CImgDisplay::_resize<unsigned int>(unsigned int, unsigned int, unsigned int, bool)in test.o
      cimg_library::CImgDisplay::_init_fullscreen()       in test.o
      cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)in test.o
  "_XCreateWindow", referenced from:
      cimg_library::CImgDisplay::_init_fullscreen()       in test.o
      cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)in test.o
  "_XCloseDisplay", referenced from:
      cimg_library::CImgDisplay::screen_dimy()       in test.o
      cimg_library::CImgDisplay::screen_dimx()       in test.o
  "_XMapRaised", referenced from:
      cimg_library::CImgDisplay::_map_window()       in test.o
      cimg_library::CImgDisplay::_init_fullscreen()       in test.o
  "_XUnmapWindow", referenced from:
      cimg_library::CImgDisplay::_handle_events(_XEvent const*)  in test.o
  "_XFreeColormap", referenced from:
      cimg_library::CImgDisplay::assign()      in test.o
  "_XMoveWindow", referenced from:
      cimg_library::CImgDisplay::move(int, int)in test.o
  "_XNextEvent", referenced from:
      cimg_library::CImgDisplay::wait_all()      in test.o
  "_XCreateSimpleWindow", referenced from:
      cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)in test.o
  "_XCheckTypedEvent", referenced from:
      cimg_library::CImgDisplay::_events_thread(void*)   in test.o
  "_XSendEvent", referenced from:
      cimg_library::CImgDisplay::_paint(bool)  in test.o
  "_XDestroyWindow", referenced from:
      cimg_library::CImgDisplay::_desinit_fullscreen()       in test.o
      cimg_library::CImgDisplay::assign()      in test.o
  "_XUngrabKeyboard", referenced from:
      cimg_library::CImgDisplay::_desinit_fullscreen()       in test.o
  "_XResizeWindow", referenced from:
      cimg_library::CImgDisplay::_handle_events(_XEvent const*)  in test.o
      cimg_library::CImgDisplay::resize(int, int, bool)in test.o
  "_XInitThreads", referenced from:
      cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)in test.o
  "_XFree", referenced from:
      cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)in test.o
  "_XSetWMProtocols", referenced from:
      cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool)in test.o
  "_XSetInputFocus", referenced from:
      cimg_library::CImgDisplay::_handle_events(_XEvent const*)  in test.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [test] Error 1
```



A priori, il arrive pas à faire appel à certaines fonctions, mais je vois pas trop pourquoi ...
Est ce que qqun saurait me dire pourquoi et que faire pour corriger ce problème ?



Merci d'avance


----------



## ntx (22 Mars 2009)

Un .h n'est pas une librairie, il ne comprend que les déclarations des symboles pas leurs définitions. Il faut ajouter l'exécutable qui contient les symboles utilisés, le .a, .so ou .dylib, à ta ligne de compilation.
Voir le mode d'emploi de g++ 

[Edit]
Apparemment ils ont mis leur code dans le .h, donc reprend les lignes de compilations tel quelles sont définies pour compiler les exemples :

```
g++ -o use_RGBclass use_RGBclass.cpp -I.. -Wall -W -ansi -pedantic -lm -Dcimg_display=3 -framework Carbon -Dcimg_use_vt100
```
Les symboles qu'il te manque sont dans les librairies X11.


----------



## tatouille (22 Mars 2009)

oui il manque des options... la tu demandes de compiler avec un display xwindow (sans mettre de lien vers la libX et les autres libs donc depend Cimg dans ce cas)
plutot que d'utiliser le CGDisplay

un conseil utilise openGL...


----------

