I have copied header file and cpp file from one of my old project( build in VS-2010) into new project( developing it in QT5.1) and have encounter this weird error
1>Message_list.obj : error LNK2019: unresolved external symbol "public: bool __thiscall Message_list::NoMessageTime::operator()(struct Message const &,struct Message const &)const " (??RNoMessageTime#Message_list##QBE_NABUMessage##0#Z) referenced in function "bool __cdecl std::_Debug_lt_pred<class Message_list::NoMessageTime,struct Message,struct Message>(class Message_list::NoMessageTime,struct Message &,struct Message const &,wchar_t const *,unsigned int)" (??$_Debug_lt_pred#VNoMessageTime#Message_list##UMessage##U3##std##YA_NVNoMessageTime#Message_list##AAUMessage##ABU3#PB_WI#Z)
I have no idea how to solve it.
In my header file
Message_list.h
#include <set>
#include <QSTRING>
#include "Message.h"
class Message_list
{
class NoMessageTime
{
public:
bool operator ()( const Message& left, const Message& right ) const;
};
typedef std::multiset<Message, NoMessageTime> MessageSet;
public:
void add( const Message& message );
private:
/** Inserts an item into the correct place in the list
*/
void Message_list::insert_item( const Message& message );
MainWindow* dialog_;
MessageSet messages_;
};
Message_list.cpp
void Message_list::addd( const Message& message )
{
QMutex mutex;
mutex.lock();
// Do something here
messages_.insert( message ); // error comes here
mutex.unlock();
}
Same files compiled successfully in vs-2010..
Related
I am looking use web sockets in Unreal. I am following the tutorial found here: Web Socket Tutorial
Most notably I am trying to bind to the events before connection. In the example, they use .AddLambda however, I would like to try to use .AddUFunction. It seems the function takes in the Object, the function name, and VarTypes ...types. I can't seem to figure out what the last parameter is for the delegates that use parameters. (At least I believe that is the problem anyway) The functions themselves have the correct signature and matches the delegates I want to bind to.
Here is what I have so far:
void AWebSocketController::CreateWebSocket(FString ServerUrl, FString ServerProtocol)
{
Socket = FWebSocketsModule::Get().CreateWebSocket(ServerUrl, ServerProtocol);
// We bind to the events
Socket->OnConnected().AddUFunction(this, FName("OnSocketConnection"));
Socket->OnConnectionError().AddUFunction(this, FName("OnSocketConnectionError"));
Socket->OnClosed().AddUFunction(this, FName("OnSocketClosed"));
Socket->OnMessage().AddUFunction(this, FName("OnSocketReceiveMessage"));
Socket->OnMessageSent().AddUFunction(this, FName("OnSocketSentMessage"));
// And we finally connect to the server.
Socket->Connect();
}
It gives me the following error messages:
error LNK2005: "public: void __cdecl AWebSocketController::OnSocketClosed(int,class FString const &,bool)" (?OnSocketClosed#AWebSocketController##QEAAXHAEBVFString##_N#Z) already defined in WebSocketController.cpp.obj
error LNK2005: "public: void __cdecl AWebSocketController::OnSocketConnection(void)" (?OnSocketConnection#AWebSocketController##QEAAXXZ) already defined in WebSocketController.cpp.obj
error LNK2005: "public: void __cdecl AWebSocketController::OnSocketConnectionError(class FString const &)" (?OnSocketConnectionError#AWebSocketController##QEAAXAEBVFString###Z) already defined in WebSocketController.cpp.obj
error LNK2005: "public: void __cdecl AWebSocketController::OnSocketReceiveMessage(class FString const &)" (?OnSocketReceiveMessage#AWebSocketController##QEAAXAEBVFString###Z) already defined in WebSocketController.cpp.obj
error LNK2005: "public: void __cdecl AWebSocketController::OnSocketSentMessage(class FString const &)" (?OnSocketSentMessage#AWebSocketController##QEAAXAEBVFString###Z) already defined in WebSocketController.cpp.obj
The function definitions:
void AWebSocketController::OnSocketConnection()
{
}
void AWebSocketController::OnSocketConnectionError(const FString& ErrorMessage)
{
}
void AWebSocketController::OnSocketClosed(int32 StatusCode, const FString& Reason, bool WasClean)
{
}
void AWebSocketController::OnSocketReceiveMessage(const FString& Message)
{
}
void AWebSocketController::OnSocketSentMessage(const FString& Message)
{
}
I have never come across this .AddUFunction before and I can't seem to find any examples of how to use it. If anyone can help me out or point me in the right direction, it would be appreciated.
Works for me!
SandboxGameInstance.cpp
#include "SandboxGameInstance.h"
#include "WebSocketsModule.h"
#include "IWebSocket.h" // Socket definition
void USandboxGameInstance::Init()
{
Super::Init();
FWebSocketsModule& Module = FModuleManager::LoadModuleChecked<FWebSocketsModule>(TEXT("WebSockets"));
const FString ServerURL = TEXT("ws://127.0.0.1:3000/"); // Your server URL. You can use ws, wss or wss+insecure.
const FString ServerProtocol = TEXT("ws"); // The WebServer protocol you want to use.
TSharedPtr<IWebSocket> Socket = FWebSocketsModule::Get().CreateWebSocket(ServerURL, ServerProtocol);
// We bind to the events
Socket->OnConnected().AddUFunction(this, FName("OnSocketConnection"));
Socket->OnConnectionError().AddUFunction(this, FName("OnSocketConnectionError"));
Socket->OnClosed().AddUFunction(this, FName("OnSocketClosed"));
Socket->OnMessage().AddUFunction(this, FName("OnSocketReceiveMessage"));
Socket->OnMessageSent().AddUFunction(this, FName("OnSocketSentMessage"));
// And we finally connect to the server.
Socket->Connect();
}
void USandboxGameInstance::OnSocketConnection()
{
UE_LOG(LogTemp, Warning, TEXT("CONNECTED"));
}
void USandboxGameInstance::OnSocketConnectionError(const FString& ErrorMessage)
{
UE_LOG(LogTemp, Warning, TEXT("ERROR"));
}
void USandboxGameInstance::OnSocketClosed(int32 StatusCode, const FString& Reason, bool WasClean)
{
UE_LOG(LogTemp, Warning, TEXT("CLOSED"));
}
void USandboxGameInstance::OnSocketReceiveMessage(const FString& Message)
{
UE_LOG(LogTemp, Warning, TEXT("RECEIVED"));
}
void USandboxGameInstance::OnSocketSentMessage(const FString& Message)
{
UE_LOG(LogTemp, Warning, TEXT("SENT"));
}
SandboxGameInstance.h
#pragma once
#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "SandboxGameInstance.generated.h"
UCLASS()
class SANDBOX_API USandboxGameInstance : public UGameInstance
{
GENERATED_BODY()
public:
virtual void Init() override;
UFUNCTION()
void OnSocketConnection();
UFUNCTION()
void OnSocketConnectionError(const FString& ErrorMessage);
UFUNCTION()
void OnSocketClosed(int32 StatusCode, const FString& Reason, bool WasClean);
UFUNCTION()
void OnSocketReceiveMessage(const FString& Message);
UFUNCTION()
void OnSocketSentMessage(const FString& Message);
};
Please read the Documentation on Events
You must declare function signatures that match that of the Event Delegate within your class for which a function pointer will be bound.
The example image above is from the Engine Source.
I'm trying to code a little plugin for bakkesmod because I'm pissing myself off.
I watched the only 2 video that exists on this topic but ... it doesn't work and I have this error for each void - >> Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol "__declspec(dllimport) public: void __thiscall GameWrapper::HookEvent(class std::basic_string<char,struct std::char_traits,class std::allocator >,class std::function<void __cdecl(class std::basic_string<char,struct std::char_traits,class std::allocator >)>)" (_imp?HookEvent#GameWrapper##QAEXV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$function#$$A6AXV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z#3##Z) TagName C:\Users\leodu\source\repos\TagName\TagName\TrollTagName.obj 1
here is my code.
TroolTagName.cpp (not judge the name)
#include "TrollTagName.h"
BAKKESMOD_PLUGIN(TroolTagName, "Trool Tag Name", "1.0", PERMISSION_ALL)
void TroolTagName::onLoad()
{
this->Log("This is my first Bakkesmod Plugin");
this->LoadHooks();
}
void TroolTagName::onUnload()
{
}
void TroolTagName::LoadHooks()
{
gameWrapper->HookEvent("Function TAGame.GameEvent_Soccar_TA.EventMatchEnded", std::bind(&TroolTagName::GameEndedEvent, this, std::placeholders::_1));
gameWrapper->HookEvent("Function TAGame.AchievementManager_TA.HandleMatchEnded", std::bind(&TroolTagName::GameEndedEvent, this, std::placeholders::_1));
}
void TroolTagName::GameEndedEvent(std::string name)
{
cvarManager->executeCommand("load_freeplay");
}
void TroolTagName::Log(std::string msg)
{
cvarManager->log("TroolTagName: " + msg);
}
TroolTagName.h
#include "bakkesmod\plugin\bakkesmodplugin.h"
#pragma comment(lib, "pluginsdk.lib")
class TroolTagName : public BakkesMod::Plugin::BakkesModPlugin
{
public:
virtual void onLoad();
virtual void onUnload();
void LoadHooks();
void GameEndedEvent(std::string name);
private:
void Log(std::string msg);
};
The project and a Dynamic-library dll project.
I tried adding __declspec (dllexport) before void but ... I got this error - >> redefinition; different linkage and I found nothing for this error so I am blocked :(
I wrote a simple class which manages the current execution session. Therefore, I decided to use a singleton pattern but the compilation crashes at linked step. This is the error:
error LNK2005: "class Session * session" (?session##3PAVSession##A) already defined in ClientTsFrm.obj
(...)client\FrmSaveChat.obj TeamTranslate
error LNK2005: "class Session * session" (?session##3PAVSession##A) already defined in ClientTsFrm.obj
(...)client\Login.obj TeamTranslate
error LNK2019: unresolved external symbol "protected: __thiscall Session::Session(void)" (??0Session##IAE#XZ)
referenced in function "public: static class Session * __cdecl Session::Instance(void)" (?Instance#Session##SAPAV1#XZ)
(...)client\Session.obj TeamTranslate
error LNK2001: unresolved external symbol "private: static char const * const Session::_nick" (?_nick#Session##0PBDB)
(...)client\Session.obj TeamTranslate
error LNK2001: unresolved external symbol "private: static char const * const Session::_service" (?_service#Session##0PBDB)
(...)client\Session.obj TeamTranslate
error LNK2001: unresolved external symbol "private: static char const * const Session::_serverAddress" (?_serverAddress#Session##0PBDB)
(...)client\Session.obj TeamTranslate
error LNK2001: unresolved external symbol "private: static char const * const Session::_googleAPI" (?_googleAPI#Session##0PBDB)
(...)client\Session.obj TeamTranslate
error LNK2001: unresolved external symbol "private: static char const * const Session::_language" (?_language#Session##0PBDB)
(...)client\Session.obj TeamTranslate
error LNK2001: unresolved external symbol "private: static int Session::_numbLanguageSelected" (?_numbLanguageSelected#Session##0HA)
(...)client\Session.obj TeamTranslate
error LNK2001: unresolved external symbol "private: static char const * const Session::_translationEngine" (?_translationEngine#Session##0PBDB)
(...)client\Session.obj TeamTranslate
error LNK1120: 8 unresolved externals
(...)client\bin\TeamTranslate.exe TeamTranslate
IntelliSense: identifier "wxZipStreamLink" is undefined
(..)\include\wx\zipstrm.h 417 5
session.h (singleton)
#ifndef __SESSION_H__
#define __SESSION_H__
#include <cstring>
#include <stdio.h>
class Session {
public:
static Session* Instance();
void setNick(char* nick);
const char* getNick();
void setService(char* serv);
const char* getService();
void setLanguage(char* lang);
const char* getLanguage();
const char* getServerAddress();
void setServerAddress(char *sv);
void setGoogleAPIKey(char* code);
const char* getGoogleAPIKey();
void setNumbLanguageSelected(int v);
int getNumbLanguageSelected();
const char* Session::getTranslationEngine();
void Session::setTranslationEngine(char *sv);
char* Session::getGoogleURLTranslation();
void update();
bool read();
protected:
Session();
private:
static Session* _instance;
static const char* _nick; // client nickname
static const char* _service; // service used to translation (Google, Bing,....)
static const char* _serverAddress;
static const char* _googleAPI;
static const char* _language;
static int _numbLanguageSelected;
static const char* _translationEngine;
};
#endif
Session.cpp
#include "Session.h"
Session* Session::_instance = 0;
Session* Session::Instance() {
if (_instance == 0) {
_instance = new Session;
_instance->read();
}
return _instance;
}
void Session::setGoogleAPIKey(char* code){
_googleAPI = strdup(code);
}
const char* Session::getGoogleAPIKey(){
return _googleAPI;
}
void Session::setLanguage(char* lang){
_language = strdup(lang);
}
const char* Session::getLanguage(){
return _language;
}
void Session::setNick(char* nick){
_nick = strdup(nick);
}
const char* Session::getNick(){
return _nick;
}
void Session::setService(char* serv){
_service = strdup(serv);
}
const char* Session::getService(){
return _service;
}
const char* Session::getServerAddress(){
return _serverAddress;
}
void Session::setServerAddress(char *sv){
_serverAddress = strdup(sv);
}
void Session::setNumbLanguageSelected(int v){
this->_numbLanguageSelected = v;
}
int Session::getNumbLanguageSelected(){
return _numbLanguageSelected;
}
const char* Session::getTranslationEngine(){
return _translationEngine;
}
void Session::setTranslationEngine(char* sv){
_translationEngine = strdup(sv);
}
void Session::update(){
FILE* config = fopen("conf\\config.txt", "w");
fprintf(config, "%s\n", _serverAddress);
fprintf(config, "%s\n", _nick);
fprintf(config, "%d\n", _numbLanguageSelected);
fprintf(config, "%s\n", _language);
fprintf(config, "%s", _translationEngine);
fflush(config);
fclose(config);
}
bool Session::read(){
FILE * config;
if (config = fopen("conf\\config.txt", "r"))
{
fscanf(config, "%s", _serverAddress);
fscanf(config, "%s", _nick);
fscanf(config, "%d", _numbLanguageSelected);
fscanf(config, "%s", _language);
fscanf(config, "%s", _translationEngine);
fflush(config);
fclose(config);
return true;
} else
return false;
}
char* Session::getGoogleURLTranslation(){
return "https://www.googleapis.com/language/translate/v2?key=";
}
Example about how I call the singleton:
#include "../data/Session.h"
static Session* session = Session::Instance();
Can you help me to fix the errors?
thanks in advance.
One of your headers (which you didn't show, but it is included in both "ClientTsFrm.cpp" and "FrmSaveChat.cpp") defines a variable called "session" of type Session*.
The other errors are caused by your forgetting to define most static members of Session.
I created a templated data class (CAnyData, please see its header file copy for your reference), with which I declared some variables in my another class (CConstantDataBlock, please see its header file copy for your reference). As you may see, the latter one is nearly an empty class. But when I compiled my project, the VS2008 compiler thowed the following linking errors. Would please help me figure out what's wrong with my CConstantDataBlock and/or CAnyData?
1>------ Build started: Project: Tips, Configuration: Debug Win32 ------
1>Compiling...
1>ConstantDataBlock.cpp
1>Linking...
1> Creating library F:\Tips\Debug\Tips.lib and object F:\Tips\Debug\Tips.exp
1>ConstantDataBlock.obj : error LNK2019: unresolved external symbol "public: __thiscall CAnyData<double>::~CAnyData<double>(void)" (??1?$CAnyData#N##QAE#XZ) referenced in function __unwindfunclet$??0CConstantDataBlock##QAE#XZ$0
1>ConstantDataBlock.obj : error LNK2019: unresolved external symbol "public: __thiscall CAnyData<int>::~CAnyData<int>(void)" (??1?$CAnyData#H##QAE#XZ) referenced in function __unwindfunclet$??0CConstantDataBlock##QAE#XZ$0
1>ConstantDataBlock.obj : error LNK2019: unresolved external symbol "public: __thiscall CAnyData<double>::CAnyData<double>(void)" (??0?$CAnyData#N##QAE#XZ) referenced in function "public: __thiscall CConstantDataBlock::CConstantDataBlock(void)" (??0CConstantDataBlock##QAE#XZ)
1>ConstantDataBlock.obj : error LNK2019: unresolved external symbol "public: __thiscall CAnyData<int>::CAnyData<int>(void)" (??0?$CAnyData#H##QAE#XZ) referenced in function "public: __thiscall CConstantDataBlock::CConstantDataBlock(void)" (??0CConstantDataBlock##QAE#XZ)
1>F:\Tips\Debug\Tips.exe : fatal error LNK1120: 4 unresolved externals
1>Build log was saved at "file://f:\Tips\Tips\Debug\BuildLog.htm"
1>Tips - 5 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
#pragma once
#include <string>
using namespace std;
template <class T>
class CAnyData
{
public:
CAnyData(void);
CAnyData(int nWordNumber, string sContents, T Type, int nWidth, int nPrecision);
~CAnyData(void);
// Operators
CAnyData( const CAnyData& rhs );
const CAnyData& operator = (const CAnyData& rhs);
// Must define less than relative to name objects.
bool operator<( const CAnyData& AnyData ) const;
// Compares profile's of two objects which represent CAnyData
inline bool operator ==(const CAnyData& rhs) const;
// Get properties
inline int WordNumber() const { return m_nWordNumber; }
inline const string& Contents() const { return m_sContents; }
inline const T& DataType() const { return m_Type; }
inline int Width() const { return m_nWidth; }
inline int Precision() const { return m_nPrecision; }
// Set properties
void WordNumber(int nWordNumber) const { m_nWordNumber = nWordNumber; }
void Contents(string sContents) const { m_sContents = sContents; }
void DataType(T Type) const { m_Type = Type; }
void Width(int nWidth) const { m_nWidth = nWidth; }
void Precision(int nPrecision) const { m_nPrecision = nPrecision; }
protected:
void Init(void);
protected:
int m_nWordNumber;
string m_sContents;
T m_Type;
int m_nWidth;
int m_nPrecision;
};
#pragma once
#include "AnyData.h"
// Constants block
// This block consists of 64 words to be filled with useful constants.
class CConstantDataBlock
{
public:
CConstantDataBlock(void);
~CConstantDataBlock(void);
protected:
CAnyData<int> m_nEarthEquatorialRadius;
CAnyData<int> m_nNominalSatelliteHeight;
CAnyData<double> m_dEarthCircumference;
CAnyData<double> m_dEarthInverseFlattening;
};
It seems that you do not have definitions for several of the methods of CAnyData, including the default constructor and the destructor. When you use these in your CConstantDataBlock-class, the constructor and destructor are required though.
Since CAnyData is a class-template, all definitions should be written directly into the header-file (just as you have done with all the getters and setters).
I have an very strange error: when I want to use the SocialServer::Client class from my SocialServer::Server class, the linker threw me two LNK2019 errors :
Error 1 error LNK2019: unresolved external symbol "public: void __thiscall SocialServer::Client::Handle(void)" (?Handle#Client#SocialServer##QAEXXZ) referenced in function "private: static unsigned int __stdcall SocialServer::Server::listenThread(void *)" (?listenThread#Server#SocialServer##CGIPAX#Z) C:\Users\benjamin\Documents\Visual Studio 2010\Projects\FCX Social Server\SocialServer Core\Server.obj SocialServer Core
Error 2 error LNK2019: unresolved external symbol "public: __thiscall SocialServer::Client::Client(unsigned int)" (??0Client#SocialServer##QAE#I#Z) referenced in function "private: static unsigned int __stdcall SocialServer::Server::listenThread(void *)" (?listenThread#Server#SocialServer##CGIPAX#Z) C:\Users\benjamin\Documents\Visual Studio 2010\Projects\FCX Social Server\SocialServer Core\Server.obj SocialServer Core
However , these 2 missing function are correctly implemented :
Client.h
#pragma once
#include "dll.h"
namespace SocialServer
{
class __social_class Client
{
public:
Client(SOCKET sock);
~Client();
void Handle();
private:
static unsigned __stdcall clientThread(void* value);
SOCKET _socket;
uintptr_t _thread;
unsigned int _thread_id;
};
}
Client.cpp
#pragma once
#include "Client.h"
namespace SocialServer
{
Client::Client(SOCKET socket)
{
this->_socket = socket;
}
Client::~Client()
{
}
void Client::Handle()
{
std::cout << " New client " << std::endl;
this->_thread = _beginthreadex(NULL, 0, Client::clientThread, &this->_socket, CREATE_SUSPENDED, &this->_thread_id);
ResumeThread((HANDLE)this->_thread);
}
unsigned __stdcall Client::clientThread(void* value)
{
// Some code to execute here ...
}
}
Where does the problem comes from ?
i've found the solution.
In a function that's used by _beginthreadex() (with unsigned __stdcall) , always add a return at the end.