2016-10-25 4 views
0

Это мой Makefile:ошибки Использование Makefile для компиляции FLTK исходного кода, который использует изображения

# object files 
OBJS = main.o 

# compiler 
# since fltk-config --cxx displays the c++ compiler that was used to compile FLTK (g++) 
#  we just use it instead of ... for safety purpose 
#CC = g++-5 -std=c++11 
CXX = $(shell fltk-config --cxx) 

# debugging flag 
DEBUG = -g 

# flags used in compiling and creating object files 
# - fltk-config --cxxflags displays C++ complier options to use when compiling FLTK 
#  source files 
#  + can also be used when compiling non FLTK files 
# - Wall: tells compiler to print all warnings 
# - c: is needed to create object file, i.e. .o files 
CXXFLAGS = $(shell fltk-config --cxxflags) -Wall -c $(DEBUG) 

# flags used in linking 
# - fltk-config --ldflags displays the linker options to use when linking a FLTK app 
# - ??? fltk-config --ldstaticflags ... when lking a FLTK app to the static FLTK libraries 
#LFLAGS = $(shell fltk-config --ldflags) -Wall $(DEBUG) 
# may need below options when using images 
LINKFLTK_IMG = $(shell fltk-config --use-images --ldstaticflags) -Wall $(DEBUG) 
#LINKFLTK_IMG = $(shell fltk-config --use-images --ldflags) -Wall $(DEBUG) 

# FLTK libraries 
FLTKLIB = -lfltk 

executable: $(OBJS) 
    $(CXX) $(LINKFLTK_IMG) $(OBJS) $(FLTKLIB) 

main.o: main.cpp 
    $(CXX) $(CXXFLAGS) main.cpp 

clean: 
    \rm *.o a.out 

Это код, который я пытаюсь скомпилировать:

#include <FL/Fl.H> 
#include <FL/Fl_Window.H> 
#include <FL/Fl_Box.H> 
#include <FL/Fl_Shared_Image.H> 
#include <FL/Fl_JPEG_Image.H> 

int main() 
{ 
    // const int x = 505; 
    const int x = 1000; 

    //const int y = 340; 
    const int y = 600; 

    const int border = 10; 

    // init the image library 
    fl_register_images(); 

    // create a window and enclosed box 
    Fl_Window *win = new Fl_Window(x+3*border, y+3*border); 
    Fl_Box *box = new Fl_Box(border, border, x+border, y+border); 

    // load jpeg image into memory and attach to the box 
    Fl_JPEG_Image *jpg = new Fl_JPEG_Image("moon.jpg"); 
    box->image(*jpg); 

    // done defining the new window 
    win->end(); 

    // show the window and then delegate control to FLTK 
    win->show(); 
    return(Fl::run()); 
} 

Это ошибка:

/usr/bin/ld: cannot find -lpng 
/usr/bin/ld: cannot find -lz 
/usr/bin/ld: cannot find -ljpeg 
/usr/bin/ld: cannot find -lXft 
/usr/bin/ld: cannot find -lfontconfig 
/usr/bin/ld: cannot find -lfontconfig 
/usr/bin/ld: cannot find -lXinerama 
collect2: error: ld returned 1 exit status 
make: *** [executable] Error 1 

После выполнения команды make файл main.o был успешно сгенерирован. Поэтому я думаю, что что-то не так с процессом связывания. Отправьте справку.

+0

Насколько я помню, png, jpeg и связанные с ними библиотеки (например, libz) не включены в библиотеку fltk, поэтому вам нужно связать их вручную – VladimirM

ответ

0

Зависит от версии Linux вы используете

SUSE - Судо Zypper установить

  • libjpeg62-Devel или libjpeg-Devel
  • libpng12-Devel или Libpng-Devel
  • zlib- devel
  • xorg-x11-devel

Ubuntu вариантов - Sudo APT-получить установку

  • libjpeg62-DEV
  • libpng12-DEV
  • libx11-DEV
  • libxcursor-DEV
  • libxext-DEV
  • libxft-DEV
  • libxinerama-dev
  • libxi-dev
  • zlib1g-dev

В зависимости от того, на что были вызваны пакеты, он варьируется от системы к системе. Я не знаю, что они называются redhat, debian или slackware.