0

When i linked the .o files,some problems happened:

gcc -L/usr/local/apr/lib -lapr-1 -pthread -laprutil-1  devpkg.o bstrlib.o db.o shell.o commands.o   -o devpkg
devpkg.o: In function `main':
/root/workspace/devpkg/devpkg.c:21: undefined reference to `apr_pool_initialize'
/root/workspace/devpkg/devpkg.c:22: undefined reference to `apr_pool_create_ex'
/root/workspace/devpkg/devpkg.c:36: undefined reference to `apr_getopt_init'
/root/workspace/devpkg/devpkg.c:38: undefined reference to `apr_getopt'

I used "objdump -T" to check the lib,it returned:

objdump -T libapr-1.so|grep apr_pool_initialize
000000000001db00 g    DF .text  00000000000000fb  Base        apr_pool_initialize

Why did this happen?

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
kino-chen
  • 40
  • 5
  • What if you put the `-l` rules at the end of the command instead? – John Zwinck Aug 28 '14 at 07:33
  • `undefined reference` indicates a compilation error, not a linkage error. You should probably `#include` the lib's header file (at the top of file devpkg.c). – barak manos Aug 28 '14 at 07:34
  • @barakmanos: No, unless I'm terribly confused "undefined reference" is definitely a linker error. (But it's probably best for me to be explicitly fallibilist before the day's first cup of coffee.) – Thomas Padron-McCarthy Aug 28 '14 at 07:46
  • @ThomasPadron-McCarthy: I dunno, linkage errors are typically recognizable by their "hard-to-read" nature, but perhaps that's how it is just on some IDEs... – barak manos Aug 28 '14 at 08:30

1 Answers1

2

This is most likely just a simple dependency issue. You might want to try listing all the libraries you link to after the .o files, in the right order based on their dependencies with one another.

downhillFromHere
  • 1,967
  • 11
  • 11