Using a Win32 DLL in a UWP App - linking issue - c++

I followed Using a Win32 DLL in a UWP App recipe, but I'm getting linking errors, like:
LNK2019 unresolved external symbol "public: int __cdecl Giraffe::GetID(void)" (?GetID#Giraffe##QEAAHXZ) referenced in function "public: void __cdecl winrt::WinUI3Lib::implementation...
Did anyone got it working?

Related

Visual Studio Build fails when using a class from another project

I am working on a C++ application and I cannot build it because of LNK2001 and LNK2019 errors.
It has 4 projects: Client, Depry, Miscellaneous and Server. I want to have a base exception class in Miscellaneous and to be able to inherit from it in the Client and Server projects.
I tried adding the "include" folder from the Miscellaneous project to the Client's Additional Dependencies and I also added Miscellanous to Client's project dependencies. It did not work.
Example Errors:
Error LNK2019 unresolved external symbol "public: virtual __cdecl DepryException::~DepryException(void)" (??1DepryException##UEAA#XZ) referenced in function "public: virtual void * __cdecl DepryException::`scalar deleting destructor'(unsigned int)" (??_GDepryException##UEAAPEAXI#Z) ChatClient E:\SEng\CPlusPlus\Depry\Client\ChatClient.obj 1
Error LNK2001 unresolved external symbol "public: virtual char const * __cdecl DepryException::what(void)const " (?what#DepryException##UEBAPEBDXZ) ChatClient E:\SEng\CPlusPlus\Depry\Client\ChatClient.obj 1

Building and Linking V8 in Visual Studio

I'm having a really hard time trying to figure out how to build Google's V8 on Windows.
So far I have:
Installed depot_tools
Fetched v8: fetch v8
Created the project files: gn gen --ide=vs2015 out/Default
Built the entire solution in VS2015
My issue is that this only produces a large number of .obj files and no .lib files.
I have set the projects (v8, v8_base, v8_libbase, etc.) to Configuration type: Static library (.lib):
I'm not sure how to get Visual Studio to generate the library files. Any help appreciated!
Update
I have managed to produce library files using the following steps:
Open VS Developer Command Line
Navigate to the directories containing obj files for v8_base, v8_libbase, v8_external_snapshot and v8_libplatform.
For each of these, build a .lib manually using the lib command e.g. lib /o:v8_base *.obj
Copy all these lib files into a directory along with icui18n.lib and icuuc.lib (these were created fine during the build.)
I'm now trying to actually use the libraries and have a new problem which I would appreciate help with.
I have linked the following libraries in VS: v8_base.lib; v8_libbase.lib; v8_external_snapshot.lib; v8_libplatform.lib; icui18n.lib; icuuc.lib; winmm.lib;, however I am having an issue with a few unresolved symbols:
unresolved external symbol "public: static void __cdecl v8::sampler::Sampler::TearDown(void)" (?TearDown#Sampler#sampler#v8##SAXXZ) referenced in function "public: static void __cdecl v8::internal::V8::TearDown(void)" (?TearDown#V8#internal#v8##SAXXZ) TriviaBot v8_base.lib(v8.obj)
unresolved external symbol "public: void __cdecl v8::sampler::Sampler::Stop(void)" (?Stop#Sampler#sampler#v8##QEAAXXZ) referenced in function "private: void __cdecl v8::internal::Isolate::Deinit(void)" (?Deinit#Isolate#internal#v8##AEAAXXZ) v8_base.lib(isolate.obj)
unresolved external symbol "public: void __cdecl v8::sampler::Sampler::Stop(void)" (?Stop#Sampler#sampler#v8##QEAAXXZ) v8_base.lib(log.obj)
unresolved external symbol "public: __cdecl v8::sampler::Sampler::Sampler(class v8::Isolate *)" (??0Sampler#sampler#v8##QEAA#PEAVIsolate#2##Z) referenced in function "public: __cdecl v8::internal::Ticker::Ticker(class v8::internal::Isolate *,int)" (??0Ticker#internal#v8##QEAA#PEAVIsolate#12#H#Z) v8_base.lib(log.obj)
unresolved external symbol "public: __cdecl v8::sampler::Sampler::Sampler(class v8::Isolate *)" (??0Sampler#sampler#v8##QEAA#PEAVIsolate#2##Z) v8_base.lib(cpu-profiler.obj)
unresolved external symbol "public: virtual __cdecl v8::sampler::Sampler::~Sampler(void)" (??1Sampler#sampler#v8##UEAA#XZ) referenced in function "public: virtual void * __cdecl v8::internal::Ticker::`scalar deleting destructor'(unsigned int)" (??_GTicker#internal#v8##UEAAPEAXI#Z)
unresolved external symbol "public: virtual __cdecl v8::sampler::Sampler::~Sampler(void)" (??1Sampler#sampler#v8##UEAA#XZ) v8_base.lib(cpu-profiler.obj)
unresolved external symbol "public: void __cdecl v8::sampler::Sampler::Start(void)" (?Start#Sampler#sampler#v8##QEAAXXZ) referenced in function "public: void __cdecl v8::internal::Profiler::Engage(void)" (?Engage#Profiler#internal#v8##QEAAXXZ) v8_base.lib(log.obj)
unresolved external symbol "public: void __cdecl v8::sampler::Sampler::IncreaseProfilingDepth(void)" (?IncreaseProfilingDepth#Sampler#sampler#v8##QEAAXXZ) referenced in function "public: void __cdecl v8::internal::Profiler::Engage(void)" (?Engage#Profiler#internal#v8##QEAAXXZ) v8_base.lib(log.obj)
unresolved external symbol "public: void __cdecl v8::sampler::Sampler::IncreaseProfilingDepth(void)" (?IncreaseProfilingDepth#Sampler#sampler#v8##QEAAXXZ) v8_base.lib(cpu-profiler.obj)
unresolved external symbol "public: void __cdecl v8::sampler::Sampler::DecreaseProfilingDepth(void)" (?DecreaseProfilingDepth#Sampler#sampler#v8##QEAAXXZ) referenced in function "public: void __cdecl v8::internal::Profiler::Disengage(void)" (?Disengage#Profiler#internal#v8##QEAAXXZ) v8_base.lib(log.obj)
unresolved external symbol "public: void __cdecl v8::sampler::Sampler::DecreaseProfilingDepth(void)" (?DecreaseProfilingDepth#Sampler#sampler#v8##QEAAXXZ) v8_base.lib(cpu-profiler.obj)
unresolved external symbol "public: void __cdecl v8::sampler::Sampler::DoSample(void)" (?DoSample#Sampler#sampler#v8##QEAAXXZ) referenced in function "public: virtual void __cdecl v8::internal::SamplingThread::Run(void)" (?Run#SamplingThread#internal#v8##UEAAXXZ) v8_base.lib(log.obj)
unresolved external symbol "public: void __cdecl v8::sampler::Sampler::DoSample(void)" (?DoSample#Sampler#sampler#v8##QEAAXXZ) v8_base.lib(cpu-profiler.obj)
unresolved external symbol "public: static void __cdecl v8::sampler::Sampler::SetUp(void)" (?SetUp#Sampler#sampler#v8##SAXXZ) referenced in function "private: static void __cdecl v8::internal::V8::InitializeOncePerProcessImpl(void)" (?InitializeOncePerProcessImpl#V8#internal#v8##CAXXZ) v8_base.lib(v8.obj)
All of the error seem to be related to v8::sampler - any help is again appreciated!
And it looks like I'm answering my own question again. I hope the info I listed in the question will be useful for anyone who struggles with the out-of-date documentation like me.
My update covers everything required except for the fact I didn't even notice the v8_libsampler project and forgot to generate the library file for it. Once I did that and linked it, I was up and running!
Just like you, I was trying different settings to get the lib building. And here are my steps:
After gn gen, run gn args out/Default, uncomment is_component_build, that's the equivalent of component=shared_library I guess.
While I also have problem building all.sln in vs.net I realized msbuild can give me some of the dll/lib files.
Good luck.
I have done similar config but for VS2013 and runned ninja to build everything. Build has produced me set of DLLs, including v8.dll, which I am completely fine with.

OpenCV - SURF functionality issue

I am trying to build an OpenCV program which uses SURF matching algorithm, the code is in the following link :
http://feelmare.blogspot.ro/2011/10/sift-matching-c-source-code-using.html
However, I am obtaining 2 errors regarding some external symbols : _cvExtractSurf and _cvSURFParams.
error LNK2019: unresolved external symbol _cvExtractSURF referenced in function "public: bool __thiscall CMareMatchingClass::ExtractBGsurf(struct _IplImage *)" (?ExtractBGsurf#CMareMatchingClass##QAE_NPAU_IplImage###Z)
error LNK2019: unresolved external symbol _cvSURFParams referenced in function "public: __thiscall CMareMatchingClass::CMareMatchingClass(void)" (??0CMareMatchingClass##QAE#XZ)
Do you know how can I solve this errors? I am running the code by using opencv 2.3.0 in visual studio 2010 in Windows 7 - 64 bit.
You didn't link a needed library - try to link all OpenCV libraries in project settings. See documentation.

Unresolved external

I am having difficulty figuring out my unresolved external errors.
I have 2 different solutions that both share a core project. Solution #1 is called SnapGame and Solution #2 is called SnapEditor. The core project is called SnapCore.
My SnapGame solution is a Win32 application. It compiles, references, and links the SnapCore project with no issues.
The SnapEditor solution is a Windows Forms Application. It compiles and references the SnapCore project. However, it will not link with it properly. I get unresolved external errors any time I try to reference anything from the SnapCore project.
The SnapCore project has some GDI+ support classes. All classes in the SnapCore project are under the SnapCore namespace.
Here is the file Form1.cpp:
#include "stdafx.h"
#include "App.h"
#include "Orient.h"
using namespace SnapCore;
using namespace SnapEdit;
void Form1::Init()
{
SnapCore::Orient orient;
new App();
}
Here are the linker errors I get:
1>Form1.obj : warning LNK4248: unresolved typeref token (01000049) for 'Gdiplus.GpCachedBitmap'; image may not run
1>Form1.obj : error LNK2028: unresolved token (0A000019) "public: __clrcall SnapCore::App::App(void)" (??0App#SnapCore##$$FQAM#XZ) referenced in function "public: void __clrcall SnapEdit::Form1::InitSnapCore(void)" (?InitSnapCore#Form1#SnapEdit##$$FQ$AAMXXZ)
1>Form1.obj : error LNK2028: unresolved token (0A00001A) "public: __clrcall SnapCore::Orient::Orient(void)" (??0Orient#SnapCore##$$FQAM#XZ) referenced in function "public: void __clrcall SnapEdit::Form1::InitSnapCore(void)" (?InitSnapCore#Form1#SnapEdit##$$FQ$AAMXXZ)
1>Form1.obj : error LNK2019: unresolved external symbol "public: __clrcall SnapCore::App::App(void)" (??0App#SnapCore##$$FQAM#XZ) referenced in function "public: void __clrcall SnapEdit::Form1::InitSnapCore(void)" (?InitSnapCore#Form1#SnapEdit##$$FQ$AAMXXZ)
1>Form1.obj : error LNK2019: unresolved external symbol "public: __clrcall SnapCore::Orient::Orient(void)" (??0Orient#SnapCore##$$FQAM#XZ) referenced in function "public: void __clrcall SnapEdit::Form1::InitSnapCore(void)" (?InitSnapCore#Form1#SnapEdit##$$FQ$AAMXXZ)
1>C:\Work\PC\SnapEdit\SnapEdit\Debug\SnapEdit.exe : fatal error LNK1120: 4 unresolved externals
I can't figure out why my SnapGame solution links with no troubles, but the SnapEditor solution will not.
Any help would be appreciated.
If I understand you right, SnapEditor is a managed application. It can't simply refer to a native library, like SnapCore. Use P/Invoke, or write a managed wrapper.

Linking Lua with Visual Studio 2010

We use Lua (www.lua.org) script to let users to customize our server software written in C++.
At the moment we are porting the 32 bits Windows version of our project to Visual Studio 2010.
Once everything works fine with VS 2008, we thought that we would have no problem on upgrade process.
Unfortunately whenever we tried to link the lualib (as dll) to our project in VS 2010, the lua functions could not be found by the linker (the error messages are displayed below).
It seems that some calling convention is wrong on 2010, like the application may be looking for the lua functions with a prefix '_'.
To access lua functions (written in C) from our project modules (C++) we use this:
extern "C" {
#include "lua/src/lua.h"
#include "lua/src/lualib.h"
#include "lua/src/lauxlib.h"
}
The same project compiles and links with lualib successfully on VS 2008 and Linux (g++).
Could anybody help me with this ?
1>dscscript.obj : error LNK2019: unresolved external symbol __imp__luaL_openlibs referenced in function "public: int __thiscall DsCScriptEngine::Init(void)" (?Init#DsCScriptEngine##QAEHXZ)
1>dscscript.obj : error LNK2019: unresolved external symbol __imp__luaL_newstate referenced in function "public: int __thiscall DsCScriptEngine::Init(void)" (?Init#DsCScriptEngine##QAEHXZ)
1>dscscript.obj : error LNK2019: unresolved external symbol __imp__lua_close referenced in function "public: void __thiscall DsCScriptEngine::Shutdown(void)" (?Shutdown#DsCScriptEngine##QAEXXZ)
1>dscscript.obj : error LNK2019: unresolved external symbol __imp__lua_pcall referenced in function "public: long __thiscall DsCScriptEngine::Execute(char const *)" (?Execute#DsCScriptEngine##QAEJPBD#Z)
etc.
The reported missing names are correct, this not a compile problem. You must be linking the wrong .lib. The name you use sounds wrong, it isn't "lualib", the current version of the import library is named lua5.1.lib (or lua51.lib, not sure what the difference is). Download it from here.