I wrote the simplest apr program: apr_skeleton.c, but encountered the following problems during compilation:
$ Gcc 'apr-config -- cflags -- libs' apr-skeleton.c-o apr-skeleton
In file encoded ded from/usr/include/apr-1.0/apr_general.h: 28,
From apr-skeleton.c: 12:
/Usr/include/apr-1.0/apr. h: 270: error: expected '=', ';', 'asm 'or' _ attribute _ 'before' apr _ off_t 'apr _ off_t
It was not a problem with apr_skeleton.c, so I followed the prompt to open row 270th of apr. h:
Typedef off64_t apr_off_t;
It is estimated that off64_t is not defined, so grep has a/usr/include, and the related definition is found in unistd. h:
# If defined _ USE_LARGEFILE64 &&! Defined _ off64_t_defined
Typedef _ off64_t off64_t;
# Define _ off64_t_defined
# Endif
It seems that _ USE_LARGEFILE64 is not defined. Continue grep and find it in/usr/include/features. h:
# Ifdef _ LARGEFILE64_SOURCE
# Define _ USE_LARGEFILE64 1
# Endif
It seems that the cause is found. In the first line of apr_skeleton.c, define _ LARGEFILE64_SOURCE, and compile... successfully. The link... failed !?
Tip:
/Tmp/ccd1_w18.o: In the 'main' function:
/Home/ht/docs/apr-tutorial/sample/apr-skeleton.c: 22: Undefined reference to 'apr _ initialize'
/Home/ht/docs/apr-tutorial/sample/apr-skeleton.c: 30: Undefined reference to 'apr _ terminate'
Collect2: ld returned 1 exit status
It is estimated that the database is not included in apr-config. Check the result as follows:
$ Apr-config -- cflags -- libs
-Pipe-Wall-g-O2-pthread-luuid-lrt-lcrypt-lpthread-ldl
In/usr/lib/find the libapr-1.a, you know plus-lapr-1 can be done, so:
$ Gcc-lapr-1 'apr-config -- cflags -- libs' apr-skeleton.c-o apr-skeleton
Compiled successfully!
PS:
1) apr_skeleton.c from the http://dev.ariel-networks.com/apr/, this is a suitable for beginners to all the tutorials.
2) compiling environment: $ cat/proc/version
Linux version 2.6.18-5-686 (Debian 2.6.18.dfsg.1-17) (dannf@debian.org) (gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21) #1 SMP Mon Dec 24 16:41:07 UTC 2007
The above is the old version of the solution, new.
New GCC compilation options for/usr/local/apr/bin/apr-1-config -- cflags -- libs -- link-ld generation
-G-O2-pthread-luuid-lrt-lcrypt-lpthread-ldl-L/usr/local/apr/lib-lapr-1
Then gcc-g-O2-pthread-luuid-lrt-lcrypt-lpthread-ldl-L/usr/local/apr/lib-lapr-1-o apr-skeleton
Note:
This # define _ LARGEFILE64_SOURCE must be added to the first line of source code of all instances to solve the apr. h error.
Someone may ask what the apr-1-config is, download apr: http://apr.apache.org/and then install it.