c++ - unitest 文件(visual studio)上未解析的外部符号

标签 c++ unit-testing visual-c++ visual-studio-2013

我正在用 c++ 和 visual studio 做我的第一个测试,我不知道为什么,当它在程序中没有发生时,我有一个“未解析的外部符号”的问题。

Error 97 error LNK2001: unresolved external symbol "public: static class Session * __cdecl Session::Instance(void)" (?Instance@Session@@SAPAV1@XZ) (...)\MyTest\Messages.obj MyTest

Error 98 error LNK2001: unresolved external symbol "public: char * __thiscall Config::getLanguage(void)" (?getLanguage@Config@@QAEPADXZ) (...)\MyTest\Messages.obj MyTest

Error 99 error LNK2001: unresolved external symbol "class wxString StringTranslate" (?StringTranslate@@3VwxString@@A) (...)\MyTest\Messages.obj MyTest

Error 100 error LNK2001: unresolved external symbol "public: void __thiscall Session::addMSG(class std::shared_ptr)" (?addMSG@Session@@QAEXV?$shared_ptr@VMessage@@@std@@@Z)(...)\speech-translation-tools\MyTest\Messages.obj MyTest

Error 101 error LNK2001: unresolved external symbol "public: char * __thiscall Config::getNick(void)" (?getNick@Config@@QAEPADXZ) (...)speech-translation-tools\MyTest\Messages.obj MyTest

Error 102 error LNK2001: unresolved external symbol "public: char * __thiscall Config::getServerAddress(void)" (?getServerAddress@Config@@QAEPADXZ) (...) MyTest\Messages.obj MyTest Error 103 error LNK1120: 6 unresolved externals

测试文件:

#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();

        }
    };
}

客户端.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);
};

最佳答案

您正在包含一个 .cpp 文件

#include "lib/ClientTS.cpp"

应该是吗?

#include "lib/ClientTS.h"

关于c++ - unitest 文件(visual studio)上未解析的外部符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28950665/

相关文章:

javascript - Sinon 不 Mocking db-mysql Node.js 库

asp.net-mvc - 单元测试 MVC Controller

c++ - 有没有办法用 Boost.Log 实现多个独立的日志系统?

python-3.x - 使用pytest-mock在python中使用SQLalchemy模拟数据库调用

c++ - 从 C++ 调用 Tensorflow Lite .tflite CNN 模型时的非法指令

Windows 结构的 C++

c++ - 如何使用 Microsoft Visual C++ 调试器调试 MinGW EXE?

c++ - 找不到 opencv_highgui230.dll

c++ - Lua C API : Handling and storing additional arguments

c++ - 如何使用fftw Guru界面