Nios II: Getting or building the toolchain
From Crashcourse Wiki
You can get a Nios II cross-compile toolchain in one of two ways:
- Download a prebuilt one, or
- Build your own.
Installing the pre-built toolchain
Simply download the Nios II toolchain tarball found [here]. That tarball unloads its entire contents under the relative directory opt/nios2 and, while some online documentation insists that that toolchain must be installed directly under the root directory, it seems perfectly acceptable to install it elsewhere in a non-root directory as long as your search path is set correctly to find it.
Regardless of where you install it, a quick test is to simply try to cross-compile your basic "Hello, world" C program and check the result:
$ nios2-linux-gcc hi.c $ file a.out a.out: ELF 32-bit LSB executable, version 1, statically linked, not stripped $
Sadly, unlike with other more-established architectures, the Linux file command still doesn't know about Nios II, which is why you don't get that information printed out, only the fact that it's an ELF executable.
In addition, if you're curious, you can examine the actual properties of the toolchain's compiler with (lines broken for readability):
$ nios2-linux-gcc -v Reading specs from /home/rpjday/nios/opt/nios2/bin/../lib/gcc/nios2-linux-uclibc/3.4.6/specs Configured with: /root/buildroot/toolchain_build_nios2/gcc-3.4.6/configure \ --prefix=/opt/nios2 --build=i386-pc-linux-gnu --host=i386-pc-linux-gnu --target=nios2-linux-uclibc --enable-languages=c,c++ --disable-__cxa_atexit --enable-target-optspace --with-gnu-ld --disable-shared --disable-nls --enable-threads --enable-multilib Thread model: posix gcc version 3.4.6 $
Building your own toolchain
If you're feeling ambitious, you can try to build your own Nios II toolchain from scratch, following the directions on the first part of the Nios wiki page [here]. After doing a Subversion checkout of buildroot and running make menuconfig, make sure you deselect everything that doesn't involve building the toolchain, at which point most of your work will be configuring what's under the "Toolchain" submenu.
Some of the critical pieces of info for your toolchain configuration (at least for now):
- Use precisely the version of 2.6.23.x for the Linux kernel headers.
- Use precisely the version of 0.9.29 for uClibc.
- There is no NPTL support; if you want threads, select "linuxthreads (stable/old)".
- The wiki page also recommends enabling elf2flt, RPC and WCHAR support.
- The pre-built toolchain has multilib support, so you might want to enable that as well.
- If you choose to build the optional gdb, it must be version 6.6.
If the build succeeds, you can find the new toolchain components under build_nios2/staging_dir/bin, which is the directory you would add to your search path.
Return to Altera Nios II main page.

