The linker consistently giving undefined references

Stop Undefined References

There are many reasons why you might receive undefined references. The typical reason is that you have not specified an appropriate library or your command line order is incorrect. In order for a library to resolve references the dependency for the library must precede the library in the command line order.
E.G.

 gcc -o foo -L/path/to/mylib bar.o -lbaz

In the example you are building program foo that uses object file bar.o that has depencies to references in libbaz.a that is stored in the /path/to/mylib directory. If you have say three libraries with circular dependencies you must specify the libraries mutltiple times until there are no more undefined references.
E.G.

 gcc -o foo -L/path/to/libraries bar.o -lbaz -lfiz -ljaz -lbaz

In the example baz has dependencies on fiz and jaz, fiz has depencies on jaz and baz and jaz may have dependencies on baz.

Wchar_t

There is no wide character support in the latest stable version of mingw, so forcefully defining _GLIBCXX_USE_WCHAR_T (for example, in c++config.h) will cause linker errors (the program usually compiles fine).

Re: Wchar_t

keith's picture

This isn't strictly true. As a C data type, wchar_t is effectively a representation of a UTF-16LE entity, and the standard C functions for manipulating such entities generally work as expected. However, (and I guess this is what you really mean), much of the G++ class support for this data type is missing, so forcibly trying to use it is almost certain to fail.

This is unlikely to change, for the current gcc-3.x-mingw32 series compiler suite.

For some prior discussion, see:

http://thread.gmane.org/gmane.comp.gnu.mingw.user/10818

http://thread.gmane.org/gmane.comp.gnu.mingw.user/12917

(also referenced from the original MinGWiki FAQ article, now reproduced here).

Site Status

Site maintenance completed May 25th, 2012 at 12:38 UTC