Building and Linking V8 in Visual Studio - c++

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.

Related

Unresolved external symbol ATL::IAtlMemMgr after upgrading to Visual Studio 2019

I am currently upgrading our source code from VS2012 to VS2019. One project which uses MFC does not link successfully:
fatal error LNK1120: 4 unresolved externals
error LNK2001: unresolved external symbol "public: void * __cdecl ATL::IAtlMemMgr::Allocate(unsigned __int64)" referenced in function "public: virtual struct ATL::CStringData * __cdecl ATL::CAtlStringMgr::Allocate(int,int)"
error LNK2001: unresolved external symbol "public: void __cdecl ATL::IAtlMemMgr::Free(void *)" referenced in function "public: virtual void __cdecl ATL::CAtlStringMgr::Free(struct ATL::CStringData *)"
error LNK2001: unresolved external symbol "public: void * __cdecl ATL::IAtlMemMgr::Reallocate(void *,unsigned __int64)" referenced in function "public: virtual struct ATL::CStringData * __cdecl ATL::CAtlStringMgr::Reallocate(struct ATL::CStringData *,int,int)"
error LNK2001: unresolved external symbol "public: virtual struct ATL::CStringData * __cdecl ATL::IAtlStringMgr::Reallocate(struct ATL::CStringData *,int,int)"
We are building with Multi-Byte Character Set (MBCS). My first thought was, that we are missing the the mbcs libraries. But as mentioned here, the libraries are installed by default, "when you select MFC and ATL support".
I added atlbase.h in the code and added atls.lib manually as additional dependency, but that did not solve the problem.
How can I figure out which library is missing?
Edit 1:
Let's take a look into atlmem.h:
__interface __declspec(uuid("654F7EF5-CFDF-4df9-A450-6C6A13C622C0")) IAtlMemMgr{
public:
_Ret_maybenull_ _Post_writable_byte_size_(nBytes) void* Allocate(_In_ size_t nBytes) throw();
As far as I see, this is one of the symbols which is not found. As can be red about the __interface keyword, it implicitly makes the functions pure virtual. These kind of linker errors might be caused by non pure virtual function declarations.
Might there be a bug which makes the functions in the __interface not pure virtual?
After excluding nearly all source files and commenting out a lot of functionality, I could see that the linker errors are correlated to <afxwin.h>. Moving <afxwin.h> to the top of each source files removed the linker errors.
However, I am interested to know why compiling with VS2012 gives another behavior compared to VS2019.

XDispatch C++ Unresolved Externals

I'm work with GCD in C++ with xdisptach, libdispatch in Visual Studio 2012 on Windows 7.
I am declaring a class with a global variable that is a dispatch queue. Other functions in the class call the queue's function. Everything compiles fine, except when i instantiate the queue in the constructor.
xdispatch::queue* dispatch_queue;
AsyncNode()
{
dispatch_queue = new xdispatch::queue(Name);
}
When dispatch_queue = new xdispatch::queue(Name); is commented out, it all compiles fine. Otherwise i get the following errors.
Error 50 error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall xdispatch::queue::~queue(void)" (__imp_??1queue#xdispatch##UAE#XZ) referenced in function "public: virtual void * __thiscall xdispatch::queue::`scalar deleting destructor'(unsigned int)" (??_Gqueue#xdispatch##UAEPAXI#Z)
Error 49 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall xdispatch::queue::queue(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0queue#xdispatch##QAE#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function "public: __thiscall AsyncNode::AsyncNode(void)" (??0AsyncNode##QAE#XZ)
Error 53 error LNK2001: unresolved external symbol "public: virtual void __thiscall xdispatch::object::resume(void)" (?resume#object#xdispatch##UAEXXZ)
Error 51 error LNK2001: unresolved external symbol "public: virtual void * __thiscall xdispatch::queue::native(void)const " (?native#queue#xdispatch##UBEPAXXZ)
Error 52 error LNK2001: unresolved external symbol "public: virtual struct dispatch_queue_s * __thiscall xdispatch::queue::native_queue(void)const " (?native_queue#queue#xdispatch##UBEPAUdispatch_queue_s##XZ)
This is the main site for xdispatch, but i can't find anything in terms of a forum or help with xdispatch in particular. There are many for objective-c.... :/
http://opensource.mlba-team.de/xdispatch/docs/current/index.html
First of all, the behavior regarding deleting the "problematic" line is normal - when you're defining a pointer you're not invoking any function, and that is the reason you are not getting the "unresolved external errors".
When you're initializing the variable by calling the constructor, you then run into problems because you're trying to call a function which is not available at link time.
When working with external libraries using DLLs, you must link to the appropriate import libraries, usually supplied as "lib" files. In your case, there is a folder named "lib" in the zip package. Also, the DLLs must availble at run-time - by putting them in the folder of the executable, or adding them to the PATH environment variable.
In order to link to a library, follow these steps (taken from MSDN):
Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.
Click the Linker folder.
Click the Input property page.
Modify the Additional Dependencies property.

Strange LNK2001 linker error

Yesterday I got this linker error. I have searched on google and msdn without success.
My problem:
I have moved some parts of my cpp project in a extern static library. I added the h file to my main project and added the dependencies to the lib files. Unfortunately I get a lot linker errors.
1>Compressor.obj : error LNK2001: unresolved external symbol "public: bool __thiscall NWindows::NFile::NFind::CFileInfo::Find(unsigned short const *)" (?Find#CFileInfo#NFind#NFile#NWindows##QAE_NPBG#Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "public: class NWindows::NCOM::CPropVariant & __thiscall NWindows::NCOM::CPropVariant::operator=(unsigned short const *)" (??4CPropVariant#NCOM#NWindows##QAEAAV012#PBG#Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "public: bool __thiscall CInFileStream::Open(unsigned short const *)" (?Open#CInFileStream##QAE_NPBG#Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "public: bool __thiscall NWindows::NFile::NIO::COutFile::Create(unsigned short const *,bool)" (?Create#COutFile#NIO#NFile#NWindows##QAE_NPBG_N#Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "void __cdecl ConvertUInt32ToString(unsigned int,unsigned short *)" (?ConvertUInt32ToString##YAXIPAG#Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "public: bool __thiscall NWindows::NDLL::CLibrary::Load(unsigned short const *)" (?Load#CLibrary#NDLL#NWindows##QAE_NPBG#Z)
All this methods a part of my extern lib. I have tries a lot of compiler settings without success.
Further more when I remove the lib dependencie completely from the linker I get 26 LNK2001 error. So the linker finds only "parts" of the lib.
Do I use a wrong compiler / linker option for my projects?
edit:
The problem was the parameter define LPCTSTR of the method CLibrary::Load(LPCTSTR fileName). In my lib I set the option "Treat wchar_t as build-in type (Properties->C/C++->Lanuage-> ... ) to No. And now it works.
There's not enough information in the question so my answer merely serves as a guide.
Take one function, for instance bool NWindows::NFile::NFind::CFileInfo::Find(unsigned short const *) and find definition of it in your code. Is it there? With this exact function signature? Is it in unnamed namespace? Is it declared static in source file?
Also, try full rebuild of everything. You'd be surprised how many times full rebuild makes mysterious problems go away.

Linker generates LNK2001 (( try to make unmanaged c++ dll in vs 2010

Error 10 error LNK2001: unresolved external symbol "public: virtual void __thiscall MPPostProcess::prepareForProcess(void)" (?prepareForProcess#MPPostProcess##UAEXXZ) D:\Prj\MagicLib\MagicLib\dllmain.obj MagicLib
Error 11 error LNK2001: unresolved external symbol "public: virtual void __thiscall MPPostProcess::prepareForProcess(void)" (?prepareForProcess#MPPostProcess##UAEXXZ) D:\Prj\MagicLib\MagicLib\MPImageData.obj MagicLib
Error 12 error LNK2019: unresolved external symbol "private: virtual __thiscall PPBlackAndWhite::~PPBlackAndWhite(void)" (??1PPBlackAndWhite##EAE#XZ) referenced in function "private: virtual void * __thiscall PPBlackAndWhite::`scalar deleting destructor'(unsigned int)" (??_GPPBlackAndWhite##EAEPAXI#Z) D:\Prj\MagicLib\MagicLib\dllmain.obj MagicLib
How to cure this?
There are 2 likely candidates for unresolved external errors:
If you defined the MPPostProcess class, then you have probably forgot to provide an implementation for the prepareForProcess(void) and ~PPBlackAndWhite(void) functions.
If the MPPostProcess class is a class you are using provided by an external library, then you need to link to the library that provides those functions
You probably haven't provided definitions for prepareForProcess() or ~PPBlackAndWhite().

Bullet Physics Engine static library installation issues

hey so i just downloaded bullet 2.78, and took the following steps:
unziped and found this tutorial
followed the steps exactly for Cmake, except i found the pictures in the tutorial had some things checked like INSTALL LIBS and i didn't so I ended up checking EVERYTHING possible.
Went into the newly generated BULLET_PHYSICS.vcxproj and built it under debug and release
Saw i had a bunch of new libs in the lib folder in msvn/BulletBuild/lib but did nothing with them
Followed the rest of the steps in the tutorial exactly for setting up the actual project
Tried to build the last line of code: FAIL
Wondered Do i NEED the dlls, because only .libs and pdbs showed up in the lib folder, and the tutorial didn't mention em
My only experience in rebuilding libraries is through SFML by building its msvn files included in the download and using the resulting dynamic lib and dll files. The instructions in the tutorial are very different however. (If someone could explain to me how this works it would be GREAT)
I followed the instructions exactly, multiple times but i'm not sure what i'm missing. The build works if i comment out the line of code in main but keep the include, but when i keep it i get this:
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "void * __cdecl btAlignedAllocInternal(unsigned int,int)" (?btAlignedAllocInternal##YAPAXIH#Z)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "void __cdecl btAlignedFreeInternal(void *)" (?btAlignedFreeInternal##YAXPAX#Z)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall btConvexInternalShape::getAabbSlow(class btTransform const &,class btVector3 &,class btVector3 &)const " (?getAabbSlow#btConvexInternalShape##UBEXABVbtTransform##AAVbtVector3##1#Z)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual char const * __thiscall btCollisionShape::serialize(void *,class btSerializer *)const " (?serialize#btCollisionShape##UBEPBDPAXPAVbtSerializer###Z)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: __thiscall btPolyhedralConvexShape::btPolyhedralConvexShape(void)" (??0btPolyhedralConvexShape##QAE#XZ)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall btPolyhedralConvexShape::~btPolyhedralConvexShape(void)" (??1btPolyhedralConvexShape##UAE#XZ)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall btConvexInternalShape::setLocalScaling(class btVector3 const &)" (?setLocalScaling#btConvexInternalShape##UAEXABVbtVector3###Z)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall btCollisionShape::getBoundingSphere(class btVector3 &,float &)const " (?getBoundingSphere#btCollisionShape##UBEXAAVbtVector3##AAM#Z)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual float __thiscall btCollisionShape::getAngularMotionDisc(void)const " (?getAngularMotionDisc#btCollisionShape##UBEMXZ)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual float __thiscall btCollisionShape::getContactBreakingThreshold(float)const " (?getContactBreakingThreshold#btCollisionShape##UBEMM#Z)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall btCollisionShape::serializeSingleShape(class btSerializer *)const " (?serializeSingleShape#btCollisionShape##UBEXPAVbtSerializer###Z)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall btBoxShape::getAabb(class btTransform const &,class btVector3 &,class btVector3 &)const " (?getAabb#btBoxShape##UBEXABVbtTransform##AAVbtVector3##1#Z)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall btBoxShape::calculateLocalInertia(float,class btVector3 &)const " (?calculateLocalInertia#btBoxShape##UBEXMAAVbtVector3###Z)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall btPolyhedralConvexShape::initializePolyhedralFeatures(void)" (?initializePolyhedralFeatures#btPolyhedralConvexShape##UAE_NXZ)
1>C:\Libraries and Headers\Bullet\bullet-2.78\msvc\BulletTestApp\Release\BulletTestApp.exe : fatal error LNK1120: 14 unresolved externals
I know there's a link problem somewhere but i followed the instructions exactly so i don't know how to fix it. I don't see any additional dependencies when looking at the properties of the added projects if that's not how it's supposed to be... but I guess i don't understand this method of using a library in the first place though so that knowledge would help.
Alright, so apparently right clicking my TestBulletApp project and clicking 'Project Dependencies' was where i went wrong. msVS++ 2010 left the option there for some reason even though it
doesn't work to do it that way.
Instead to make the project dependent on the other projects in the solution you have to right click on your project like my "TestBulletApp" and go to Properties->Common Properties->Framework and References->Add New Reference" and add the depended on static library projects already added to the sollution such as 'bulletCollision' or whatever; also check that "Link Library Dependencies" is True on the right hand side.
So yeah thanks for the heads up guys..... 'cough' 'cough' =)