Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
All support for Intel NUC 7 - 13 systems has transitioned to ASUS. Read latest update.
12583 Discussions

Problem building a program with Nios II IDE : undefined reference to 'main'

Altera_Forum
Honored Contributor II
4,285 Views

Hi everyone. 

 

I'm a newbie at using Nios II IDE, and I'd like to run a C++ program I did on Cyclone II Development Board. For that, I created a "nios ii application with bsp template" with a .sopcinfo file that a coworker gave me. I created a "Hello_world" project and I renamed "hello_world.c" into "hello_world.cc" because I want to program in C++. 

 

I'll now talk about the following program : 

 

#include <iostream># include "system.h" int main() { return 0; } My problem is that I can't build that simple program, because I get the following error :  

 

 

--- Quote Start ---  

../Test_bsp/libhal_bsp.a(alt_main.o)(.text+0x58): In function `alt_main': 

d:/Algo_Nios/software/Test_bsp/HAL/src/alt_main.c:165: undefined reference to `main' 

--- Quote End ---  

which refers to the following lines in "alt_main.c" : 

 

#ifdef ALT_NO_EXIT main (alt_argc, alt_argv, alt_envp);# else result = main (alt_argc, alt_argv, alt_envp); <-- that's the line close(STDOUT_FILENO); exit (result);# endifI've tried various things, like including the "alt_main.h" librairy, or type "int alt_main()" instead of "int main()", but no matter what I do, I can't build the project. 

 

I'd appreciate any help or hints to solve my problem. 

 

Thanks, 

 

Tthegarde
0 Kudos
6 Replies
Altera_Forum
Honored Contributor II
2,362 Views

File name extension does matter. For instance, if you change the filename to "hello_world.cpp", it works. 

 

Jake
0 Kudos
Altera_Forum
Honored Contributor II
2,362 Views

I would report this to Altera.  

 

Table 4-3 on page 4-5 of the "NIOS II Software Developer's Handbook": 

http://www.altera.com/literature/hb/nios2/n2sw_nii5v2.pdf 

 

indicates that the ".cc" extension is supported. However, the Altera plugin for eclipse is not adding files with this extension to the Makefile automatically.  

 

Jake
0 Kudos
Altera_Forum
Honored Contributor II
2,362 Views

Thanks for your quick answer Jakobjones. I did renamed my file into "xxx.cpp" and it builds correctly. 

 

I did thought that the ".cc" extension was supported because I saw it in the Project --> "Properties / C/C++ General / File Types" and it was associated with "C++ Source Files" ... 

 

I'll check if that issue is not already known, and eventually report it to Altera. 

 

 

Tthegarde
0 Kudos
Altera_Forum
Honored Contributor II
2,362 Views

Hi all, 

 

I just had the same error whereas I work in C and not in C++ (enable_c_plus_plus option unchecked). 

 

The solution I found is to delete the /libhal_bsp.a file from the BSP and generate then clean -> build the project again and now it works. 

 

I've tried to regenerate the error without success.  

 

Maybe it can help some of you. 

 

Regards
0 Kudos
Altera_Forum
Honored Contributor II
2,362 Views

I did same way what you have mention here. I am still getting this errors undefined reference to fread, fopen, fseek

0 Kudos
Altera_Forum
Honored Contributor II
2,362 Views

Figured our another way around this. When I was creating the project from BSP file in Nios II Eclipse, the project directory already existed (and contained 2 source files inside). Apparently if the wizard isn't the one creating the folder, it will give you that error. So I renamed the folder to 'sources', created the project 'pname' in folder 'pname' that was not there and it worked.

0 Kudos
Reply