gcc - IUP in C - tutorial fails to compile -
i'm using iup on manjaro gnu/linux, , i'm trying compile first sample program this site. however, compiler says cannot locate iup.h. installed iup using yaourt, installing package named iup-all-bin.
what should change #include directive iup.h to?
edit: 1 of comments, able find header , library files (i think!), now, error gcc instead:
$gcc hello0.c -i/usr/include/iup-3.7/ -l/usr/lib -o hello0 /tmp/ccmabpwz.o: in function `main': hello0.c:(.text+0x1e): undefined reference `iupopen' hello0.c:(.text+0x28): undefined reference `iuplabel' hello0.c:(.text+0x30): undefined reference `iupdialog' hello0.c:(.text+0x38): undefined reference `iupshow' hello0.c:(.text+0x3d): undefined reference `iupmainloop' hello0.c:(.text+0x42): undefined reference `iupclose' collect2: error: ld returned 1 exit status i know libiup.so (along non-lua libraries) in /usr/lib, , header file in /usr/include/iup-3.7
as may or may not know, there 2 steps necessary source code executable: compiling , linking. (each of steps have steps, irrelevant discussion.)
when include file #include:
#include <iup.h> #include <stdlib.h> /* ... */ iup.h , stdlib.h not appear out of thin air. real file names, , compiler needs know find them can dutifully include , process them. stdlib.h in directory (usually /usr/include) compiler in default, when install nonstandard libraries, might need tell compiler else can include files can’t find elsewhere. that’s -i flag comes in. if iup.h exists in /usr/include/iup-3.7, can tack on -i/usr/include/iup-3.7 , compiler there after can’t find iup.h in /usr/include. hat trick, might find interesting since /usr/include/iup-3.7 subdirectory of /usr/include, can change #include directive if wanted to:
#include <iup-3.7/iup.h> but can brittle if it’s not in iup-3.7 subdirectory.
now compiler has finished compiling c file object file, contains of logic in machine code, unresolved references functions iupopen, can’t run quite yet. in order able run it, have link object files of program together, hoping functions defined in other files satisfy references file.
by default, gcc link in c standard library, giving access functions printf , exit. when referencing functions external library, have tell want link program , resolve references. can using -l.
lastly, should note -l, too, uses search path. -i, adds include path, -l adds library search path. if have libraries located somewhere nonstandard, you’ll have include -l flag tell linker find library in addition -l flag tell linker want reference particular library.
Comments
Post a Comment