Momentics IDE - "undefined reference" for function

Hi everyone,
I am new to Momentics, but got it installed on a Linux machine and used the “10-steps to your first qnx program” to write, compile and debug a simple hello world application.

Now here is the problem:
As soon as I don’t write my code in the autogenerated, but put functions in a separate file (.c and .h), I get the following error:

undefined reference to ‘add(float, float)’

I added two simple files to the project, test.c and test.h, which look like this:
float add(float a, float b);

float add(float a, float b) {return a+b;}

The files are both in the main project folder (like and show up on the left side in the project list view as part of the project, but it seems like Momentics is still not using the test.c file in the project.

I tried to look for any setting in the project properties where I have to define the files I want to make into my project, but I can’t find anything. I have the same problem when I use Momentics in Windows.

This is probably really stupid, but I can’t figure it out. So any help would be great.

Many thanks,

Are you sure that you have got the same function name in test.h and test.c?
They are probably different. Check function name, add new line to all project files, save and try to recompile.

Did you #include “test.h” in test.c ?

If your file is and test.c then when use the prototype in test.h it assumes add() is a C++ fonction and apply the name mangling rule to it that explain why it can find it at link time. You need to tell add() is C and not C++ by having test.h look like this

#ifdef __cplusplus
extern “C” {

float add(float,float);

#ifdef __cplusplus

If this is the solution to your problem note that this has nothing to do with Momentics or QNX. It a C/C++ issue.