美文网首页
OCLint自定义规则1-源代码安装及问题总结

OCLint自定义规则1-源代码安装及问题总结

作者: Jackie_pc | 来源:发表于2019-04-04 18:30 被阅读0次

    源代码安装

    如果要自定义规则,那么必须下载源码进行安装:

    1. clone源码:
    cd ~/Documents
    git clone https://github.com/oclint/oclint.git
    cd oclint
    # 检出tag中的v0.13.1版本到为v0.13.1分支
    git checkout -B v0.13.1 v0.13.1
    
    1. 进入oclint-scripts目录执行make脚本:
    cd oclint-scripts
    ./make
    
    1. 编译成功后,会有以下路径:
      ~/Documents/oclint/build/oclint-release
      这个就是编译好的oclint,我们还需要把这个路径添加到系统的PATH中,在.bash_profile中添加:
    OCLINT_HOME=~/Documents/oclint/build/oclint-release
    export PATH=$OCLINT_HOME/bin:$PATH
    
    1. 进入~/Documents/oclint/build/oclint-release目录,执行:
    cp ~/Documents/oclint/build/oclint-release/bin/oclint* /usr/local/bin/
    ln -s ~/Documents/oclint/build/oclint-release/lib/oclint /usr/local/lib
    ln -s ~/Documents/oclint/build/oclint-release/lib/clang /usr/local/lib
    

    这里使用ln -s,把lib中的clang和oclint软链接到/usr/local/lib中,是为了后面自己编写rule能快速的更新/usr/local/lib中对应的oclint库,而不需要每次更新自定义rule库,又要手动copy到/usr/local/lib。

    1. 重启启动终端,然后输入:
      oclint --version
      出现以下打印信息说明安装成功:
      image.png

    make中遇到的错误

    make可能出现错误:.
    1、 需要提前安装cmake、ninja,在终端执行brew install cmake ninja
    2、编译失败,llvm问题:把version.py中的llvm_latest_release_branch改为最新clang版本(tags/RELEASE_700/final),重新./make可以解决这个问题。
    3、编译错误/Users/laiyoung_/OCLint/oclint-0.13.1/oclint-driver/main.cpp:181:38: error: no viable conversion from 'void (*)()' to 'llvm::cl::VersionPrinterTy' (aka 'function<void (llvm::raw_ostream &)>') llvm::cl::AddExtraVersionPrinter(&oclintVersionPrinter); ^~~~~~~~~~~~~~~~~~~~~
    解决办法:去main.cpp源代码中删除llvm::cl::AddExtraVersionPrinter(&oclintVersionPrinter);
    4、Undefined symbols for architecture x86_64: "clang::cross_tu::IndexError::ID", referenced from: clang::ento::AnyFunctionCall::getRuntimeDefinition() const in libclangStaticAnalyzerCore.a(CallEvent.cpp.o) "clang::cross_tu::CrossTranslationUnitContext::getCrossTUDefinition(clang::FunctionDecl const*, llvm::StringRef, llvm::StringRef)", referenced from: clang::ento::AnyFunctionCall::getRuntimeDefinition() const in libclangStaticAnalyzerCore.a(CallEvent.cpp.o) "clang::cross_tu::CrossTranslationUnitContext::emitCrossTUDiagnostics(clang::cross_tu::IndexError const&)", referenced from: clang::ento::AnyFunctionCall::getRuntimeDefinition() const in libclangStaticAnalyzerCore.a(CallEvent.cpp.o) "clang::cross_tu::CrossTranslationUnitContext::CrossTranslationUnitContext(clang::CompilerInstance&)", referenced from: clang::ento::CreateAnalysisConsumer(clang::CompilerInstance&) in libclangStaticAnalyzerFrontend.a(AnalysisConsumer.cpp.o) "clang::cross_tu::CrossTranslationUnitContext::~CrossTranslationUnitContext()", referenced from: (anonymous namespace)::AnalysisConsumer::~AnalysisConsumer() in libclangStaticAnalyzerFrontend.a(AnalysisConsumer.cpp.o) ld: symbol(s) not found for architecture x86_64 clang-7: error: linker command failed with exit code 1 (use -v to see invocation) ninja: build stopped: subcommand failed.
    解决办法:oclint-driver下CMakeLists中的TARGET_LINK_LIBRARIES段添加clangCrossTU、clangIndex字段

    相关文章

      网友评论

          本文标题:OCLint自定义规则1-源代码安装及问题总结

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