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 :(
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've been struggling to find why my linker gets an unresolved external symbol error. The error looks like this:
Error
LNK2019
unresolved external symbol "public: __thiscall Shader::Shader(char const *)" (??0Shader##QAE#PBD#Z) referenced in function "public: __thiscall GridWorldGPGPU::GridWorldGPGPU(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,unsigned int)" (??0GridWorldGPGPU##QAE#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##I#Z)
DV2556_Project
grid_world_GPGPU.obj
1
As far as I understand it it has something to do with that my linker finds the declaration of the Shader::Shader(char const *)-function but cannot find the definition. I have been staring at this for hours and cannot figure out why the linker becomes sad.
grid_world_GPGPU.h:
#ifndef GRID_WORLD_GPGPU_H
#define GRID_WORLD_GPGPU_H
#include "grid_world.h"
#include <../swift_open_gl.h>
class GridWorldGPGPU : public GridWorld {
private:
Shader* compute_shader_ = nullptr;
public:
GridWorldGPGPU(std::string in_path_shader, unsigned int in_side = 1);
};
#endif // !GRID_WORLD_GPGPU_H
grid_world_GPGPU.cpp:
GridWorldGPGPU::GridWorldGPGPU(std::string in_path_shader, unsigned int in_side)
: GridWorld(in_side) {
this->compute_shader_ = new Shader(in_path_shader.c_str());
}
The Shader-class is defined in the swift_open_gl.h file:
#ifndef SWIFT_OPEN_GL_H
#define SWIFT_OPEN_GL_H
#include <glad/glad.h>
#include <GLFW/glfw3.h>
class Shader {
public:
Shader(const char* cs_path);
};
#endif // !SWIFT_OPEN_GL_H
And swift_open_gl.cpp has this:
#include "..\swift_open_gl.h"
inline Shader::Shader(const char * cs_path) {
//Do stuff
}
I've tried with and without the inline (Visual Studio added it when I tried moving the function definition between the .h-file and a .cpp-file, so I decided to try it) and i have verified that the #include <../swift_open_gl.h> doesn't occur anywhere else in the project than the files listed above.
An extra set of eyes to look over this would be appreciated!
Provide default constructor of the class as well.
class Shader {
public:
Shader(){} // default constructor
Shader(const char* cs_path);
};
Dont use inline in Shader::Shader(const char* cs_path){} definition
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..
I'm have some problems with compiling my new project.
Compiler outputs:
1>------ Build started: Project: IRPCore, Configuration: Debug Win32 ------
1> core.cpp
1> Creating library D:\Repo\Inter Role Play Gamemode\sa-mp-0.2-plugin-sdk\IRP\Debug\IRPCore.lib and object D:\Repo\Inter Role Play Gamemode\sa-mp-0.2-plugin-sdk\IRP\Debug\IRPCore.exp
1>core.obj : error LNK2001: unresolved external symbol "public: static class std::tr1::unordered_map<int,struct item,class std::hash<int>,struct std::equal_to<int>,class std::allocator<struct std::pair<int const ,struct item> > > core::itemCache" (?itemCache#core##2V?$unordered_map#HUitem##V?$hash#H#std##U?$equal_to#H#3#V?$allocator#U?$pair#$$CBHUitem###std###3##tr1#std##A)
1>main.obj : error LNK2001: unresolved external symbol "public: static class std::tr1::unordered_map<int,struct item,class std::hash<int>,struct std::equal_to<int>,class std::allocator<struct std::pair<int const ,struct item> > > core::itemCache" (?itemCache#core##2V?$unordered_map#HUitem##V?$hash#H#std##U?$equal_to#H#3#V?$allocator#U?$pair#$$CBHUitem###std###3##tr1#std##A)
1>D:\Repo\Inter Role Play Gamemode\sa-mp-0.2-plugin-sdk\IRP\Debug\IRPCore.dll : fatal error LNK1120: 1 unresolved externals
Here comes core.cpp
#include <iostream>
#include <unordered_map>
#include "core.h"
core::core(void)
{
}
core::~core(void)
{
}
void core::Item_Insert(int uid, item Item)
{
core::itemCache.insert(std::make_pair<int,item>(uid, Item));
return;
}
std::string core::convertNativeStringToString(AMX *amx, cell input)
{
char *string = NULL;
amx_StrParam(amx, input, string);
return string ? string : "";
}
Should I link some more libs or so?
Thanks in advance.
Edit: Here comes core definition from core.h
class core
{
public:
static std::unordered_map<int, item> itemCache;
core(void);
~core(void);
static void Item_Insert(int uid, item Item);
static std::string convertNativeStringToString(AMX *amx, cell input);
private:
};
Add a definition of core::itemCache to core.cpp. In general, static data members of classes are declared in the class definition and defined in a source file.
As #Pete Becker is saying, put this at the top of the cpp:
std::unordered_map<int, item> core::itemCache;
in addition to the
static std::unordered_map<int, item> itemCache;
already in the .h.
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.