如何在忍者上添加包含路径,并为VS 2019添加叮当

How to add include path on Ninja and clang for VS 2019?

本文关键字:添加 并为 VS 叮当 2019 路径 包含 忍者      更新时间:2023-10-16

>所以,我想使用 CMake 和 clang 作为 VS2019 的前端,使用额外的包含路径构建我的项目。

我已经尝试过的:

  • CMakeList.txt
# CMakeList.txt : CMake project for test-llvm, include source and define
# project specific logic here.
#
cmake_minimum_required (VERSION 3.8)
# Add source to this project's executable.
add_executable (test-llvm "test-llvm.cpp" "test-llvm.h")
# TODO: Add tests and install targets if needed.
set(INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
  • CMakeSettings.json
{
  "configurations": [
    {
      "name": "x64-Clang-Debug",
      "generator": "Ninja",
      "configurationType": "Debug",
      "buildRoot": "${projectDir}\out\build\${name}",
      "installRoot": "${projectDir}\out\install\${name}",
      "cmakeCommandArgs": "",
      "buildCommandArgs": "-v",
      "ctestCommandArgs": "",
      "inheritEnvironments": [ "clang_cl_x64" ],
      "variables": []
    },
    {
      "name": "x86-Clang-Release",
      "generator": "Ninja",
      "configurationType": "RelWithDebInfo",
      "buildRoot": "${projectDir}\out\build\${name}",
      "installRoot": "${projectDir}\out\install\${name}",
      "cmakeCommandArgs": "",
      "buildCommandArgs": "-v",
      "ctestCommandArgs": "",
      "inheritEnvironments": [ "clang_cl_x86" ],
      "variables": []
    }
  ]
}
  • test-llvm.cpp
#include <needtoinclude.h>
int main()
{
    std::cout << "Hello world" << std::endl;
}
  • test-llvm.h (Empty(

    包括
  • /需要包括.h
#pragma once
#include <iostream>

以及我得到哪些错误

>------ Build All started: Project: test-llvm, Configuration: x64-Clang-Debug ------
  [1/2] C:PROGRA~2MIB055~12019PROFES~1COMMON7IDECOMMON~1MICROS~1Llvmbinclang-cl.exe  /nologo -TP   -m64 -fdiagnostics-absolute-paths  /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 /showIncludes /FoCMakeFilestest-llvm.dirtest-llvm.cpp.obj /FdCMakeFilestest-llvm.dir -c ......test-llvm.cpp
  FAILED: CMakeFiles/test-llvm.dir/test-llvm.cpp.obj 
  C:PROGRA~2MIB055~12019PROFES~1COMMON7IDECOMMON~1MICROS~1Llvmbinclang-cl.exe  /nologo -TP   -m64 -fdiagnostics-absolute-paths  /DWIN32 /D_WINDOWS /W3 /GR /EHsc /MDd /Zi /Ob0 /Od /RTC1 /showIncludes /FoCMakeFilestest-llvm.dirtest-llvm.cpp.obj /FdCMakeFilestest-llvm.dir -c ......test-llvm.cpp
C:UsersstakemuraDropboxDocumentstest-llvmtest-llvm.cpp(1,13): fatal error : 'needtoinclude.h' file not found
  <U+FEFF>#include <needtoinclude.h>
                   ^~~~~~~~~~~~~~~~~
  1 error generated.
  ninja: build stopped: subcommand failed.
Build All failed.

我应该怎么做才能添加包含路径?

我修改了CMakeList.txt如下所示。似乎解决了。

# CMakeList.txt : CMake project for test-llvm, include source and define
# project specific logic here.
#
cmake_minimum_required (VERSION 3.8)
# Add source to this project's executable.
add_executable (test-llvm "test-llvm.cpp" "test-llvm.h")
# TODO: Add tests and install targets if needed.
include_directories("include")