kermitt2 / pdfalto

PDF to XML ALTO file converter
GNU General Public License v2.0
216 stars 70 forks source link

Can't compile pdfalto: error: ‘for’ loop initial declarations are only allowed in C99 mode #134

Closed jbollmeyer closed 2 years ago

jbollmeyer commented 2 years ago

I am using redhat EL 7 After in installed cmake3 manually i do make and get the following:

[ 61%] Building C object CMakeFiles/pdfalto.dir/src/whereami.c.o
/home/hamersjbo/pdfalto/src/whereami.c: In function ‘wai_getModulePath’:
/home/hamersjbo/pdfalto/src/whereami.c:249:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
   for (int r = 0; r < WAI_PROC_SELF_MAPS_RETRY; ++r)
   ^
/home/hamersjbo/pdfalto/src/whereami.c:249:3: note: use option -std=c99 or -std=gnu99 to compile your code
make[2]: *** [CMakeFiles/pdfalto.dir/src/whereami.c.o] Error 1
make[1]: *** [CMakeFiles/pdfalto.dir/all] Error 2
make: *** [all] Error 2

I googled (stackoverflowed?) and tried: make CFLAGS='-std=gnu99' and make CFLAGS='-std=c99' But it did not help.

i took the compile string with make -n and added the -std=c99 and got following:

[hamersjbo@erstapfrk003 pdfalto]$ /usr/bin/cc   -I/home/hamersjbo/pdfalto/libs/image/zlib/src -I/home/hamersjbo/pdfalto/libs/libxml/include -I/home/hamersjbo/pdfalto/libs/freetype/include -I/home/hamersjbo/pdfalto/libs/image/png/src -I/home/hamersjbo/pdfalto/xpdf-4.03 -I/home/hamersjbo/pdfalto/xpdf-4.03/goo -I/home/hamersjbo/pdfalto/xpdf-4.03/fofi -I/home/hamersjbo/pdfalto/xpdf-4.03/xpdf -I/home/hamersjbo/pdfalto/xpdf-4.03/build -I/home/hamersjbo/pdfalto/libs/icu/common   -o CMakeFiles/pdfalto.dir/src/whereami.c.o   -c /home/hamersjbo/pdfalto/src/whereami.c
/home/hamersjbo/pdfalto/src/whereami.c: In function ‘wai_getModulePath’:
/home/hamersjbo/pdfalto/src/whereami.c:249:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
   for (int r = 0; r < WAI_PROC_SELF_MAPS_RETRY; ++r)
   ^
/home/hamersjbo/pdfalto/src/whereami.c:249:3: note: use option -std=c99 or -std=gnu99 to compile your code
[hamersjbo@erstapfrk003 pdfalto]$ /usr/bin/cc   -I/home/hamersjbo/pdfalto/libs/image/zlib/src -I/home/hamersjbo/pdfalto/libs/libxml/include -I/home/hamersjbo/pdfalto/libs/freetype/include -I/home/hamersjbo/pdfalto/libs/image/png/src -I/home/hamersjbo/pdfalto/xpdf-4.03 -I/home/hamersjbo/pdfalto/xpdf-4.03/goo -I/home/hamersjbo/pdfalto/xpdf-4.03/fofi -I/home/hamersjbo/pdfalto/xpdf-4.03/xpdf -I/home/hamersjbo/pdfalto/xpdf-4.03/build -I/home/hamersjbo/pdfalto/libs/icu/common -std=c99  -o CMakeFiles/pdfalto.dir/src/whereami.c.o   -c /home/hamersjbo/pdfalto/src/whereami.c
/home/hamersjbo/pdfalto/src/whereami.c: In function ‘wai_getExecutablePath’:
/home/hamersjbo/pdfalto/src/whereami.c:195:5: warning: implicit declaration of function ‘realpath’ [-Wimplicit-function-declaration]
     resolved = realpath(WAI_PROC_SELF_EXE, buffer);
     ^
/home/hamersjbo/pdfalto/src/whereami.c:195:14: warning: assignment makes pointer from integer without a cast [enabled by default]
     resolved = realpath(WAI_PROC_SELF_EXE, buffer);
              ^
/home/hamersjbo/pdfalto/src/whereami.c: In function ‘wai_getModulePath’:
/home/hamersjbo/pdfalto/src/whereami.c:275:20: warning: assignment makes pointer from integer without a cast [enabled by default]
           resolved = realpath(path, buffer);
                    ^

Sorry for the noob dev questions.

kermitt2 commented 2 years ago

Your gcc version is likely too old, which version are you using? At least gcc 4.9 is required (gcc 4.9 is actually quite old too now).

In the CMakeList.txt, c11 is activated which replaces the older c99:

set(CMAKE_CXX_STANDARD 11)

so normally the setting is already beyond c99.

You could try the following in CMakeList.txt:

set_property(TARGET pdfalto PROPERTY C_STANDARD 99)

but I guess it will very likely fail elsewhere.

jbollmeyer commented 2 years ago

tried devtolls4, but failed also. changed to a deian System (sid)

got following wile make: /usr/bin/ld: libs/icu/linux/64/libicuuc.a(uvector.ao): relocation R_X86_64_32 against .bss._ZZN6icu_627UVector16getStaticClassIDEvE7classID' can not be used when making a PIE object; recompile with -fPIE /usr/bin/ld: libs/icu/linux/64/libicuuc.a(edits.ao): relocation R_X86_64_32 against.rodata.str2.2' can not be used when making a PIE object; recompile with -fPIE /usr/bin/ld: libs/icu/linux/64/libicuuc.a(patternprops.ao): relocation R_X86_64_32S against .rodata._ZN6icu_62L6latin1E' can not be used when making a PIE object; recompile with -fPIE /usr/bin/ld: libs/icu/linux/64/libicuuc.a(utrie.ao): relocation R_X86_64_32 against.text._ZL21defaultGetFoldedValueP8UNewTrieii' can not be used when making a PIE object; recompile with -fPIE /usr/bin/ld: libs/icu/linux/64/libicuuc.a(bmpset.ao): relocation R_X86_64_32S against symbol _ZTVN6icu_626BMPSetE' can not be used when making a PIE object; recompile with -fPIE /usr/bin/ld: libs/icu/linux/64/libicuuc.a(unisetspan.ao): relocation R_X86_64_32S against.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE

kermitt2 commented 2 years ago

For this one, simply add to CMakeList.txt:

set(CMAKE_EXE_LINKER_FLAGS "-no-pie")
jbollmeyer commented 2 years ago

This helps, Thank you.