linux - Compiling SDL program written in C. -


i've got problem compiling sdl program. i've installed sdl dev package according post: https://askubuntu.com/questions/344512/what-is-the-general-procedure-to-install-development-libraries-in-ubuntu (method 1). seems completed without errors. when i'm trying compile such instruction: gcc -i/usr/include/sdl/ showimage.c -o out -l/usr/lib -lsdl

it returns error:

showimage.c:7:23: fatal error: sdl_image.h: no such file or directory compilation terminated. 

even if put sdl_image.h folder i'm compiling returns error:

/tmp/ccfiso10.o: in function `load_image': showimage.c:(.text+0xd): undefined reference `img_load' collect2: ld returned 1 exit status 

here code recive teacher:

#include <stdlib.h> #include <stdio.h> #include <string.h>  #include "sdl.h" #include "sdl_image.h"  sdl_surface* load_image(char *file_name) {         /* open image file */         sdl_surface* tmp = img_load(file_name);         if ( tmp == null ) {             fprintf(stderr, "couldn't load %s: %s\n",                     file_name, sdl_geterror());                 exit(0);         }         return tmp; (....) 

i know code ok, because friend compiled , works fine.

can me compile this?

the first error you're seeing because include path wrong. set include path using -i flag gcc. since include path incorrect, sdl header mention can not found.

to fix this, set -i directory contains header want use.

the second error comes linker, can't find img_load symbol. symbol contained in sdl libraries, , these libraries need supplied linker in order find symbols.

to fix this, need set -l directory containing library files of sdl, , need use -l supply name of library link against.

there's tool called pkg-config give correct -i -l , -l lines, given library name. try running pkg-config --cflags --libs sdl sdl_image.

--cflags give include parameters, , --libs give library directories , names.

you can include command in gcc invocation this:

gcc `pkg-config --cflags --libs sdl sdl_image` showimage.c -o out 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -