5

I downloaded and built JS V8 for using in VS2010 in Release mode. Now I try run Hello World example:

#include "v8.h"

int _tmain(int argc, _TCHAR* argv[])
{
    v8::HandleScope handle_scope;

    v8::Persistent<v8::Context> context = v8::Context::New();

    v8::Context::Scope context_scope(context);

    v8::Handle<v8::String> source = v8::String::New("'Hello' + ', World'");

    v8::Handle<v8::Script> script = v8::Script::Compile(source);

    v8::Handle<v8::Value> result = script->Run();

    context.Dispose();

    v8::String::AsciiValue ascii (result);

    printf ("%s\n", *ascii);

    return 0;
}

I added Additional Dependencies:

"C:\v8\build\Release\lib\preparser_lib.lib"
"C:\v8\build\Release\lib\v8_base.lib"

When I try to compile and run the program, I encountered a linking error:

1>------ Build started: Project: V8_example, Configuration: Release Win32 ------
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__inet_addr@4
...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

When I have set "Ignore All Default Libraries: Yes(/NODEFAULTLIB)", these errors showed up:

1>------ Build started: Project: V8_example, Configuration: Release Win32 ------
1>v8_base.lib(strtod.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
1>v8_base.lib(full-codegen-ia32.obj) : error LNK2001: unresolved external symbol @__security_check_cookie@4
...
1>c:\users\admin\documents\visual studio 2010\Projects\V8_example\Release\V8_example.exe : fatal error LNK1120: 141 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Has anyone tried to run this example or know how to fix these errors?

ajp15243
  • 7,704
  • 1
  • 32
  • 38
ibn_maksimys
  • 119
  • 1
  • 1
  • 5

3 Answers3

1

The error is caused by the missing symbol __imp__inet_addr@4, which is located in Ws2_32.lib.

Go to project Properties -> Linker -> Input -> Additional Dependencies. Simply add Ws2_32.lib and you're done.

Jonas Byström
  • 25,316
  • 23
  • 100
  • 147
  • The number of errors reduced under 28: 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 : error LNK2001: unresolved external symbol "private: static int const v8::internal::Snapshot::cell_space_used_" (?cell_space_used_@Snapshot@internal@v8@@0HB)... – ibn_maksimys Oct 29 '12 at 08:48
1

I had to include the following libraries: v8_base.lib;v8_snapshot.lib;ws2_32.lib;winmm.lib

DO NOT DEFINE /NODEFAULTLIB:LIBCMT this caused my build to fail.

If you're curious as to how I found out, I looked under the ALL.sln that is generated by GYP and checked the shell target. It's an executable that has to link with v8_base at some point, so it has the required Linker options. It was a bit difficult to find, however.

TReed0803
  • 585
  • 3
  • 9
0

how about /NODEFAULTLIB:LIBCMT, to exclude only this single library? also I believe you need to link v8_snapshot.lib or v8_nosnapshot.lib or you build shared library and link to v8.lib

exebook
  • 32,014
  • 33
  • 141
  • 226