美文网首页
读xtensor源码1——环境配置

读xtensor源码1——环境配置

作者: Elinx | 来源:发表于2018-07-22 23:33 被阅读156次

    1. 选用的软件

    xtensor支持vs2017,使用windows环境能更加方便的读代码,工具列表:

    • vs217社区版
    • git windows
    • cmake最新版

    2. 编译

    2.1 编译xtl

    xtensor依赖自己的库xtl,因此需要下载xtl和xtensor,git clone之后,得目录结构图如下:

    - github
    |--- xtensor
    |--- xtl
    |--- x-lib
    

    其中x-lib是用来保存x生产的库。先build xtl

    mkdir build
    cd build
    cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=''D:\workpace\github\x-lib"
    

    生成在x-lib的目录结构如下:

    x-lib
    ├─include
    │  └─xtl
    └─lib
        └─cmake
            └─xtl
    

    注意这里使用的cmd是vs2017的开发者console,否则找不到nmake。

    2.2 编译xtensor

    使用跟编译xtl完全一样的编译方式即可,如果不是把xtensor的install文件夹放到x-lib的话,会找不到xtl,使用x-lib,则能够构建通过:

    Found xtl: D:/workpace/github/x-lib/include/xtl
    

    注意这里跟xtl一样会出现找不到一个json库,这只是个warning,不是error,可以不管。

    CMake Warning at CMakeLists.txt:35 (find_package):
      By not providing "Findnlohmann_json.cmake" in CMAKE_MODULE_PATH this
      project has asked CMake to find a package configuration file provided by
      "nlohmann_json", but CMake did not find one.
    
      Could not find a package configuration file provided by "nlohmann_json"
      (requested version 3.1.1) with any of the following names:
    
        nlohmann_jsonConfig.cmake
        nlohmann_json-config.cmake
    
      Add the installation prefix of "nlohmann_json" to CMAKE_PREFIX_PATH or set
      "nlohmann_json_DIR" to a directory containing one of the above files.  If
      "nlohmann_json" provides a separate development package or SDK, be sure it
      has been installed.
    

    然后nmake install把xtensor也安装到相应的目录即可。现在的目录结构变成了:

    x-lib
    ├─include
    │  ├─xtensor
    │  └─xtl
    └─lib
        ├─cmake
        │  ├─xtensor
        │  └─xtl
        └─pkgconfig
    

    3. 带test的编译

    2中的编译只能生成install target,我们的目的是能够调试跟踪用例,那么还需要一点儿努力。

    按照官网的说法,打开BUILD_TESTS选项即可生成test和benchmark两个target,要么指定gtest的路径,要么选择联网安装gtest,vs2017社区版默认是装了gtest的adaptor的,但是找不到目录,只能选择联网了,使用的命令:

    cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=D:\workpace\github\x-lib 
    -DDOWNLOAD_GTEST=ON ..
    

    成功后再build/test下面有gtest的路径生成。成功之后运行nmake编译又出错了:

    gtest.lib(gtest-all.cc.obj) : error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MT_StaticRelease”不匹配值“MD_DynamicRelease”(main.cpp.obj 中)
    

    原因是最新的vs生成的代码使用的动态链接,而gtest默认使用的是静态链接,解决方法是使用gtest_force_shared_crt,gtest的github有介绍

    最终,为了能够生成vs工程,cmake命令变成了:

    cmake -DCMAKE_INSTALL_PREFIX=D:\workpace\github\x-lib 
    -DDOWNLOAD_GTEST=ON 
    -Dgtest_force_shared_crt=ON ..
    

    最后运行cmake --build .进行漫长的编译后终于成功了:

    其实还有一点儿错误,但是已经不影响了,生成了200多个test,足够看了。
    

    4. 下一步计划

    • 替换成clang(社区版是否支持?)
    • 运行并分析用例
    • 将这个编译构建的issue提到xtensor社区

    To Be Continued...

    相关文章

      网友评论

          本文标题:读xtensor源码1——环境配置

          本文链接:https://www.haomeiwen.com/subject/qubrmftx.html