我正在用c++和visual进行我的第一次测试,我不知道为什么,当程序中没有“未解决的外部符号”时,我遇到了一个问题。
错误97错误LNK2001:未解决的外部符号"public:静态类会话* __cdecl会话::实例(无效)“(?\MyTest\Messages.obj@ Session @SAPAV1 1@XZ)(.)\MyTest\Messages.obj MyTest 错误98错误LNK2001:未解决的外部符号"public: char * __thiscall Config::getLanguage(void)“(?getLanguage@Config@@QAEPADXZ) (.)\MyTest\Messages.obj MyTest 错误99错误LNK2001:未解决的外部符号"class wxString StringTranslate“(?StringTranslate@@3VwxString@@A) (.)\MyTest\Messages.obj MyTest 错误100错误LNK2001:未解决的外部符号"public: void __thiscall会话::addMSG(class std::shared_ptr)“ 错误101错误LNK2001:未解决的外部符号"public: char * __thiscall Config::getNick(void)“(?getNick@Config@@QAEPADXZ) LNK2001 MyTest 错误102错误LNK2001:未解决的外部符号"public: char * __thiscall Config::getServerAddress(void)“(?getServerAddress@Config@@QAEPADXZ) (.)MyTest\Messages.obj MyTest错误103错误LNK1120: 6个未解决的外部项
测试文件:
#include "stdafx.h"
#include "CppUnitTest.h"
#include <wx/wx.h>
#include <wx/stattext.h>
#include "data/Session.h"
#include "lib/ClientTS.cpp"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace MessageTXT
{
TEST_CLASS(UnitTest1)
{
public:
TEST_METHOD(TEST_MESSAGE_SEND)
{
ClientTS *clientts = new ClientTS;
wxString sr = "enviar_mensaje";
clientts->sendMessage(&sr);
clientts->disconnect();
}
};
}Clientts.h
#pragma once
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#include <wx/frame.h>
#else
#include <wx/wxprec.h>
#endif
#include "../data/Session.h"
#include "../data/Message.h"
#include "../data/Config.h"
#include "EventType.h"
#include <wx/sizer.h>
#include <wx/wx.h>
#include <wx/timer.h>
#include <wx/stattext.h>
#include <wx/richtext/richtextctrl.h>
#include <wx/textctrl.h>
#include <wx/button.h>
#include <wx/grid.h>
#include "../gui/NationList.h"
#include "../gui/NationInfo.h"
#include "../ArchiveLog.h"
#include "../GlobalVariables.h"
#include "../translateController/translateController.h"
#include "../translateController/translateVariable.h"
#include <list>
#include <functional>
#define MENU_ESCI 1800
#define MENU_OPZIONI 1801
#define MENU_SPEECH 1802
typedef std::function<void()> cbClientTsFrm;
class ClientTS {
public:
static Session* session;
static ConfigPTR config;
static bool flagSave;
static char LANG_MSG_SRC[500];
static char MSG_SRC[500];
static cbClientTsFrm notifyMSGcb;
//static ISoundEngine* engine; //Audio Engine to record sound
static IAudioRecorder* recorder; //Flow of audio daa
//static uint64 scHandlerID;
static char identity[IDENTITY_BUFSIZE];
/* Create struct for callback function pointers */
static struct ClientUIFunctions funcs;
public:
ClientTS(){
session = Session::Instance();
config = session->getConfig();
}
virtual ~ClientTS(){}
static void sendMessage(wxString *msgToSend);
static void disconnect();
static char* getLANG_MSG_SRC(){ return LANG_MSG_SRC; }
static char* getMSG_SRC(){ return MSG_SRC; }
static IAudioRecorder* getIAudioRecorder(){ return recorder; }
static bool getFlagSave(){ return flagSave; }
static void setFlagSave(bool flg){ flagSave = flg; }
template <typename Observer>
static void setCBClientTSMSG(Observer && fn){ notifyMSGcb = std::forward<Observer>(fn); }
static void speak(char *LANG, char*MSG);
static void Print(char*word);
static size_t read_callback(static void *ptr, size_t size, size_t nmemb, static void *userp);
static void writeWaveFile(const char* filename, SAudioStreamFormat format, static void* data);
static void SetupColor(COLORE *c);
static void onConnectStatusChangeEvent(uint64 serverConnectionHandlerID, int newStatus, unsigned int errorNumber);
static void onNewChannelEvent(uint64 serverConnectionHandlerID, uint64 channelID, uint64 channelParentID);
static void onNewChannelCreatedEvent(uint64 serverConnectionHandlerID, uint64 channelID, uint64 channelParentID, anyID invokerID, const char* invokerName, const char* invokerUniqueIdentifier);
static void onDelChannelEvent(uint64 serverConnectionHandlerID, uint64 channelID, anyID invokerID, const char* invokerName, const char* invokerUniqueIdentifier);
static void onClientMoveEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID, uint64 newChannelID, int visibility, const char* moveMessage);
static void onClientMoveSubscriptionEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID, uint64 newChannelID, int visibility);
static void onClientMoveTimeoutEvent(uint64 serverConnectionHandlerID, anyID clientID, uint64 oldChannelID, uint64 newChannelID, int visibility, const char* timeoutMessage);
static void onTalkStatusChangeEvent(uint64 serverConnectionHandlerID, int status, int isReceivedWhisper, anyID clientID);
static void onIgnoredWhisperEvent(uint64 serverConnectionHandlerID, anyID clientID);
static void onServerErrorEvent(uint64 serverConnectionHandlerID, const char* errorMessage, unsigned int error, const char* returnCode, const char* extraMessage);
static void onUserLoggingMessageEvent(const char* logMessage, int logLevel, const char* logChannel, uint64 logID, const char* logTime, const char* completeLogString);
static void onCustomPacketEncryptEvent(char** dataToSend, unsigned int* sizeOfData);
static void onCustomPacketDecryptEvent(char** dataReceived, unsigned int* dataReceivedSize);
static void onEditMixedPlaybackVoiceDataEvent(uint64 serverConnectionHandlerID, short* samples, int sampleCount, int channels, const unsigned int* channelSpeakerArray, unsigned int* channelFillMask);
static void showChannels(uint64 serverConnectionHandlerID);
static void showChannelClients(uint64 serverConnectionHandlerID, uint64 channelID);
static void onTextMessageEvent(uint64 serverConnectionHandlerID, anyID targetMode, anyID toID, anyID fromID, const char* fromName, const char* fromUniqueIdentifier, const char* message);
static void showClients(uint64 serverConnectionHandlerID);
static void createChannel(uint64 serverConnectionHandlerID, const char *name);
static void deleteChannel(uint64 serverConnectionHandlerID);
static void renameChannel(uint64 serverConnectionHandlerID);
static void switchChannel(uint64 serverConnectionHandlerID);
static void toggleVAD(uint64 serverConnectionHandlerID);
static void setVadLevel(uint64 serverConnectionHandlerID);
static void requestWhisperList(uint64 serverConnectionHandlerID);
static void requestClearWhisperList(uint64 serverConnectionHandlerID);
static void toggleRecordSound(uint64 serverConnectionHandlerID);
static int readIdentity(char* identity);
static int writeIdentity(const char* identity);
static uint64 enterChannelID();
static void createDefaultChannelName(char *name);
static void enterName(char *name);
static void emptyInputBuffer();
static DWORD WINAPI TTS_THREAD(LPVOID lpParameter);
static DWORD WINAPI CTRL_STT(LPVOID lpParameter);
static DWORD WINAPI ClientStart(LPVOID lpParameter);
static DWORD WINAPI STT_THREAD(LPVOID lpParameter);
};发布于 2015-03-09 20:25:13
您正在包括一个.cpp文件
#include "lib/ClientTS.cpp"应该是吧?
#include "lib/ClientTS.h"发布于 2015-03-09 20:33:10
该消息指出未解决的外部符号。
这意味着代码在语法上是正确的,但是当将所有Session和.lib文件链接在一起时,并不能找到所引用的所有外部符号(类.obj和类.lib成员函数)。
这意味着您缺少依赖关系:要么是项目中缺少源文件,要么是库文件。
https://stackoverflow.com/questions/28950665
复制相似问题