Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

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

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);# endif
I'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

6 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

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

    Jake
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

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

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.