我想在另一个Visual Studio C++项目中使用V8库。这不是我的日常生活环境,所以我可能会错过一些明显的东西。如何链接所需的库在Visual Studio C++项目中使用谷歌V8
我认为我所做的一切,因为它是在这里指出:
https://code.google.com/p/v8/wiki/BuildingWithGYP
即
签出以下回购:
svn co http://src.chromium.org/svn/trunk/tools/third_party/python_26 third_party/python_26 --revision 89111
svn co http://src.chromium.org/svn/trunk/deps/third_party/cygwin third_party/cygwin --revision 66844
svn co https://src.chromium.org/chrome/trunk/deps/third_party/icu52 third_party/icu --revision 277999
svn co http://googletest.googlecode.com/svn/trunk testing/gtest --revision 643
svn co http://googlemock.googlecode.com/svn/trunk testing/gmock --revision 410
从V8项目在CMD窗口中的根
然后我跑了:
python build\gyp_v8 -Dcomponent=static_library -Dtarget_arch=x64 -Dv8_enable_i18n_support=0 -Dv8_use_snapshot=0
...得到了:
Updating projects from gyp files...
Warning: Missing input files:
C:\...\v8\tools\gyp\..\..\src\uri.h
C:\...\v8\tools\gyp\..\..\src\feedback-slots.h
Running build/landmines.py...
接下来,我跑:
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.com" /build Release build\All.sln
...并得到了:
(...)
19>------ Build started: Project: All, Configuration: Release x64 ------
========== Build: 18 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
从我得到了我认为失败的一个测试项目中的错误:
…18>C:\...\v8\testing\gtest\include\gtest/internal/
gtest-param-util.h(393): error C2868: 'testing::internal::TestMetaFactory<v8::in
ternal::compiler::MachineStoreOperatorTest_ParameterIsCorrect_Test>::ParamType'
: illegal syntax for using-declaration; expected qualified-name (compiler\machin
e-operator-unittest.cc)…
之后,我在Visual Studio中创建了新的C++ Empty项目。添加一个文件到源文件节点此示例内容:
#include <include\v8.h>
#include <include\libplatform\libplatform.h>
using namespace v8;
Local<Array> NewPointArray(int x, int y, int z) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
// We will be creating temporary handles so we use a handle scope.
EscapableHandleScope handle_scope(isolate);
// Create a new empty array.
Local<Array> array = Array::New(isolate, 3);
// Return an empty result if there was an error creating the array.
if (array.IsEmpty())
return Local<Array>();
// Fill out the values
array->Set(0, Integer::New(isolate, x));
array->Set(1, Integer::New(isolate, y));
array->Set(2, Integer::New(isolate, z));
// Return the value through Escape.
return handle_scope.Escape(array);
}
int main(){}
我添加的路径到我的C/C++早期检出的V8项目的根文件夹 - >常规 - >附加包含目录属性(而不是Visual Studio项目,因为那里没有v8头文件)。
我还在链接器 - >常规 - >其他库目录属性中添加了来自同一个v8项目的build \ Release \ lib文件夹的路径。该文件夹包含以下内容:
gmock.lib
gtest.lib
v8_base.lib
v8_libbase.lib
v8_libplatform.lib
v8_nosnapshot.lib
接下来应该做什么。
当我尝试生成项目在Visual Studio我得到:
1>------ Build started: Project: SOProject, Configuration: Debug Win32 ------
1>Source.obj : error LNK2019: unresolved external symbol "public: __thiscall v8::HandleScope::~HandleScope(void)" ([email protected]@@[email protected]) referenced in function "public: __thiscall v8::EscapableHandleScope::~EscapableHandleScope(void)" ([email protected]@@[email protected])
1>Source.obj : error LNK2019: unresolved external symbol "public: __thiscall v8::EscapableHandleScope::EscapableHandleScope(class v8::Isolate *)" ([email protected]@@[email protected]@[email protected]@Z) referenced in function "class v8::Local<class v8::Array> __cdecl NewPointArray(int,int,int)" ([email protected]@[email protected]@[email protected]@@[email protected]@[email protected])
1>Source.obj : error LNK2019: unresolved external symbol "private: class v8::internal::Object * * __thiscall v8::EscapableHandleScope::Escape(class v8::internal::Object * *)" ([email protected]@[email protected]@[email protected]@[email protected]@@Z) referenced in function "public: class v8::Local<class v8::Array> __thiscall v8::EscapableHandleScope::Escape<class v8::Array>(class v8::Local<class v8::Array>)" ([email protected]@[email protected]@@[email protected]@@[email protected]@[email protected]@@[email protected]@@Z)
1>Source.obj : error LNK2019: unresolved external symbol "public: static class v8::Local<class v8::Integer> __cdecl v8::Integer::New(class v8::Isolate *,int)" ([email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@[email protected]@Z) referenced in function "class v8::Local<class v8::Array> __cdecl NewPointArray(int,int,int)" ([email protected]@[email protected]@[email protected]@@[email protected]@[email protected])
1>Source.obj : error LNK2019: unresolved external symbol "public: bool __thiscall v8::Object::Set(unsigned int,class v8::Handle<class v8::Value>)" ([email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@Z) referenced in function "class v8::Local<class v8::Array> __cdecl NewPointArray(int,int,int)" ([email protected]@[email protected]@[email protected]@@[email protected]@[email protected])
1>Source.obj : error LNK2019: unresolved external symbol "public: static class v8::Local<class v8::Array> __cdecl v8::Array::New(class v8::Isolate *,int)" ([email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@[email protected]@Z) referenced in function "class v8::Local<class v8::Array> __cdecl NewPointArray(int,int,int)" ([email protected]@YA?AV?$L[email protected]@[email protected]@@[email protected]@[email protected])
1>Source.obj : error LNK2019: unresolved external symbol "public: static class v8::Isolate * __cdecl v8::Isolate::GetCurrent(void)" ([email protected]@[email protected]@[email protected]) referenced in function "class v8::Local<class v8::Array> __cdecl NewPointArray(int,int,int)" ([email protected]@[email protected]@[email protected]@@[email protected]@[email protected])
1>D:\PROGRAMMING\!VisualStudioProjects\SOProject\Debug\SOProject.exe : fatal error LNK1120: 7 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
我应该怎么读呢?从其他职位,如:
How to compile the smallest possible V8 library for Windows?
https://groups.google.com/forum/#!topic/v8-users/KhniGgixxGM
Embedding v8 with Visual C++ 2010
...我得到我需要另一个链接库。
究竟是哪些,为什么这些以及如何在Visual Studio中完全链接它们。当然,我尝试了不同的组合和解决方案,但没有任何积极的结果
在此先感谢。
目标平台,调试级别和代码生成选项为您的项目应该与那些在图书馆指定,即它不是可以将“Release x64”库与“Debug Win32”二进制文件链接起来,可以构建x86库的调试版本或配置可执行文件的x64版本构建。还要检查项目和库中的“C/C++ - >代码生成 - >运行时库”选项,它也必须匹配(默认情况下,它是多版本DLL,可能应该更改为多线程) – dewaffled 2014-10-26 21:21:15