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.

 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.

 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.


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:

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

This wiki is not a forum for discussion of usage issues. Please use the list instead. We do not allow creation of comments by anonymous or untrusted users, on any page.
Site Status

Site maintenance performed successfully, site online Dec 13th 12:00 AM Eastern.