代码之家  ›  专栏  ›  技术社区  ›  Mark Rajcok

如何在构建拼花cpp时静态链接箭头?

  •  2
  • Mark Rajcok  · 技术社区  · 6 年前

    parquet-cpp home page :

    默认情况下,Parquet链接到Arrow的共享库。如果希望静态链接箭头符号,请传递-DPARQUET\u Arrow\u LINKAGE=static。

    我确实想静态链接Arrow,因为我想在其他没有安装Arrow的服务器上使用我的程序。我试过了 -DPARQUET_ARROW_LINKAGE=static ,但我得到一个关于“缺少传递依赖项”的错误:

    # cmake -DPARQUET_BUILD_TESTS=Off -DCMAKE_BUILD_TYPE=Release -DPARQUET_MINIMAL_DEPENDENCY=ON -DPARQUET_ARROW_LINKAGE=static .
    -- The C compiler identification is GNU 4.8.5
    ...
    -- [ /usr/local/share/cmake-3.9/Modules/FindBoost.cmake:1717 ] Boost_FOUND = 1
    -- Boost version: 1.55.0
    ...
    -- THRIFT_HOME:
    -- Thrift compiler/libraries NOT found:  (THRIFT_INCLUDE_DIR-NOTFOUND, THRIFT_STATIC_LIB-NOTFOUND). Looked in system search paths.
    -- Thrift include dir: /root/tmp/parquet-cpp-master/thrift_ep/src/thrift_ep-install/include
    -- Thrift static library: /root/tmp/parquet-cpp-master/thrift_ep/src/thrift_ep-install/lib/libthrift.a
    -- Thrift compiler: /root/tmp/parquet-cpp-master/thrift_ep/src/thrift_ep-install/bin/thrift
    -- Checking for module 'arrow'
    --   No package 'arrow' found
    -- Could not find the Arrow library. Looked for headers in , and for libs in
    -- Building Apache Arrow from commit: 501d60e918bd4d10c429ab34e0b8e8a87dffb732
    -- CMAKE_CXX_FLAGS:  -O3 -DNDEBUG  -Wall -std=c++11
    -- Found cpplint executable at /root/tmp/parquet-cpp-master/build-support/cpplint.py
    CMake Error at CMakeLists.txt:515 (message):
      Missing transitive dependencies for Arrow static linking
    

    所以我 found the code 产生错误的:

      if (NOT DEFINED ENV{BROTLI_STATIC_LIB_ENC} OR
          NOT DEFINED ENV{BROTLI_STATIC_LIB_DEC} OR
          NOT DEFINED ENV{BROTLI_STATIC_LIB_COMMON} OR
          NOT DEFINED ENV{SNAPPY_STATIC_LIB} OR
          NOT DEFINED ENV{ZLIB_STATIC_LIB} OR
          NOT DEFINED ENV{LZ4_STATIC_LIB} OR
          NOT DEFINED ENV{ZSTD_STATIC_LIB})
        message(FATAL_ERROR "Missing transitive dependencies for Arrow static linking")
    

    但这并不能真正帮助我,因为我不知道如何定义这些环境变量。

    我需要先编译Arrow并自行安装吗?(我宁愿让拼花地板cpp帮我做。)

    1 回复  |  直到 6 年前
        1
  •  6
  •   Mark Rajcok    6 年前

    我安排了一个脚本来下载依赖项源、设置环境变量并运行 cmake 最后一行。只需更改DEPDIR变量值,将其设置为所选目录。

    #!/bin/bash
    
    CMKDIR=$PWD
    DEPDIR=/tmp
    
    cd $DEPDIR
    
    #snappy
    git clone https://github.com/google/snappy.git
    cd snappy
    mkdir build 
    cd build 
    cmake ..
    make
    
    export SNAPPY_STATIC_LIB=$DEPDIR/snappy/build/libsnappy.a
    
    cd $DEPDIR
    
    #brotli
    git clone https://github.com/google/brotli.git
    cd brotli
    mkdir out
    cd out
    ../configure-cmake
    make
    
    export BROTLI_STATIC_LIB_ENC=$DEPDIR/brotli/out/libbrotlienc-static.a
    export BROTLI_STATIC_LIB_DEC=$DEPDIR/brotli/out/libbrotlidec-static.a
    export BROTLI_STATIC_LIB_COMMON=$DEPDIR/brotli/out/libbrotlicommon-static.a
    
    cd $DEPDIR
    
    #zlib
    git clone https://github.com/madler/zlib.git
    cd zlib
    ./configure
    make
    
    export ZLIB_STATIC_LIB=$DEPDIR/zlib/libz.a
    
    cd $DEPDIR
    
    #lz4
    git clone https://github.com/lz4/lz4.git
    cd lz4
    make
    
    export LZ4_STATIC_LIB=$DEPDIR/lz4/lib/liblz4.a
    
    cd $DEPDIR
    
    #zstd
    git clone https://github.com/facebook/zstd.git
    cd zstd
    make
    
    export ZSTD_STATIC_LIB=$DEPDIR/zstd/lib/libzstd.a
    
    cd $CMKDIR
    
    cmake -DPARQUET_BUILD_TESTS=Off -DCMAKE_BUILD_TYPE=Release -DPARQUET_MINIMAL_DEPENDENCY=ON -DPARQUET_ARROW_LINKAGE=static
    

    这个脚本非常简单,但应该是有效的。只需将其复制到一个新文件中(在同一个CMakeLists.txt目录中),为该文件提供执行权限(即。 sudo chmod +x filename )然后像这样执行:

    ./filename.sh 
    

    关于 fPIC期权发行 ,您必须编辑一些文件:

    精炼的 :在CmakeList中添加此行。txt,开头,在前两行之后:

    set(CMAKE_POSITION_INDEPENDENT_CODE ON)
    

    lz4型 zstd公司 :编辑lib子目录中的Makefile,位于此行之后

    CFLAGS  += $(DEBUGFLAGS) $(MOREFLAGS)
    

    添加此行:

    CFLAGS += -fPIC
    

    兹利布 :编辑生成文件,在此行之后

    CFLAGS=-O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN
    

    添加此行:

    CFLAGS+=-fPIC
    

    布罗特利 :从make output中可以看到,该选项已设置。

    再次运行make之前,请执行以下脚本:

    #!/bin/bash
    
    DEPDIR=/tmp
    
    cd $DEPDIR/snappy/build
    cmake ..
    make clean
    make
    
    cd $DEPDIR/lz4
    make clean
    make
    
    cd $DEPDIR/zstd
    make clean
    make