D
D
demsee2018-09-06 22:43:31
C++ / C#
demsee, 2018-09-06 22:43:31

C header file connection error (in what)?

I'm trying to run the copy.c file (example 4-1) from the
Linux Programming Interface book .
In the main file copy.c, the file "tlpi_hdr.h" [written by the author] is included;
#include "tlpi_hdr.h"
the file "error_functions.h" [written by the author] is
#include "error_functions.h"
included. There are no functions in the file "tlpi_hdr.h" - only macro definitions, but in the self-written file error_functions. c there are functions that are used in the main file and when compiling the copy.c file, errors occur related to the use of functions from the file "error_functions.h"


In function `main':
copy.c:(.text+0x67): undefined reference to `usageErr'
copy.c:(.text+0xb6): undefined reference to `errExit'
copy.c:(.text+0x122) : undefined reference to `errExit'

Question: how to include the header file "error_functions.h" in the main file copy.c
After all, header files should only use functions from the standard library, and the file error_functions.c is not included in the standard library.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2018-09-06
@demsee

when compiling file copy.c throws errors
In function `main':
copy.c:(.text+0x67): undefined reference to `usageErr'
copy.c:(.text+0xb6): undefined reference to `errExit'
copy. c:(.text+0x122): undefined reference to `errExit'
These are linking errors, not compilation errors. The file copy.c compiled fine.
To link you need to link with error_functions.o:
gcc copy.c error_functions.c -o copy

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question