tags:

views:

139

answers:

1

Hi,

I have a function implemented in a cpp file and declared in header file. In the main program cpp file I include the header file and use the function. However this fails to link (undefined reference to myFunc). What do I have to change to get it working?

EDIT: pro file:

SOURCES += as241.c \
    main.cpp \
    normalvar.cpp \
    normaldistribution.cpp \
    studenttdistribution.cpp
LIBS += -lgsl \
    -lgslcblas \
    -lm
HEADERS += as241.h \
    var.h \
    distribution.h \
    normalvar.h \
    normaldistribution.h \
    studenttdistribution.h

In main.cpp I use a function from as241

as241.h:

#ifndef AS241_H
#define AS241_H

double ppnd16(double p);

#endif // AS241_H

as241.cpp:

#include "as241.h"
#include <math.h>

double ppnd16(double p)
{
  //code
}
+1  A: 

I can't be sure without seeing the code, but in yout *.h file (the one that matches the *.c file) you should do:

extern c{
// old c code
}
elcuco
All the files I mentioned are added to the project.
Grzenio