Code Monkey home page Code Monkey logo

Comments (1)

ZhongLingXiao avatar ZhongLingXiao commented on September 21, 2024

可以按照作者博客的方法首先安装 googletest

$ git clone https://github.com/google/googletest.git # version 1.10.0
$ cd googletest/
$ mkdir build/
$ cd build/
$ cmake ..
$ make 
$ make install

然后按照README.md中的方法执行编译即可。
文章链接:https://lesliezhu.com/blog/2022/11/10/writing_an_interpreter_in_cpp_1/#gtest


另外如果你想从源码进行编译,可以这样修改:

这里有2个点需要注意:

  1. 在 clone 仓库的时候注意要获取子模块--recursive标志。所以clone 代码是:
    git clone --recursive https://github.com/LeslieZhu/monkey-cpp.git

  2. 作者使用的是 find_package 方法找到 googletest。我们做以下修改从源码进行编译。举例来说:src/01 这个文件夹的 CMakeList.txt 文件做以下修改。

cmake_minimum_required(VERSION 3.14)
project(waiicpp)

IF(NOT CMAKE_BUILD_TYPE)
  SET(CMAKE_BUILD_TYPE "Release")
ENDIF(NOT CMAKE_BUILD_TYPE)

# GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_CXX_FLAGS "-Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")

MESSAGE("    Build type is ${CMAKE_BUILD_TYPE} [use -DCMAKE_BUILD_TYPE=Release or -DCMAKE_BUILD_TYPE=Debug on the cmake command to configure the build type]")

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")

include_directories(${PROJECT_SOURCE_DIR})

# Add GoogleTest as a subdirectory
add_subdirectory(../../third_party/googletest googletest)

# Link to GoogleTest
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})

add_executable(monkey
  main/monkey.cpp
)

target_link_libraries(monkey
)

add_executable(monkey_test
  test/main.cpp
  test/lexer_test.cpp
)

# Link to GoogleTest libraries
target_link_libraries(monkey_test
  gtest
  gtest_main
)

修改后按README.md的方法进行编译:

$ cd src/01/
$ mkdir build/
$ cd build/
$ cmake ..
$ make

我以上测试环境是在 wsl2 Ubuntu 22.04 上进行测试的。wsl2安装和开发环境搭建可以参考:
https://zhuanlan.zhihu.com/p/456132493

from monkey-cpp.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.