1 AUTHOR: Alex Kloss <alex@22-music.com>
5 LICENSE: GNU Free Documentation License Version 1.2
7 SYNOPSIS: What to do on errors
10 The LFS Book has a short, but nice chapter about errors. A longer essay about
11 how to spot where the error is, how to describe it (on IRC or the mailing
12 list), and possibly get around it is the goal of this hint.
15 Common sense, LFS, patience. Programming skills (optional).
18 Almost every LFS adept has seen lines like:
22 - ld returned signal 2: ...
24 The first urge is to write to the mailing list or on IRC something like:
26 I have an error in program <fill in whatever is appropriate>!
28 First of all, is it really an error? If you find the option "-Werror" in the
29 lines that call gcc, the "error" you're facing could as well be a warning
30 (-Werror makes gcc handle all warnings as errors). You will often find warning
31 and error messages mixed before the classical "make[1]: Error". A warning is
32 something gcc complains about, but continues without error, while an error is
33 something that stops you from compiling the package you are about to build.
34 To disable distracting warning messages, use "export CFLAGS="-w".
36 Mostly, further information about the errors are missing, which is a nuisance
37 for both the one who asks and the one who tries to answer, because of the
38 annoying dialogue that is often following. I have to admit that the LFS mailing
39 list and IRC never failed to solve my problems (and that in a rather cheerful
40 way), but I reached a point at where I wanted to solve as many of my problems
41 as possible. So I had to learn a lot, which was undoubtedly fun.
45 You have to distinguish between the different kinds of errors. The more you
46 can tell about the error, the easier it is to solve.
48 This should be a normal hint, but I guess it is easier to draw a chart:
50 Question: When did it happen? What happened? Where did it happen?
53 , ... not found ---<- Dependencies (depmod)
54 Compile-time Error < -, ` Linking (ld)
59 Run-time Error ----< , full
64 * gcc-3.4 and later don't accept labels at the end of compound statements
65 nor the usage of protected functions from within other files.
67 That looks pretty simple, eh? But that is only the beginning. We will have a
68 look at each of these error types closely!
70 1. Compile-time Errors
72 First of all, check the package you are about to compile for files like README
73 and/or INSTALL. You can work around most errors by strictly following those
76 When you are about to build your package, you sometimes get the error that
77 something is missing or malformed or simply uncompileable.
83 There is a lot gcc may be unable to find. If there is something to include, it
84 may be the file that should be included, that is missing. The questions here
85 are: 1. what is missing? and 2. what to do against?
87 1.1.1.1 Missing header file
89 If only a header file is missing, you will experience an error message like:
91 foo.c:3:31: /usr/include/bar.h: No such file or directory
93 If there's a file missing, you may want to search your system for it:
95 find / -name <filename> or
96 locate <filename> (run updatedb, if locate demands it)
98 If you don't find the file, the next question would be: where should this file
99 come from? Is there a prerequisite you forgot? Are all tools available in the
102 If the file is anywhere else than in the common include path (/usr/include,
103 /usr/local/include), you may add -I<uncommon include path> to the CFLAGS,
104 e.g. "export CFLAGS=-I/usr/X11R6/include". If the #include statement
105 contains a subdirectory, while the file to be included is in the common
106 directory, you'll have to edit the #include statement.
108 In most cases the file will be in a directory the developer did not expect.
109 The easiest way around that would be a symlink, but that is not a clean way.
110 So we search the sources for occurrences of the "missing" file first:
112 grep -R "<missing file's path and name>" *.*
114 Now edit every file that uses the wrong path in it's #include statements. The
115 lazy user can utilize sed:
119 sed s|'<"missing" file>'|'<found file'>|g $i.bak > $i
122 This should solve the problem; you can continue building the package.
124 1.1.1.2 Missing declaration
126 Another fine error message goes about a missing declaration:
128 foo:124:4: bla undefined
130 if "bla" is a function from generic libraries (like glibc), it will probably be
131 documented with a manpage which holds information about which header file(s)
132 it needs to be included:
136 Look at /usr/share/man/man3 for documented function calls: The manpage will
137 look something like that:
140 FUNC(3) Linux Programmer's Manual FUNC(3)
143 func, ffunc, vfunc - Example function without any use
147 int func(char *format, ...);
148 int ffunc(FILE *stream, const char *format, ...);
150 #include <vstdfunc.h>
151 int vfunc(const char *format, va list ap);
157 In most of the cases the header file is not included where it's needed, so you
158 just write it into the file where it is missing: "#include <stdfunc.h>".
160 If the definition is not in any standard library, you will have to search the
161 codebase of the program you are about to compile for the function it's missing:
163 grep "<function name>" *.* | less
165 Now search for something like "#define bla ( const char * ...". If you don't
166 find anything, the function is likely to be included in other sources, so you
167 better check the requirements of the package you are about to compile, in case
168 something is missing.
170 If the file where the definition is included is a header file (*.h), simply
171 include it, otherwise copy and paste the definition into the file gcc is
174 Sometimes it's not the definition, but a missing argument to a function. The
175 last living example of this gizmo was an error due to some API change in the
176 alsa-1.0-pre driver when compiling any alsa-enabled package that used at least
177 one of the snd_pcm_hw_param-functions (e.g. mplayer or wine). The related error
180 audio.c: In function `Alsa_TraceParameters':
181 audio.c:292: error: too few arguments to function `snd_pcm_hw_params_get_format'
184 In this case you need to know what arguments the function is expecting.
185 Therefore, we seek the header file that defines the function (like explained
186 for missing functions). For our alsa example, the line in the header file was
187 in /usr/include/alsa/pcm.h and looked like:
189 int snd_pcm_hw_params_get_format(const snd_pcm_hw_params_t *params,
190 snd_pcm_format_t *val);
192 While the code from which that function was invoked only used:
194 (...) format = snd_pcm_hw_params_get_format(hw_params);
196 One must notice that only the first argument is given, the other argument
197 "snd_pcm_format_t" of the type "*val" is missing. Now we need to know what
198 type *val is, then we could insert it into audio.c.
200 1.1.1.3 function bla... redefined
202 Another almost similar error occurs if something is defined twice. The compiler
203 is unable to tell if both definitions are equal, so it will give the error even
204 in that case. You have to search for the definitions, check out which one is
205 valid for your case and embrace the "invalid" function with "#ifndef <Name>"
206 and "#endif". One could easily remove the "invalid" definition, but if another
207 package would need it, it would be missing then, so the #ifndef/#endif-way is
208 clearly the better one.
212 Linking mostly fails because of missing libraries. Make sure your
213 /etc/ld.so.conf contains all directories with libraries in it. In case, another
214 directory is needed, use LDFLAGS: "export LDFLAGS=-L/usr/X11R6/lib" to include
215 XFree86's libraries for sure. "/lib" and "/usr/lib" are always included by
216 default and need not to be in there.
218 Another (occasional) error can occur if libs are not linked right. I only
219 saw it happen once when some program linked to libpng, but forgot about libz,
220 which is used by libpng, but needs to be linked to, too. So in the Makefile,
221 where I found "LIBS=-lpng", I completed it to "LIBS=-lpng -lz". Mostly the
222 function that is missing is given; you can try to grep it in the library
225 1.1.3 Module Dependency checking (depmod)
227 Another error that only happens if the running kernel differs from the one the
228 sources are compiled against (which could be the case when compiling in chrooted
229 mode) is the "unresolved dependency in module"-error. To get around that bug,
230 run depmod with the "-F /usr/src/linux/System.map"-option. And be sure that you
231 are compiling the modules with the same compiler as you used when compiling the
236 The version 3.4.x introduces some new errors, which compiled fine using earlier
237 version of the same compiler. Instead of resorting to an older version, it
238 should be easier to fix them.
240 1.2.1 gcc-3.4.x: label at the end of compound statement
242 Since gcc-3.4.x, labels at the end of a compound statement are treated as
243 errors, though they are widely used in spite of their scruffyness. Certainly
244 this problem is easily solved: just replace the ocurrences of
252 and remove the label from the source or comment it out. As a rule, avoid goto
253 statements in your C code.
255 1.2.2 gcc-3.4.x: protected functions
259 Error: `foo::bar function(pointer*)' is protected
261 shows that somewhere in the code there is a function prefixed with
265 Though this has a meaning, it stops our application from compiling, so we can
266 easily comment this out:
270 and continue the compilation.
272 1.3 Segmentation Fault
274 This is most annoying. It means an application tries to get something from a
275 file/pipe/device/environment variable that is not set and has no fallback if
276 there is nil but rather dumps core and stop immediately. If the following in-
277 formation is not sufficing for you, you may want to have a look at the SIG11
278 FAQ which can be found at http://www.bitwizard.nl/sig11 - but look at this
281 1.3.1 Segfault during compilation
283 Segmentation faults during compilation are rarely seen. You only get SIG11 if
284 the memory is full while building a package and it will happen only on systems
285 with little memory. You can add a loop device to swap to expand your memory;
286 this will make compilation much slower, but at least it will work on such
287 devices that have insufficient memory:
289 dd if=/dev/zero of=/tmp/swapspace bs=1M count=128
290 losetup /dev/loop0 /tmp/swapspace
294 will set up 128MB of swap space (or virtual memory). If it still fails,
295 increase the amount of disk space used (count=256; count=512; count=XXX). If
296 you are done compiling or want to increase the size, remove the added swapspace
300 losetup -d /dev/loop0
303 1.3.2 Segfault during execution
305 If a program segfaults, there is not much you can easily do to hunt the error
306 down unless you have some programming skills. Contact the developer and give
307 him a detailed view of your system; maybe in /var/log is something about the
308 error? If you want to hunt the bug down yourself anyway, read the SIG11 FAQ and
309 use strace which you will find at http://www.liacs.nl/~wichert/strace/ and is
310 easily installed on the program; it may help you to find out what file/pipe/
311 environment string/etc the program is expecting to be available. Then try to
312 grep the sources of the program which is segfaulting after the file/pipe/etc
313 which failed. Add a fallback routine. A nice example is the gsview-4.4-patch.
314 gsview 4.4 tried to get the environment variable LANG, but had no fallback for
315 the case it was not set. The malignant part of the source looked like:
317 strncpy(lang, getenv("LANG"), sizeof(lang)-1);
319 Which would have copied a part of the LANG(uage) environment variable without
320 the last character - if LANG was empty, it would have tried to copy -1 char-
321 acters, which resulted in a segfault. The easy solution would have been to set
322 LANG to something, but the better solution is to provide a fallback and change
325 strncpy(lang, (getenv("LANG") == 0) ? "C" : getenv("LANG"),sizeof(lang)-1);
327 That is a bit obfuscated for the C-illiterate, but it means "if LANG is 0, then
328 use 'C' instead of the LANG environment variable (which stands for standard),
329 else use the LANG environment variable minus one char". Now it is your turn,
330 if you still want to get that bug by yourself!
334 Hangups are the most annoying errors there are. Fortunately, they are as seldom
335 as annoying with Linux (unless you use bleeding edge sources only). Hangups are
336 mostly caused by endless loops, driver problems that leads to bus lockups, and
337 hardware issues (like defective capacitors in the CPU power supply, check for
338 bursted ones). Infinite loops are easily spotted by the warnings of most
339 compilers, the latter is harder to find. Try to downgrade the driver you think
340 is responsible for the hangup and send a report to the relative mailing list.
344 You recognize a full hangup by pressing the [CAPS LOCK] key. If the led is
345 flashing, the keyboard is still hooked to the console, so that's no full
346 hangup. Try pressing different keys then. If nothing else works, use a hard
347 reboot (that is always the last means of getting back to work). If the
348 keyboard is still available, but the screen is blank, try to reboot with
349 [ALT][CTRL][DEL]. If even that doesn't work, you may be lucky enough to have
350 the sysrq key feature compiled into your kernel. For further information, read
351 [/usr/src/linux/Documentation/sysrq.txt].
353 1.4.2 Program-only Hangup
355 If the program hangs up leaving the rest system intact, you can use the
356 appropriate of the kill/killall/xkill command to get rid of it. Program-only
357 Hangups occurs on infinite loops, e.g. trying to read from a blocked pipe, in
358 most cases the load will go up visibly.
362 If you get an error message not covered by this hint, check the relevant
363 mailinglists, enter the error message into google and look 1. if there is a
364 newer version or 2. if a cvs version, if available, has the same error. If
365 nothing else helps, ask in IRC or mail to the developers mailinglist or submit
366 a bug report. Remember to describe the error precisely and give enough
367 information about the system you are trying to build the package on (logs,
368 versions, strace output, dmesg output, debug messages and so on).
370 1.6 Some Useful Links
372 About the SIG11 (Segfault) Error: http://www.bitwizard.nl/sig11
373 This page has some general information about the SIG11 error
375 Aquiring Programming Skills: http://ibiblio.org/obp/thinkCS
376 This page features a book called "How to think like a computer scientist",
377 which can be downloaded freely in the flavours Java, C++ and Python. The
378 C++ variant will be most helpful for the LFS adept, since most GNU projects
379 uses either C or C++.
382 May the source be with you!
386 * Started to write this hint.
389 * Initial Version, small additions.
392 * Almost forgot to give Tushar some credits, little changes and additions.
393 * Small changes and corrections suggested by Bill Maltby
396 * Adding a link to the SIG11 FAQ, some more stuff about segfaults and have
397 a few words about the depmod problem with different kernels.
400 * Adding a Links section with a link to a book that helps in aquiring C++
404 * Added a short section about redefined functions.
407 * Minor corrections, added gcc-3.4 inability to accept labels at the end of
408 a compound statement and it's solution.
411 * Another minor corrections plus gcc-3.4 stuff about protected functions.
414 Thanks to teemu for reminding me on "-I" and "-l" as much as Tushar for the
415 warning about warnings and ringing the bell of the "-w" option, not to
416 forget Bill for his corrections. Thanks to Gerard for inspiring me with his
417 LFS section about errors! Thanks to Allen B. Downey for his brilliant book
418 that's distributed freely under License GPL! :-)