【发布时间】:2016-08-01 12:50:34
【问题描述】:
我有这样的 IGlobal.h 文件:
#ifndef _IGLOBALS_
#define _IGLOBALS_
#define _USE_MATH_DEFINES
#define PLUG_NUM_CHANNELS 2
#define PLUG_NUM_PRESETS 1
#define PLUG_FPS 100
#define PLUG_PPQ 96
#define KNOB_NUM_FRAMES 128
#define PIANOROLL_MIN_NOTES 2
#define PIANOROLL_MAX_NOTES 8
#define PIANOROLL_MIN_VELOCITY 40
#define PIANOROLL_MAX_VELOCITY 127
#define PIANOROLL_PATTERN_LENGTH PLUG_PPQ * 4
#define LFO_NUM_SAMPLES 882
#define WAVEPLAYER_WIDTH 441
#define WAVEPLAYER_HEIGHT 136
#define WAVEPLAYER_PATH_LENGTH 256
#define ENVELOPE_MIN_VALUE 0.0001
#include <algorithm>
#include <random>
#include <chrono>
#include <math.h>
#include <cmath>
#include "IPlug_include_in_plug_hdr.h"
using namespace std;
// bitmaps
IBitmap gBitmapKnobGeneral;
#endif // !_IGLOBALS_
我经常从项目中的 .h/.cpp 文件中包含它。 IBitmap 是一个结构体。
当我构建(编译)时,它说:
LNK1169 one or more multiply defined symbols found
LNK2005 "struct IBitmap gBitmapKnobGeneral" ?gBitmapKnobGeneral@@3UIBitmap@@A) already defined in ICustomControls.obj
事实上,我每次包含 IGlobal.h 时都会得到它。 #ifndef 不应该放弃这个问题吗?或者编译器自动只为declarations 而不是definitions?
【问题讨论】:
-
#endif在哪里?或者这只是文件的开头?请您添加整个错误消息吗?IPlug_include_in_plug_hdr.h包含保护吗?顺便说一句,我认为#define PIANOROLL_PATTERN_LENGTH PLUG_PPQ * 4可能会导致一些糟糕的预处理器问题。最好加上括号。 -
一般来说,你会在头文件中声明一个变量为extern,然后在一个cpp文件中定义它。
-
@RetiredNinja:是的,通常!但是如果我不这样做,编译器会自动执行吗?
-
为什么你有
#include <math.h>,然后是#include <cmath>?检查Math constants
标签: c++ include-guards