我有一個DLL項目,它有一個.h
文件,它定義了一個名稱空間中的類和相關變量。這是使用VS 2008的Windows XP。雖然很明顯,這是一個gstreamer程序:-)在多個C++源文件中使用的命名空間
我想要名稱空間IPC_RECEIVER
中的變量receiverList
,但我想在該名稱空間外面查看它,例如對應的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_ */
然後其中變量g_receiverList在IPC_RECEIVE命名空間中聲明,但沒有在任何類cpp文件。
// 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"
([email protected]@[email protected]@[email protected]
@[email protected]@[email protected]@@[email protected]@@[email protected]@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::
也不起作用。
那麼,我該如何完成這項工作:在一個文件的命名空間中聲明一個變量並在另一個文件中使用它?
這是鏈接順序問題嗎?
賓果!馬上工作。 – 2013-02-20 19:30:35