Electrical – DSP Library not working in MPLAB X

digital filterdspmicrochipmplabxpic

I have to make a digital filter with a dsPIC30F4011 (I'm completely new to microcontrollers). I was reading the documentation about the DSP Library to figure out how to use it. I created a simple C program based on a piece of code I saw in the documentation:

#include <stdio.h>
#include <stdlib.h>
#include <p30F4011.h>
#include <dsp.h>
#include <xc.h>

int main(int argc, char** argv) {

    fractional *dstV;
    fractional srcV1[2] = {Q15(0.2), Q15(0.2)};
    fractional srcV2[2] = {Q15(0.5), Q15(0.5)};

    dstV = VectorAdd(2, dstV, srcV1, srcV2);

    int n = 1;

    return (EXIT_SUCCESS);
}

But when I build it, I get the following messages:

build/default/production/main.o(.text+0x22): In function `_main':
: undefined reference to `_VectorAdd'
make[2]: *** [dist/default/production/test-dspic.X.production.hex] Error 255
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
nbproject/Makefile-default.mk:135: fallo en las instrucciones para el objetivo 'dist/default/production/test-dspic.X.production.hex'
make[2]: se sale del directorio '/home/adrian/MPLABXProjects/test-dspic.X'
nbproject/Makefile-default.mk:90: fallo en las instrucciones para el objetivo '.build-conf'
make[1]: se sale del directorio '/home/adrian/MPLABXProjects/test-dspic.X'
nbproject/Makefile-impl.mk:39: fallo en las instrucciones para el objetivo '.build-impl'

BUILD FAILED (exit value 2, total time: 1s)

It says that the function VectorAdd isn't defined. Is there something wrong or missing?

Best Answer

Adding the libdsp-elf.a library to the project from the appropriate xc16/lib directory lets the above program link properly (at least in my environment).

Review section 1.2 in the 51456b.pdf document for different ways to set it up (environment variables, including it in the library section of the project, etc.