Embedded Design Handbook

ID 683689
Date 8/28/2023
Public
Document Table of Contents

4.1.6.5.1. Linker Usage Example

To link your object files and archives into a .elf file, open a Nios® II command shell and call nios2-elf-g++ with appropriate arguments. The following example command line calls the linker:

nios2-elf-g++ -T'<linker script>' -msys-crt0='<crt0.o file>' \
-msys-lib=<system library> -L '<The path where your libraries reside>' \
-DALT_DEBUG -O0 -g -Wall -mhw-mul -mhw-mulx -mno-hw-div \
-o <your project>.elf <object files> -lm

The exact linker command line to link your executable may differ. When you build a project in the Nios® II SBT, you can see the command line used to link your application. To turn on this option in the Nios® II SBT, on the Window menu, click Preferences, select the Nios® II tab, and enable Show command lines when running make. You can also force the command lines to display by running make without the -s option from a Nios II command shell.

Note: Intel recommends that you not use the native linker nios2-elf-ld to link your programs. For the Nios® II processor, as for all softcore processors, the linking flow is complex. The g++ (nios2-elf-g++) command options simplify this flow. Most of the options are specified by the -m command-line option, but the options available depend on the processor choices you make.