使用g++在Mac平台编译v8项目

    g++ -I ../v8/include main.cc -o out \
    -Wl, ../v8/out/x64.release/libv8_base.a \
    -Wl, ../v8/out/x64.release/libv8_libbase.a \
    -Wl, ../v8/out/x64.release/libv8_external_snapshot.a \
    -Wl, ../v8/out/x64.release/libv8_libplatform.a \
    -Wl, ../v8/out/x64.release/libicui18n.a \
    -Wl, ../v8/out/x64.release/libicudata.a \
    -Wl, ../v8/out/x64.release/libicuuc.a \
    -stdlib=libstdc++ \
    -std=c++0x

上面参数中的 -stdlib=libstdc++ 表示最新版的mac使用的是llvm编译器,其默认的标准库是libc++,但v8依赖的是libstdc++。

最新的v8使用的c++11的特性,使用-std=c++0x 去除c++11的warning。

另,v8项目依赖的几个静态库文件是编译成功后在v8的out目录下生成的。

并且在执行的时候,文件依赖几个*.bin文件

下面是官方原文

Run the Example

Follow the steps below to run the example yourself:

  1. Download the V8 source code and build V8 by following the download and build instructions.

    1. This hello world example is compatible with the version 4.8. You can check out this branch with git checkout -b 4.8 -t branch-heads/4.8.

    2. Build via make x64.release on a Linux x64 system to generate the correct binaries.

  2. Copy the complete code from the previous section (the second code snippet), paste it into your favorite text editor, and save as hello_world.cpp in the V8 directory that was created during your V8 build.

  3. Compile hello_world.cpp, linking to the static libraries created in the build process. For example, on 64bit Linux using the GNU compiler:

    g++ -I. hello_world.cpp -o hello_world -Wl,--start-group out/x64.release/obj.target/{tools/gyp/libv8_{base,libbase,external_snapshot,libplatform},third_party/icu/libicu{uc,i18n,data}}.a -Wl,--end-group -lrt -ldl -pthread -std=c++0x
  4. V8 requires its 'startup snapshot' to run. Copy the snapshot files to where your binary is stored: cp out/x64.release/*.bin .

  5. Run the hello_world executable file at the command line. For example, on Linux, still in the V8 directory, type the following at the command line: ./hello_world

  6. You will see Hello, World!.



打赏作者

发表评论

电子邮件地址不会被公开。 必填项已用*标注