You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Gaurav Gupta <ga...@oracle.com> on 2004/09/30 13:23:02 UTC

How to use the sockets library of apr?

Hi,

Am getting this error when creating executable for my code for a socket
server programme. Kindly help.

ERRRORS:
/tmp/cc8HZXkf.o(.text+0x1b): In function `main':
: undefined reference to `apr_pool_create_ex'
/tmp/cc8HZXkf.o(.text+0x48): In function `main':
: undefined reference to `apr_sockaddr_info_get'
/tmp/cc8HZXkf.o(.text+0x74): In function `main':
: undefined reference to `apr_socket_create'
/tmp/cc8HZXkf.o(.text+0x95): In function `main':
: undefined reference to `apr_socket_bind'
/tmp/cc8HZXkf.o(.text+0xb5): In function `main':
: undefined reference to `apr_socket_listen'
collect2: ld returned 1 exit status

LIBRARIES INCLUDED:
-L/home/gauragup/apache/lib/libapr-1.a -L/home/gauragup/apache/lib/libapr-1.
1a

CODE:

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/unistd.h>
#include <sys/stat.h>
#include <sys/fcntl.h>
#include "apr_pools.h"
#include "apr_thread_proc.h"
#include "apr_network_io.h"
#include "apr_errno.h"
#include "apr_general.h"
#include "apr_lib.h"
#include "apr_strings.h"

main() {
    apr_status_t rv;
    apr_sockaddr_t *sa;
    apr_socket_t *sock;

    apr_pool_t *p;
    apr_pool_create(&p, NULL);
    printf("Pool created /n");

    apr_sockaddr_info_get(&sa, NULL, APR_INET, 8021, 0, p);
    printf("Got the addres /n");

    apr_socket_create(&sock, sa->family, SOCK_STREAM, APR_PROTO_TCP, p);
    printf("Socket created /n");

    apr_socket_bind(sock, sa);
    printf("Socket bound /n");

    rv = apr_socket_listen(sock, 5);
}





Re: How to use the sockets library of apr?

Posted by Jeff Trawick <tr...@gmail.com>.
On Thu, 30 Sep 2004 16:53:02 +0530, Gaurav Gupta
<ga...@oracle.com> wrote:
> Hi,
> 
> Am getting this error when creating executable for my code for a socket
> server programme. Kindly help.

I don't think this is the right way to do it, but it does seem to
work.  If somebody with the appropriate clue stick can help me out,
I'll try to write some doc to put at apr.apache.org for how to build
an apr application on Unix-like systems.  I looked but did not find
anything.

$ cat bldfoo
APRCFG=/home/trawick/inst/apr/bin/apr-1-config

CC=`$APRCFG --cc`
CFLAGS=`$APRCFG --cflags`
CPPFLAGS=`$APRCFG --cppflags`
INCLUDES=`$APRCFG --includes`
LIBAPR=`$APRCFG --link-libtool --libs`
LIBTOOL=`$APRCFG --apr-libtool`

cmd="$CC -g -c $CFLAGS $CPPFLAGS $INCLUDES foo.c"
echo $cmd
$cmd

cmd="$LIBTOOL --mode=link  $CC -o foo -g foo.o $LIBAPR"
echo $cmd
$cmd