delorie.com is funded by banner ads.
  www.delorie.com/djgpp/v2faq/faq057.html   search  

| Previous | Next | Up | Top |

8.7 Unresolved externals when linking programs

Q: Why do I get so many unresolved symbols when linking my programs?

Q: Why does GCC complain that it cannot open -lstdcx?

Q: Why do I get "Undefined reference to yywrap" when linking programs produced by Flex?


A: By default, GCC instructs the linker to only look in two libraries: libgcc.a and libc.a. Some functions aren't included there, so the linker can't find them. If you need to link against some optional library, say libxy.a, put the library into the DJGPP lib/ subdirectory and append a -lxy to the link command line. The Standard C++ Template classes are in libstdcxx.a (it's called libstdc++.a on Unix); append -lstdcxx. To use the additional GNU C++ classes in the libgpp.a library (it's called libg++.a on Unix systems), append -lgpp. Flex-generated lexical analyzers call functions in the libfl.a library; you need to append -lfl when linking them.

When linking C++ programs, you can use either one of the gxx, gpp, or g++ commands (the latter on Windows 9X only) instead of gcc; they will then instruct the linker to also scan the C++ libraries automatically, so you don't have to remember doing that yourself.

Another reason for undefined references when linking C++ programs is that you mix GCC and libstdcxx.a from different releases: they are usually incompatible.

An error message about missing -lstdcx usually means that the linker cannot find the standard C++ library, libstdcxx.a. Look into your lib/ subdirectory to see if it's there; if not, unzip it from the gppNNNb.zip file. If libstdcxx.a exists but the linker still complains, you most probably have a problem related to long file names on Windows 9X (libstdcxx.a exceeds the DOS 8+3 limits). For a quick fix, try to set LFN=y in the environment and see if that helps. If that doesn't help, make sure you unpacked gppNNNb.zip with an unzip program which supports long file names. This issue is further complicated if you use RHIDE, and is described in full in the file gnu/gcc-2.81/problems.txt which comes with the GCC distribution (and which you should have read before installing it). Bottom line is that you need to add a line either to rhide.env or to DJGPP.ENV which says this:

      RHIDE_TYPED_LIBS_DJGPP.cc=stdcxx

When you add this line, make sure neither it nor the [rhide] line have trailing whitespace, otherwise RHIDE will not recognize these lines.

If your program uses a lot of floating-point math, or needs math functions beyond those specified in the ANSI/ISO standard, consider appending -lm to your link command line. The basic math functions required by ANSI/ISO standard are included in the libc.a library, but libm.a includes higher quality versions of these functions, and also some functions not included in the default library, like Gamma function and Bessel functions, support for Posix-compliant behavior in case of errors (e.g., it math functions from libm.a always set errno), a matherr facility, etc.


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright ⌐ 1998   by Eli Zaretskii     Updated Sep 1998  

Powered by Apache!

You can help support this site by visiting the advertisers that sponsor it! (only once each, though)