Won't build on Mac
Closed this issue · 4 comments
Environment: Mac OS 10.10.3 (Yosemite) with X11 (XQuartz) installed, working, and linked in /opt/X11. I'm using g++ (clang).
Steps to reproduce: Clone github, attempt to compile /examples/CImg_demo.cpp using g++.
Expected results: Successful compilation.
Actual results: Build fails, shows the following error:
Undefined symbols for architecture x86_64:
"_XAllocClassHint", referenced from:
cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool) in readJpeg-49dd1e.o
"_XCheckMaskEvent", referenced from:
cimg_library::CImgDisplay::_events_thread(void*) in readJpeg-49dd1e.o
"_XCheckTypedEvent", referenced from:
cimg_library::CImgDisplay::_events_thread(void*) in readJpeg-49dd1e.o
"_XCheckWindowEvent", referenced from:
cimg_library::CImgDisplay::_handle_events(_XEvent const*) in readJpeg-49dd1e.o
"_XCloseDisplay", referenced from:
cimg_library::CImgDisplay::screen_width() in readJpeg-49dd1e.o
cimg_library::CImgDisplay::screen_height() in readJpeg-49dd1e.o
"_XCreateColormap", referenced from:
cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool) in readJpeg-49dd1e.o
"_XCreateImage", referenced from:
void cimg_library::CImgDisplay::_resize<unsigned char>(unsigned char, unsigned int, unsigned int, bool) in readJpeg-49dd1e.o
void cimg_library::CImgDisplay::_resize<unsigned short>(unsigned short, unsigned int, unsigned int, bool) in readJpeg-49dd1e.o
void cimg_library::CImgDisplay::_resize<unsigned int>(unsigned int, unsigned int, unsigned int, bool) in readJpeg-49dd1e.o
cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool) in readJpeg-49dd1e.o
cimg_library::CImgDisplay::_init_fullscreen() in readJpeg-49dd1e.o
"_XCreateSimpleWindow", referenced from:
cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool) in readJpeg-49dd1e.o
"_XCreateWindow", referenced from:
cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool) in readJpeg-49dd1e.o
cimg_library::CImgDisplay::_init_fullscreen() in readJpeg-49dd1e.o
"_XDestroyWindow", referenced from:
cimg_library::CImgDisplay::assign() in readJpeg-49dd1e.o
cimg_library::CImgDisplay::_desinit_fullscreen() in readJpeg-49dd1e.o
"_XFree", referenced from:
cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool) in readJpeg-49dd1e.o
"_XFreeColormap", referenced from:
cimg_library::CImgDisplay::assign() in readJpeg-49dd1e.o
"_XGetVisualInfo", referenced from:
cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool) in readJpeg-49dd1e.o
"_XGetWindowAttributes", referenced from:
cimg_library::CImgDisplay::resize(int, int, bool) in readJpeg-49dd1e.o
cimg_library::CImgDisplay::_init_fullscreen() in readJpeg-49dd1e.o
cimg_library::CImgDisplay::_map_window() in readJpeg-49dd1e.o
cimg_library::CImgDisplay::_handle_events(_XEvent const*) in readJpeg-49dd1e.o
"_XGrabKeyboard", referenced from:
cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool) in readJpeg-49dd1e.o
"_XInternAtom", referenced from:
cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool) in readJpeg-49dd1e.o
"_XLookupString", referenced from:
cimg_library::CImgDisplay::_handle_events(_XEvent const*) in readJpeg-49dd1e.o
"_XMapRaised", referenced from:
cimg_library::CImgDisplay::_init_fullscreen() in readJpeg-49dd1e.o
cimg_library::CImgDisplay::_map_window() in readJpeg-49dd1e.o
"_XMoveWindow", referenced from:
cimg_library::CImgDisplay::move(int, int) in readJpeg-49dd1e.o
"_XOpenDisplay", referenced from:
cimg_library::CImgDisplay::screen_width() in readJpeg-49dd1e.o
cimg_library::CImgDisplay::screen_height() in readJpeg-49dd1e.o
cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool) in readJpeg-49dd1e.o
"_XPutImage", referenced from:
cimg_library::CImgDisplay::_paint(bool) in readJpeg-49dd1e.o
cimg_library::CImgDisplay::_init_fullscreen() in readJpeg-49dd1e.o
"_XQueryKeymap", referenced from:
cimg_library::CImgDisplay::_handle_events(_XEvent const*) in readJpeg-49dd1e.o
"_XResizeWindow", referenced from:
cimg_library::CImgDisplay::resize(int, int, bool) in readJpeg-49dd1e.o
cimg_library::CImgDisplay::_handle_events(_XEvent const*) in readJpeg-49dd1e.o
"_XSelectInput", referenced from:
cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool) in readJpeg-49dd1e.o
cimg_library::CImgDisplay::_init_fullscreen() in readJpeg-49dd1e.o
"_XSendEvent", referenced from:
cimg_library::CImgDisplay::_paint(bool) in readJpeg-49dd1e.o
"_XSetClassHint", referenced from:
cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool) in readJpeg-49dd1e.o
"_XSetInputFocus", referenced from:
cimg_library::CImgDisplay::_handle_events(_XEvent const*) in readJpeg-49dd1e.o
"_XSetWMProtocols", referenced from:
cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool) in readJpeg-49dd1e.o
"_XSetWindowColormap", referenced from:
cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool) in readJpeg-49dd1e.o
"_XStoreColors", referenced from:
cimg_library::CImgDisplay::_set_colormap(unsigned long&, unsigned int) in readJpeg-49dd1e.o
"_XStoreName", referenced from:
cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool) in readJpeg-49dd1e.o
"_XSync", referenced from:
cimg_library::CImgDisplay::assign() in readJpeg-49dd1e.o
cimg_library::CImgDisplay::_init_fullscreen() in readJpeg-49dd1e.o
cimg_library::CImgDisplay::_map_window() in readJpeg-49dd1e.o
cimg_library::CImgDisplay::_handle_events(_XEvent const*) in readJpeg-49dd1e.o
"_XUngrabKeyboard", referenced from:
cimg_library::CImgDisplay::_desinit_fullscreen() in readJpeg-49dd1e.o
"_XUnmapWindow", referenced from:
cimg_library::CImgDisplay::_handle_events(_XEvent const*) in readJpeg-49dd1e.o
"_XVisualIDFromVisual", referenced from:
cimg_library::CImgDisplay::_assign(unsigned int, unsigned int, char const*, unsigned int, bool, bool) in readJpeg-49dd1e.o
"_XWindowEvent", referenced from:
cimg_library::CImgDisplay::_init_fullscreen() in readJpeg-49dd1e.o
cimg_library::CImgDisplay::_map_window() in readJpeg-49dd1e.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
It compiles successfully if I set "cimg_display" to 0 for my OS, (Line 205) however I don't believe this is a fix.
What are the g++ options you provided ? Did you add the flags '-lX11 -lpthread' when compiling ? They are mandatory if you want to use the display capabilities of CImg.
Wasn't providing any arguments. Added -lX11 -lpthread
and got a library not found error (ld: library not found for -lX11
), but fixed it by adding -L/usr/X11/lib -I/usr/X11/include
.
Everything seems to be working well now. Thank you.
How can I compile on Mac, without X11?
I am not in need of the display capabilities of X11 for my project.
Just define 'cimg_display=0' when compiling, either by inserting
#define cimg_display 0
#include "CImg.h"
before the inclusion of CImg.h
, or by specifying the flag -Dcimg_display=0
when compiling (with g++
).