1

我想根据输入更改我的 clang 工具的包含路径。当我在示例测试文件上运行以下代码时,出现编译错误“找不到标头”。

#include "clang/Frontend/FrontendActions.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Tooling.h"
// Declares llvm::cl::extrahelp.
#include "llvm/Support/CommandLine.h"


using namespace clang::tooling;
using namespace llvm;

static llvm::cl::OptionCategory MyToolCategory("my-tool options");


int main(int argc , char** argv) {
    int argc_ = 5;
    const char **argv_ = new const char*[5];
    std::vector<std::string> Sources;
    Sources.push_back("path\\to\\Testfile.cpp");
    argv_[0] = argv[0];
    argv_[1] = &Sources[0][0];
    argv_[2] = "--";
    argv_[3] = "c++";
    argv_[4] = "-I\"path\\to\\external\\lib\\directory\"";
    CommonOptionsParser OptionsParser(argc_, argv_, MyToolCategory);
    // run the Clang Tool, creating a new FrontendAction (explained below)


    ClangTool Tool(OptionsParser.getCompilations(), Sources);
    int result = Tool.run(newFrontendActionFactory<clang::SyntaxOnlyAction>().get());

    system("pause");
    return result;
}
4

1 回答 1

0

您可以使用-extra-arg将包含路径传递给编译器 argv_[2]="-extra-arg=-Ipath/to/external/lib/directory"

于 2018-08-25T23:46:14.590 回答