unable to build against apr -- undefined reference to `apr_initialize'

Bug #873042 reported by Steve Halasz
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
apache2 (Ubuntu)
Invalid
Medium
Unassigned

Bug Description

I'm trying to compile the following program in oneiric:

#include <apr.h>
#include <apr_general.h>
#include <apr_pools.h>
#include <apr_file_info.h>
#include <apr_file_io.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
    apr_pool_t *pool;
    apr_file_t *out;

    apr_initialize();
    //atexit(apr_terminate());

    apr_pool_create(&pool, NULL);
    apr_file_open_stdout(&out, pool);
    apr_file_printf(out, "Hello World\n");
    apr_pool_destroy(pool);

    return EXIT_SUCCESS;
}

$ gcc -Wall $(apr-1-config --cflags --cppflags --includes --link-ld) test2.c -o test
/tmp/ccmjrPSw.o: In function `main':
test2.c:(.text+0x10): undefined reference to `apr_initialize'
test2.c:(.text+0x2b): undefined reference to `apr_pool_create_ex'
test2.c:(.text+0x3e): undefined reference to `apr_file_open_stdout'
test2.c:(.text+0x54): undefined reference to `apr_file_printf'
test2.c:(.text+0x60): undefined reference to `apr_pool_destroy'
collect2: ld returned 1 exit status

This works fine in maverick.

$ apr-1-config --cflags --cppflags --includes --link-ld
  -pthread -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -I/usr/include/apr-1.0 -L/usr/lib -lapr-1

$ lsb_release -rd
Description: Ubuntu 11.10
Release: 11.10

$ apt-cache policy apache2-prefork-dev
apache2-prefork-dev:
  Installed: 2.2.20-1ubuntu1
  Candidate: 2.2.20-1ubuntu1
  Version table:
 *** 2.2.20-1ubuntu1 0
        500 http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ oneiric/main amd64 Packages
        100 /var/lib/dpkg/status

Revision history for this message
Steve Halasz (skh2) wrote :

This works fine in natty I meant to say.

Changed in apache2 (Ubuntu):
importance: Undecided → Medium
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in apache2 (Ubuntu):
status: New → Confirmed
Revision history for this message
tititou (christophe-jaillet) wrote :

Hi,

I was having the same kind of problem with Ubuntu 12.04 LTS.

After 3 evenings searching for a solution, I reached the online help of gcc about link option (http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html)

There you can read:
>>>>>>>
-l library
It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, `foo.o -lz bar.o' searches library `z' after file foo.o but before bar.o. If bar.o refers to functions in `z', those functions may not be loaded.
>>>>>>>

So, try to do:
     gcc -Wall test2.c $(apr-1-config --cflags --cppflags --includes --link-ld) -o test
That is to say, your C file before the APR stuff.
Doing so, -lapr-1 will be at the end of the command line and the linker will find the reference, as per gcc's comment above.

It worked for me.
Hope this can help.

Revision history for this message
Steve Halasz (skh2) wrote :

Hi Christophe,

That worked great. Thank you!!

Changed in apache2 (Ubuntu):
status: Confirmed → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.