[英]“Hello World” + JS V8 + VS2010
I downloaded and built JS V8 for using in VS2010 in Release mode. 我下载并构建了JS V8,以便在发布模式下在VS2010中使用。 Now I try run Hello World example :
现在我尝试运行Hello World示例 :
#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: 当我设置“忽略所有默认库:是(/ NODEFAULTLIB)”时,出现以下错误:
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? 有没有人试图运行这个例子或知道如何解决这些错误?
The error is caused by the missing symbol __imp__inet_addr@4
, which is located in Ws2_32.lib
. 该错误是由缺少的符号
__imp__inet_addr@4
引起的,该符号位于Ws2_32.lib
。
Go to project Properties -> Linker -> Input -> Additional Dependencies. 转到项目属性 - >链接器 - >输入 - >其他依赖项。 Simply add
Ws2_32.lib
and you're done. 只需添加
Ws2_32.lib
。
I had to include the following libraries: v8_base.lib;v8_snapshot.lib;ws2_32.lib;winmm.lib
我必须包含以下库:
v8_base.lib;v8_snapshot.lib;ws2_32.lib;winmm.lib
DO NOT DEFINE /NODEFAULTLIB:LIBCMT
this caused my build to fail. 不要定义
/NODEFAULTLIB:LIBCMT
这导致我的构建失败。
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. 如果你对我如何发现感到好奇,我会查看由GYP生成的ALL.sln并检查
shell
目标。 It's an executable that has to link with v8_base at some point, so it has the required Linker options. 它是一个可执行文件,必须在某些时候与v8_base链接,因此它具有所需的链接器选项。 It was a bit difficult to find, however.
然而,它有点难以找到。
how about /NODEFAULTLIB:LIBCMT
, to exclude only this single library? 怎么样
/NODEFAULTLIB:LIBCMT
,只排除这个单独的库? also I believe you need to link v8_snapshot.lib or v8_nosnapshot.lib or you build shared library and link to v8.lib 另外我相信您需要链接v8_snapshot.lib或v8_nosnapshot.lib,或者您构建共享库并链接到v8.lib
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.