我有一个在 cpp 文件中实现并在头文件中声明的函数。在主程序 cpp 文件中,我包含了头文件并使用了该函数。但是,这无法链接(对 myFunc 的 undefined reference )。我必须更改什么才能使其正常工作?
编辑:专业文件:
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
}
最佳答案
如果没有看到代码,我无法确定,但在你的 *.h 文件(与 *.c 文件匹配的文件)中你应该这样做:
extern c{
// old c code
}
关于c++ - 如何让QtCreator编译多个cpp和头文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2009161/