0

What should I do with the files ename.c.inc, error_functions.c, error_functions.h, tlpi_hdr.h?

I copied these files into /lib/ Directory. but I got the following Error when I tried to compile example listing 4.1, a simple copy function:

4.1_copy.c:(.text+0x7e): undefined reference to `usageErr'
4.1_copy.c:(.text+0xcd): undefined reference to `errExit'
4.1_copy.c:(.text+0x139): undefined reference to `errExit'
4.1_copy.c:(.text+0x16f): undefined reference to `fatal'
4.1_copy.c:(.text+0x1b6): undefined reference to `errExit'
4.1_copy.c:(.text+0x1d7): undefined reference to `errExit'
4.1_copy.c:(.text+0x1f8): undefined reference to `errExit'
collect2: ld returned 1 exit status

What do I need to do to get this program to link?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
user3049078
  • 21
  • 1
  • 1
  • Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. – Jordan Oct 26 '14 at 06:19

1 Answers1

4

When you are compiling, try adding a path to the files that need to be included in copy.c, like this:

gcc -I ../lib -o copy copy.c

That -I argument, followed by the path, tells the compiler to search in that path for included files, hopefully including tlpi_hdr.h.

Alternatively, follow the instructions at the very bottom of this page and run make from the directory where copy.c ends up.

Tony
  • 1,645
  • 1
  • 10
  • 13
  • Adding the include path doesn't help with undefined references at all. [Undefined references only occur at a much later stage of compilation](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix). To fix those, add the relevant `libtlpi.a` file to the gcc command line. – Daniel H Dec 29 '17 at 04:37
  • This is what worked for me. I ran make on the book source code directory (after installing necessary dev packages libcap-dev and libacl1-dev). After successful compilation it generated a library file called libtlpi.a . I used that file as one of the files while compiling code. E.g.; $ gcc -o copy copy.c ../libtlpi.a – razor Oct 11 '21 at 00:02