How To Compile APUE Code On CentOS 6.X

Home » CentOS » How To Compile APUE Code On CentOS 6.X
CentOS 11 Comments

Hi all,

I want to compile the source code of Advanced Programming in the Unix Environment(APUE) 3rd edition, and I encountered some difficulties. After executing “make”, I got this message:

gcc -ansi -I../include -Wall -DLINUX -D_GNU_SOURCE barrier.c -o barrier
-L../lib -lapue -pthread -lrt -lbsd
/tmp/cc0gG99O.o: In function `thr_fn’:
barrier.c:(.text+0x6e): undefined reference to `heapsort’
collect2: ld returned 1 exit status make[1]: *** [barrier] Error 1
make[1]: Leaving directory `/home/drizzlex/apue.3e/threads’
make: *** [all] Error 1

In barrier.c, I found this

#ifdef SOLARIS
#define heapsort qsort
#else extern int heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
#endif

If I change these code to

How to install libbsd to solve this problem on CentOS (this works on Ubuntu)?

11 thoughts on - How To Compile APUE Code On CentOS 6.X

  • I’ve installed libbsd(I think I have successed because when I execute man heapsort I see this)

    and I make a link /lib/libbsd.so

    since in the file Make.defines.linux the LDDIR is as follows:

    then I add this to threads/barrier.c

    howerver, I still get this:

    ? 2014/7/29 23:58, Jonathan Billings ??:

  • I write a .c file and #include and call heapsort, I get this:

    Apparently, heapsort can be called.

    于2014年7月30日 11:46:55,Theodore Si写到:

  • You shouldn’t need the bsd/stdlib.h if the barrier.c used the function definition you described in your original message. I was able to find and build the file on CentOS 6 with the EPEL libbsd package installed.

    Are you sure you installed the right package? 32-bit vs. 64-bit?


    Jonathan Billings

  • It works for me with libbsd and libbsd-devel installed:

    $ cd /tmp
    $ wget http://www.apuebook.com/src.3e.tar.gz
    $ tar zxvf src.3e.tar.gz
    $ cd apue.3e
    $ make
    [multiple lines building]
    $ cd threads
    $ make gcc -ansi -I../include -Wall -DLINUX -D_GNU_SOURCE barrier.c -o barrier -L../lib -lapue -pthread -lrt -lbsd
    /tmp/ccmCvcBh.o: In function `thr_fn’:
    barrier.c:(.text+0x80): undefined reference to `heapsort’
    collect2: ld returned 1 exit status make: *** [barrier] Error 1
    $ sudo yum -y -q install libbsd libbsd-devel
    $ make gcc -ansi -I../include -Wall -DLINUX -D_GNU_SOURCE barrier.c -o barrier -L../lib -lapue -pthread -lrt -lbsd
    $

    I’ll admit that my OS is 64-bit, but I don’t see anything in the code that would break with 32-bit.

  • It’s so weird… It works now, either with #include or not.

    于2014年7月31日 8:40:05,Jonathan Billings写到: