美文网首页ClickHouse
编译ClickHouse源码 导入CLion

编译ClickHouse源码 导入CLion

作者: 愚公300代 | 来源:发表于2020-11-11 21:33 被阅读0次

    基础信息

    • OS:MacOS Mojave 10.14.6
    • ClickHouse: master branch
    • 在Mac上编译ClickHouse只支持Clang编译器
    • 使用Mac的本地编译器和gcc都会报错

    编译过程

    安装Homebrew,已安装可跳过

    brew -v
    Homebrew 2.5.9
    Homebrew/homebrew-core (git revision 58b4b; last commit 2020-11-11)
    
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    

    安装需要的基础组件

    brew install cmake ninja libtool gettext
    

    安装CLang

    检查

    brew info llvm
    

    安装

    brew install llvm
    

    获取llvm的安装信息,用于设置编译

    To use the bundled libc++ please add the following LDFLAGS:
      LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"
    
    llvm is keg-only, which means it was not symlinked into /usr/local,
    because macOS already provides this software and installing another version in
    parallel can cause all kinds of trouble.
    
    If you need to have llvm first in your PATH run:
      echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> /Users/${user}/.bash_profile
    
    For compilers to find llvm you may need to set:
      export LDFLAGS="-L/usr/local/opt/llvm/lib"
      export CPPFLAGS="-I/usr/local/opt/llvm/include"
    

    编译

    cd ClickHouse
    mkdir build
    cd build
    cmake .. -DCMAKE_C_COMPILER=/usr/local/opt/llvm/bin/clang -DCMAKE_CXX_COMPILER=/usr/local/opt/llvm/bin/clang++ -DCMAKE_BUILD_TYPE=Debug
    ninja
    cd ..
    

    报错

    objcopy

    Cannot find objcopy.
    

    解决办法参考参考目录

    注意

    • 每次编译没成功之前,删除编译失败产生的文件

    运行

    运行方法

    cd /programs
    ./clickhouse-server server --config-file=../../programs/server/config.xml 
    

    注意编译产生的目录结构可能不同,需要查看寻找执行文件
    使用的配置文件位置也可能不同
    可以在ClickHouse源码根目录使用下面的命令查找

    find ./ -name config.xml
    

    报错

    Code: 102. DB::NetException: Unexpected packet from server localhost:9000 (expected Hello or Exception, got Unknown packet)
    
    lsof -i:9000
    COMMAND  PID     USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
    node    2989 ${user}   24u  IPv4 0x78677fdd48cdd7a7      0t0  TCP localhost:cslistener (LISTEN)
    

    kill 掉

     kill 2989
    

    再次连接成功

    ./clickhouse-client -m
    ClickHouse client version 20.12.1.1.
    Connecting to localhost:9000 as user default.
    Connected to ClickHouse server version 20.12.1 revision 54442.
    

    导入到Clion

    导入ClickHouse源码

    将CMakeLists.txt所在根目录导入到Clion中

    配置正确的clang路径

    默认情况下,clion可以探测出正确的编译器,但是在mac上,至少我的环境中探测出的编译器是App,并不work


    默认探测的编译器

    需要配置一个正取的编译器


    配置系统中正取的编译器

    报错

    WARNING "CCache is not found. We recommend setting it up if you build ClickHouse from source often. "

    添加环境变量

    参考

    How to Build ClickHouse on Mac OS
    ClickHouse 开发
    设置CMake使用的编译器
    Cannot find objcopy
    安装LLVM/Clang on OS X
    How to Use CCache with CMake?

    相关文章

      网友评论

        本文标题:编译ClickHouse源码 导入CLion

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