Diagnosing link-time problems

You can use AIX® commands and linker options to address unresolved and duplicate symbols that you might encounter.

Unresolved symbols

When an external symbol cannot be resolved, a linker error is issued. The example messages are as follows:
ld: 0711-317 ERROR: Undefined symbol: .function_name
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
The most common reason of unresolved symbol errors is missing input files. You can take one of the following actions to locate the symbols and include the target input files in which the symbols are defined during linking:
  • Include all the supplied libraries during linking so that the linker can find where the symbols are.
  • Use the nm command to list symbols in libraries or object files so that you can find out the target input files.
  • Use the dump -Tv command to examine the deferred imported symbols, which have [noIMid] value for the IMPid field in the output. You must resolve those deferred symbols to avoid unresolved symbols.
  • Use one of the following linker options to generate linker log files and analyze the log files to determine the libraries or object files that reference unresolved symbols. These options examine interdependent or redundant libraries that are used in error.
    • The -bnoquiet option writes each binder subcommand and its results to standard output. It lists unresolved symbol references and the symbols that are imported from the specified library modules.
    • The -bmap:filename option generates an address map. Unresolved symbols are listed at the top of the map, followed by imported symbols.
    • The -bloadmap:filename option generates a linker log file. The linker log file includes information about all of the arguments passed to the linker, the names of the shared objects, and the number of imported symbols. If any unresolved symbol is found, the linker log file lists the object file or shared object that references the symbol.

Duplicate symbols

When two or more functions in the linked object files have the same name, a warning message is issued. The example messages are as follows:
ld: 0711-224 WARNING: Duplicate symbol: .function_name
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.

By default, the linker uses the first definition that it encounters, which might not produce expected results. To fix this problem, you can rename the function or make the function static.

C++ only beginsThe use of template functions in C++ might generate duplicate symbols at link time when the template is implicitly instantiated in multiple source files. XL-based front end beginsYou can use the -qtemplateregistry option to fix this issue. When the -qtemplateregistry option is specified, identical instantiations of the same template in different compilation units are recorded but the redundant instantiations are not generated.C++ only endsXL-based front end ends

To find the symbols that are defined in multiple files, you can use the nm command.

Incompatible symbols

If a symbol with C++ linkage is defined in an object file that is generated by xlclang++ and referred to in an object file that is generated by xlC/xlc++, or vice verse, a linker error is issued. The example messages are as follows:
ld: 0711-317 ERROR: Undefined symbol: .symbol_name
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.

Mangled names by the Clang-based front end of IBM® XL C/C++ for AIX are as defined in the Itanium C++ ABI. Object files generated by xlC/xlc++ and xlclang++ are not interoperable.