我有一个 DLL 项目,其中包含一个.h
文件,该文件在命名空间中定义了一个类和相关变量。这是使用 VS 2008 的 Windows XP。虽然很明显,这是一个 gstreamer 程序 :-)
receiverList
我想要命名空间中的变量IPC_RECEIVER
,但我想在该命名空间之外查看它,例如在相应的IPC_SENDER
命名空间中。
// IPC-Receiver..h
#ifndef IPCRECEIVER_H_
#define IPCRECEIVER_H_
namespace IPC_RECEIVER
{
.... class declaration.
}
typedef std::list<IPC_RECEIVER::GstReceiver*> ReceiverList_t;
typedef std::list<IPC_RECEIVER::GstReceiver*>::iterator ReceiverListIter_t;
#endif /* IPCRECEIVER_H_ */
然后是一个 cpp 文件,其中变量 g_receiverList 在 IPC_RECEIVE 命名空间中声明,但不在任何类中。
// IPC-ReceeiverAPIs.cpp
#include "IPC-Receiver.h"
namespace IPC_RECEIVER
{
ReceiverList_t g_receiverList; // list to track receivers
...
}
最后是第三个文件
// IPC-Receiver.cpp
#include "IPC-Receiver.h"
extern ReceiverList_t g_receiverList;
namespace IPC_RECEIVER
{
GstReceiver::GstReceiver()
{
g_receiverList.push_back( this );
}
}
当我编译这个我得到这个错误:
Error 1 error LNK2001: unresolved external symbol
"class std::list<class IPC_RECEIVER::GstReceiver *,
class std::allocator<class IPC_RECEIVER::GstReceiver *> > g_receiverList"
(?g_receiverList@@3V?$list@PAVGstReceiver@IPC_RECEIVER@
@V?$allocator@PAVGstReceiver@IPC_RECEIVER@@@std@@@std@@A)
IPC-Receiver.obj
我尝试了在 extern 和构造函数中添加命名空间名称的各种组合。
和
IPC_RECEIVER::g_receiverList.push_back( this );
我得到:
Error 1 error C2039: 'g_receiverList' : is not a member of
'IPC_RECEIVER' x:\Projects\IPC-dll\IPC-dll\IPC-Receiver.cpp 54 IPC-dll
与
extern ReceiverList_t IPC_RECEIVER::g_receiverList;
我收到两个错误:
Error 2 error C2039: 'g_receiverList' : is not a member of 'IPC_RECEIVER' x:\Projects\IPC-dll\IPC-dll\IPC-Receiver.cpp 22
Error 2 error C2039: 'g_receiverList' : is not a member of 'IPC_RECEIVER' x:\Projects\IPC-dll\IPC-dll\IPC-Receiver.cpp 55
其中 22 和 54 是g_receiverList
使用的行。
使用::
而不是IPC_RECEIVER::
也不起作用。
那么,我该如何进行这项工作:在一个文件的命名空间中声明一个变量并在另一个文件中使用它?
这是链接顺序问题吗?