Hey!
I have been trying to add MongoDB libraries to my project. I followed the tutorial here. It compiles fine untill I start using the hpp files, creating instances of classes. Then I get the following output:
CompilerResultsLog: Info [3/3] Link UE4Editor-MongoDBTest-4863.dll
CompilerResultsLog: Info Creating library F:\Skole\UnrealTest\MongoDBTest\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-MongoDBTest-4863.lib and object F:\Skole\UnrealTest\MongoDBTest\Intermediate\Build\Win64\UE4Editor\Development\UE4Editor-MongoDBTest-4863.exp
CompilerResultsLog:Error: Error MongoDBConnectTest.cpp.obj : error LNK2019: unresolved external symbol “__declspec(dllimport) public: __cdecl mongocxx::v_noabi::instance::instance(void)” (_imp??0instance@v_noabi@mongocxx@@QEAA@XZ) referenced in function “public: virtual void __cdecl AMongoDBConnectTest::BeginPlay(void)” (?BeginPlay@AMongoDBConnectTest@@UEA AXXZ)
CompilerResultsLog:Error: Error MongoDBConnectTest.cpp.obj : error LNK2019: unresolved external symbol “__declspec(dllimport) public: __cdecl mongocxx::v_noabi::instance::~instance(void)” (_imp??1instance@v_noabi@mongocxx@@QEAA@XZ) referenced in function “public: virtual void __cdecl AMongoDBConnectTest::BeginPlay(void)” (?BeginPlay@AMongoDBConnectTest@@anonymous_user_40a38184 AAXXZ)
CompilerResultsLog:Error: Error F:\Skole\UnrealTest\MongoDBTest\Binaries\Win64\UE4Editor-MongoDBTest-4863.dll : fatal error LNK1120: 2 unresolved externals
CompilerResultsLog: Info ERROR: UBT ERROR: Failed to produce item: F:\Skole\UnrealTest\MongoDBTest\Binaries\Win64\UE4Editor-MongoDBTest-4863.dll
Anyone know what is going on? I have tried googling it and trying different things that seem to have worked for others.
The build.cs file:
using UnrealBuildTool;
using System.IO;
public class MongoDBTest : ModuleRules
{
private string ModulePath {
get { return ModuleDirectory; }
}
private string ThirdPartyPath {
get { return Path.GetFullPath(Path.Combine(ModulePath, "../../ThirdParty/")); }
}
public MongoDBTest(TargetInfo Target)
{
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
PrivateDependencyModuleNames.AddRange(new string[] { });
LoadMongoDB(Target);
}
public bool LoadMongoDB(TargetInfo Target) {
bool isLibrarySupported = false;
if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32)) {
isLibrarySupported = true;
string LibrariesPath = Path.Combine(ThirdPartyPath, "MongoDB", "Libraries");
// PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "libbsoncxx." + "lib"));
PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "libmongocxx." + "lib"));
}
if (isLibrarySupported) {
PublicIncludePaths.Add(Path.Combine(ThirdPartyPath, "MongoDB", "Includes"));
}
Definitions.Add(string.Format("WITH_MONGODB_BINDING={0}", isLibrarySupported ? 1 : 0));
return isLibrarySupported;
}
}
The header file of the class I use for testing:
#pragma once
#include "GameFramework/Actor.h"
#include "MongoDBConnectTest.generated.h"
UCLASS()
class MONGODBTEST_API AMongoDBConnectTest : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AMongoDBConnectTest();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
UFUNCTION()
void testConnection();
};
Here is the cpp file of the class:
#include "MongoDBTest.h"
#include "MongoDBConnectTest.h"
#include "mongocxx/instance.hpp"
// Sets default values
AMongoDBConnectTest::AMongoDBConnectTest()
{
}
void AMongoDBConnectTest::BeginPlay() {
testConnection();
Super::BeginPlay();
}
void AMongoDBConnectTest::testConnection() {
mongocxx::instance inst{};
}
When creating the library I followed this one and this one. In addition to having certain settings set:
- Platform: x64
- Runtime Library: Multi-threaded DLL (/MD)
- Configuration Type: Static Library (.lib)
I also have boost added in the Includes folder.