我正在为我的研发需求制作小型库。为此,我使用 Qt 4.8.6 和 Visual Stuido 2012。
这是我的.pro
文件
TEMPLATE = lib
TARGET = mylib
CONFIG += dll
HEADERS = mymath.h
SOURCES = mymath.cpp \
INCLUDEPATH += ../include \
DEFINES += MYMATHIMPL
这是我类(class)的.h
文件
#ifndef MY_MATH_H
#define MY_MATH_H
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <float.h>
#if defined(MYMATHIMPL)
# define MYMATHAPI Q_DECL_EXPORT
#else
# define MYMATHAPI Q_DECL_IMPORT
#endif
typedef struct
{
double * b;
double * c;
double * d;
double * _m;
} akima_state_t;
class MYMATHAPI AkimaInterpolator
{
public:
AkimaInterpolator(double * _x_values, double * _y_values, size_t size);
AkimaInterpolator(double *d, double *c, double* b, double *_x_values, double* _y_values, size_t _size);
~AkimaInterpolator();
double evaluateAtX(double x);
static int searchIndex(const double sortedArray[], double toFind, int len);
};
.cpp
文件包含所有声明的方法和实现。
但是当我尝试构建这个库时出现错误:
mymath.h(31): error C2470: AkimaInterpolator:: looks like a function definition, but there is no parameter list; skipping apparent body.
我检查了编译器标志,似乎设置了 MYMATHIMPL
。
cl -c -nologo -Zm200 -Zc:wchar_t- -Zi -MDd -GR -EHsc -W3 -w34100 -w34189 -DUNICODE -DWIN32 -DACPMATHIMPL -D_DEBUG -D__STDC_LIMIT_MACROS -D__ST
DC_FORMAT_MACROS -DSPM_VERSION_INFO -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -D
QT_THREAD_SUPPORT -I"c:\Qt\4.8.6\include\QtCore" -I"c:\Qt\4.8.6\include\QtGui" -I"c:\Qt\4.8.6\include" -I"..\include" -I"..\..\common\include" -I"-I"..\..\common\include" -I"..\
..\common\include" -I"c:\Qt\4.8.6\include\ActiveQt" -I"..\..\..\temp\acp_v2\debug" -I"c:\Qt\4.8.6\mkspecs\win32-msvc2012" -Fo..\..\..\temp\acp_v2\debug\ @C:\Users\admin\AppData\Local\Temp\nmC62D.tmp
我做错了什么?为什么阻止:
#if defined(MYMATHIMPL)
# define MYMATHAPI Q_DECL_EXPORT
#else
# define MYMATHAPI Q_DECL_IMPORT
#endif
没有按预期工作?
最佳答案
您没有包含任何可能定义 Q_DECL_EXPORT
的 QT header 或 Q_DECL_IMPORT
,它们也不是由命令行定义的。所以你使用 MYMATHAPI
扩展为 Q_DECL_EXPORT
,而不是应该扩展到的任何内容。
我认为它们是在 <QtGlobal>
中定义的.
关于c++ - C2470 错误 Visual Studio 2012 和 Qt 4.8.6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29603649/