How To Compile APUE Code On CentOS 6.X
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
You need the ‘libbsd’ package, available in EPEL.
(http://fedoraproject.org/wiki/EPEL)
The ‘heapsort()’ function is implemented there.
So all the packages of Fedora can also be used in CentOS?
于2014年7月29日 23:58:48,Jonathan Billings写到:
CentOS mailing list CentOS@CentOS.org http://lists.CentOS.org/mailman/listinfo/CentOS
I tried to install libbsd before, it didn’t work.(I can execute man heapsort)
Today, I installed epel-release-6-8.noarch.rpm and then yum install libbsd,(No result for man heapsort) but it still doesn’t work.
于2014年7月29日 23:58:48,Jonathan Billings写到:
CentOS mailing list CentOS@CentOS.org http://lists.CentOS.org/mailman/listinfo/CentOS
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 ??:
2014-07-30 6:01 GMT+03:00 Theodore Si:
install libbsd development package also?
I build the libbsd from source code that I downloaded from here:
http://libbsd.freedesktop.org/wiki/
I think I got all things needed, right?
于2014年7月30日 10:35:39,Theodore Si写到:
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
I build it myself, not using rpm since it doesn’t work. My OS is 32bit. CentOS mailing list CentOS@CentOS.org http://lists.CentOS.org/mailman/listinfo/CentOS
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写到: