Trouble using v8 in new empty console project in VS2012

540 views
Skip to first unread message

Petar Avarić

unread,
May 25, 2014, 5:13:18 PM5/25/14
to v8-u...@googlegroups.com
Greetings everyone!

I'm new to v8 and I'm having a little bit of trouble with unresolved external symbols when building
the HelloWorld example (found here: https://developers.google.com/v8/get_started#intro) in Visual studio 2012

I'm going to go into detail here so that this discussion may help others who attempt to solve this problem.

I've followed the build instructions (found here: https://code.google.com/p/v8/wiki/BuildingWithGYP#Building) to the letter
and everything worked just fine as far as I can tell.
The last part involved opening v8\build\all.sln with Visual Studio 2012 and allowing the automatic conversion process
to update everything from VS2010 to VS2012.
I've made it rebuild in Release mode and all projects have been build successfully.
The Release\lib folder contained the following libs:
-icui18n.lib
-icuuc.lib
-v8_base.lib
-v8_nosnapshot.lib
-v8_snapshot.lib

I went and tried out v8\build\Release\shell.exe (which, to my knowledge, depends on v8) and it worked.

Next step, I started a New Project, console application (empty) and added the v8\include and v8\build\Release\lib folders in a new "v8" folder in my new project simply as include and lib
->pasted the HelloWorld code in main.cpp
->went to Project->Properties->VC++ Directories and added a path for Include Directories to point towards the v8\include folder and Library Directories to point towards v8\lib folder.

Intelisense stopped pointing out that I'm missing .h files so i figured everything was set up properly. I previously picked Release mode again and did a clean rebuild.
The following was printed on the Output:

1>------ Rebuild All started: Project: HelloWorld, Configuration: Release Win32 ------
1>  main.cpp
1>main.obj : error LNK2001: unresolved external symbol "public: void __thiscall v8::Context::Exit(void)" (?Exit@Context@v8@@QAEXXZ)
1>main.obj : error LNK2001: unresolved external symbol "public: void __thiscall v8::Context::Enter(void)" (?Enter@Context@v8@@QAEXXZ)
1>main.obj : error LNK2001: unresolved external symbol "public: static class v8::Local<class v8::Context> __cdecl v8::Context::New(class v8::Isolate *,class v8::ExtensionConfiguration *,class v8::Handle<class v8::ObjectTemplate>,class v8::Handle<class v8::Value>)" (?New@Context@v8@@SA?AV?$Local@VContext@v8@@@2@PAVIsolate@2@PAVExtensionConfiguration@2@V?$Handle@VObjectTemplate@v8@@@2@V?$Handle@VValue@v8@@@2@@Z)
1>main.obj : error LNK2001: unresolved external symbol "public: class v8::Local<class v8::Value> __thiscall v8::Script::Run(void)" (?Run@Script@v8@@QAE?AV?$Local@VValue@v8@@@2@XZ)
1>main.obj : error LNK2001: unresolved external symbol "public: static class v8::Local<class v8::Script> __cdecl v8::Script::Compile(class v8::Handle<class v8::String>,class v8::ScriptOrigin *)" (?Compile@Script@v8@@SA?AV?$Local@VScript@v8@@@2@V?$Handle@VString@v8@@@2@PAVScriptOrigin@2@@Z)
1>main.obj : error LNK2001: unresolved external symbol "public: __thiscall v8::String::Utf8Value::~Utf8Value(void)" (??1Utf8Value@String@v8@@QAE@XZ)
1>main.obj : error LNK2001: unresolved external symbol "public: __thiscall v8::String::Utf8Value::Utf8Value(class v8::Handle<class v8::Value>)" (??0Utf8Value@String@v8@@QAE@V?$Handle@VValue@v8@@@2@@Z)
1>main.obj : error LNK2001: unresolved external symbol "public: static class v8::Local<class v8::String> __cdecl v8::String::NewFromUtf8(class v8::Isolate *,char const *,enum v8::String::NewStringType,int)" (?NewFromUtf8@String@v8@@SA?AV?$Local@VString@v8@@@2@PAVIsolate@2@PBDW4NewStringType@12@H@Z)
1>main.obj : error LNK2001: unresolved external symbol "public: __thiscall v8::HandleScope::~HandleScope(void)" (??1HandleScope@v8@@QAE@XZ)
1>main.obj : error LNK2001: unresolved external symbol "public: __thiscall v8::HandleScope::HandleScope(class v8::Isolate *)" (??0HandleScope@v8@@QAE@PAVIsolate@1@@Z)
1>main.obj : error LNK2001: unresolved external symbol "public: static class v8::Isolate * __cdecl v8::Isolate::GetCurrent(void)" (?GetCurrent@Isolate@v8@@SAPAV12@XZ)
1>C:\Game_Development\V8Native\PozdravSvijete\HelloWorld\Release\HelloWorld.exe : fatal error LNK1120: 11 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Now this is my n'th attempt at this, I tried a whole bunch of other stuff in previous empty console projects that I wasn't sure about and it didn't help at all.
I started this one from scratch and stopped at this point hoping that someone could shed some light on this issue. :)

Flying Jester

unread,
May 27, 2014, 1:13:06 AM5/27/14
to v8-u...@googlegroups.com
It looks like you haven't linked V8 in.

Look at your build tools' documentation for how to link with a library/

Petar Avarić

unread,
May 27, 2014, 3:27:39 AM5/27/14
to v8-u...@googlegroups.com
You're right. I've used the wrong method. Instead of setting Library directories i had to:

go to project properties -> Configuration properties -> Linker.
go to ->General and set the "Additional Library directories" to point to my lib file directory.
then go to Linker -> Input and type in the lib file names in the "Additional Dependencies" field:
icui18n.lib
icuuc.lib
v8_base.lib
v8_nosnapshot.lib
v8_snapshot.lib

And it worked... sort of.

The new Output had less errors:
1>------ Rebuild All started: Project: HelloWorld, Configuration: Release Win32 ------
1>  main.cpp
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>v8_base.lib(platform-win32.obj) : error LNK2001: unresolved external symbol __imp__timeGetTime@0
1>v8_base.lib(time.obj) : error LNK2001: unresolved external symbol __imp__timeGetTime@0
1>C:\Game_Development\V8Native\PozdravSvijete\HelloWorld\Release\HelloWorld.exe : fatal error LNK1120: 1 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

I went on and searched for additional dependencies i might have missed and found this stackoverflow page: http://stackoverflow.com/questions/13117358/hello-world-js-v8-vs2010

But none of the suggestions seemed to help even though they go very well with the assumption that I had to add
ws2_32.lib
winmm.lib

and maybe even advapi32.lib

Since they can all be found in the all.sln. But I end up with another set of errors if I add them:
1>------ Rebuild All started: Project: HelloWorld, Configuration: Release Win32 ------
1>  main.cpp
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>  Generating code
1>  Finished generating code
1>LIBCMT.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" (?terminate@@YAXXZ) already defined in MSVCRT.lib(MSVCR110.dll)
1>LIBCMT.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in MSVCRT.lib(MSVCR110.dll)
1>LIBCMT.lib(mlock.obj) : error LNK2005: __lock already defined in MSVCRT.lib(MSVCR110.dll)
1>LIBCMT.lib(mlock.obj) : error LNK2005: __unlock already defined in MSVCRT.lib(MSVCR110.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __amsg_exit already defined in MSVCRT.lib(MSVCR110.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __cexit already defined in MSVCRT.lib(MSVCR110.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __exit already defined in MSVCRT.lib(MSVCR110.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: __initterm_e already defined in MSVCRT.lib(MSVCR110.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: _exit already defined in MSVCRT.lib(MSVCR110.dll)
1>LIBCMT.lib(winapisupp.obj) : error LNK2005: ___crtSetUnhandledExceptionFilter already defined in MSVCRT.lib(MSVCR110.dll)
1>LIBCMT.lib(winapisupp.obj) : error LNK2005: ___crtTerminateProcess already defined in MSVCRT.lib(MSVCR110.dll)
1>LIBCMT.lib(winapisupp.obj) : error LNK2005: ___crtUnhandledException already defined in MSVCRT.lib(MSVCR110.dll)
1>LIBCMT.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in MSVCRT.lib(MSVCR110.dll)
1>LIBCMT.lib(crtheap.obj) : error LNK2005: __calloc_crt already defined in MSVCRT.lib(MSVCR110.dll)
1>LIBCMT.lib(rand_s.obj) : error LNK2005: _rand_s already defined in MSVCRT.lib(MSVCR110.dll)
1>LIBCMT.lib(winsig.obj) : error LNK2005: _raise already defined in MSVCRT.lib(MSVCR110.dll)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in MSVCRT.lib(cinitexe.obj)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in MSVCRT.lib(cinitexe.obj)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in MSVCRT.lib(cinitexe.obj)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in MSVCRT.lib(cinitexe.obj)
1>LIBCMT.lib(errmode.obj) : error LNK2005: ___set_app_type already defined in MSVCRT.lib(MSVCR110.dll)
1>LIBCMT.lib(fflush.obj) : error LNK2005: _fflush already defined in MSVCRT.lib(MSVCR110.dll)
1>LIBCMT.lib(_file.obj) : error LNK2005: ___iob_func already defined in MSVCRT.lib(MSVCR110.dll)
1>LIBCMT.lib(wsetloca.obj) : error LNK2005: __configthreadlocale already defined in MSVCRT.lib(MSVCR110.dll)
1>LIBCMT.lib(strtol.obj) : error LNK2005: _strtol already defined in MSVCRT.lib(MSVCR110.dll)
1>MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
1>MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
1>C:\Game_Development\V8Native\PozdravSvijete\HelloWorld\Release\HelloWorld.exe : fatal error LNK1169: one or more multiply defined symbols found
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

Suffice to say I'm not sure what it all means. I'll definatelly keep looking as I'm sure im not far from the solution but I'd gladly accept suggestions. 

Petar Avarić

unread,
May 27, 2014, 11:43:44 AM5/27/14
to v8-u...@googlegroups.com
Ok so the trick was to add LIBCMT.lib to the Linker's "Ignore Specific Default Libraries"

I also figured out ws2_32.lib and advapi32.lib aren't needed (at least it's not complaining about them)

And now we're down to what I believe might be the final set of errors:

1>------ Rebuild All started: Project: HelloWorld, Configuration: Release Win32 ------
1>  main.cpp
1>v8_base.lib(hydrogen-instructions.obj) : error LNK2001: unresolved external symbol __HUGE
1>v8_base.lib(heap.obj) : error LNK2001: unresolved external symbol __HUGE
1>v8_base.lib(conversions.obj) : error LNK2001: unresolved external symbol __HUGE
1>v8_base.lib(assembler.obj) : error LNK2001: unresolved external symbol __HUGE
1>v8_base.lib(strtod.obj) : error LNK2001: unresolved external symbol __HUGE
1>C:\Game_Development\V8Native\PozdravSvijete\HelloWorld\Release\HelloWorld.exe : fatal error LNK1120: 1 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

I've searched these forums for similar errors and it seems these aren't supposed to happen. The only person here to have solved it simply updated to the most recent version of V8 and the error disappeared.
Since I already have the most recent version (of everything) I'd really appreciate if someone could explain how to fix this.

Flying Jester

unread,
May 27, 2014, 10:36:24 PM5/27/14
to v8-u...@googlegroups.com
Looking at my build (which specifically uses V8 as a shared library and lacks il8n support):
The old WinSock library no longer needs to be expressly linked to the final executable. I also haven't got v8_base linking in either, just v8.lib.

It might be useful to just start a new project file, knowing what you do now (linking with V8 only, only linking with a single standard library--LIBCMT.lib or MSVCRT.lib).
Reply all
Reply to author
Forward
0 new messages