c++ - 如何让QtCreator编译多个cpp和头文件?

标签 c++ qt-creator

我有一个在 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/

相关文章:

c++ - 为什么我的应用程序会出现C++ unknown reference link错误,而linux中的库却不会

c++ - 为 STL 随机数生成器编写工厂方法

c++ - 了解 C++ 中的继承

c++ - 可能是 boost ssl 握手函数有一些内存泄漏

c++ - 将 3D 数组传递给类(转换问题)

qt4 - 声子后端插件无法加载

visual-studio-2010 - 使用 Qt Creator 设置 OpenCV 2.4.2

c++ - 如何将我的应用静态链接到 ICU 57.1 MinGW

c++ - 使用 Qt Creator 表单进行适当的子类化?

qt - 如何在 QtCreator 中为项目创建文件夹或子目录?