我有一个在cpp文件中实现的函数,并在头文件中声明。在主程序cpp文件中,我包含头文件并使用该函数。但是这无法链接(未定义的引用myFunc)。我需要做些什么才能让它发挥作用?
编辑:专业档案:
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
在main.cpp中我使用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
}
答案 0 :(得分:1)
我不能确定没有看到代码,但在你的* .h文件(与* .c文件相匹配的文件)中你应该这样做:
extern c{
// old c code
}