0

I am trying to generate assembly and executable of a simple neon-based c code. The code is,

  #include <arm_neon.h>
  void NeonTest(short int * __restrict a, short int * __restrict b, short int * __restrict z)
{
int i;
for (i = 0; i < 200; i++) {
z[i] = a[i] * b[i];
            }
}

First, I am going for the assembly to calculate the neon instructions,

arm-linux-gnueabi-gcc -O2 -march=armv7-a -mtune=cortex-a9 -ftree-vectorize -mhard-float -mfloat-abi=softfp -mfpu=neon -S neon_test.c -o nt.s

Then I am converting the nt.s file to object file.

arm-linux-gnueabi-gcc -O2 -march=armv7-a -mtune=cortex-a9 -ftree-vectorize -mhard-float -mfloat-abi=softfp -mfpu=neon -c nt.s -o nt.o

Finally, for the executable I do,

arm-linux-gnueabi-gcc -O2 -march=armv7-a -mtune=cortex-a9 -ftree-vectorize -mhard-float -mfloat-abi=softfp -mfpu=neon nt.o -o nt

I get the error,

/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/lib/crt1.o: In function `_start':
(.text+0x34): undefined reference to `main'
collect2: error: ld returned 1 exit status

I am using Ubuntu 14LTS on Intel system.

junaids
  • 177
  • 1
  • 4
  • 17
  • As the error says it all: There is no function called `main()` in your program. Check this on why main is required http://stackoverflow.com/questions/4264367/why-is-main-necessary-in-a-program – Santosh A Sep 03 '15 at 04:52
  • 1
    @SantoshA thanks the problem is solved in including a main function. – junaids Sep 03 '15 at 05:21

2 Answers2

2

You're not including the C file that contains main() when compiling, so the linker isn't seeing it You need to add it:

arm-linux-gnueabi-gcc -O2 -march=armv7-a -mtune=cortex-a9 -ftree-vectorize -mhard-float -mfloat-abi=softfp -mfpu=neon nt.o main.o -o nt

where main.o is also created following the same step as neon.o

Sandeep Kumar
  • 336
  • 1
  • 3
  • 9
1

Every program needs a starting point so the computer knows where to begin execution. In C/C++, the starting point is the beginning of the function int main. Give your program an int main by either linking your object file to an object file with int main, or adding one in this code.

To add main in your code, beneath your function definition, try

int main()
{
    NeonTest(/* your parameters */);
}
Ben
  • 5,952
  • 4
  • 33
  • 44