Cmake项目效果很好。但是智能感知不起作用

时间:2019-04-01 17:29:17

标签: cmake visual-studio-2017 intellisense c99

Intellisense does not work

我正在Visual Studio 2017中学习cmake项目。它看起来不正常。但是构建和执行效果很好。为什么智能感知不起作用?

project directory(CMakeLists.txt, CMakeSettings.json)

main directory(main.c, CMakeLists.txt)
include directory(myprint.h)
printstatic directory(printstatic.c, CMakeLists.txt)
printshared directory(printshared.c, CMakeLists.txt)

“ myprint.h”

#include <stdio.h>

void print_test_static_library();
void print_test_shared_library();

“ main.c”

#include "myprint.h"

int main()
{
    for (int ii = 0; ii < 3; ++ii) {
        printf("Hello CMake..................\n");
        print_test_static_library();
        print_test_shared_library();
    }

    return 0;
}

“主要的CMakeLists.txt”

cmake_minimum_required (VERSION 3.8)

add_executable (main "main.c")
target_link_libraries(main printstatic printshared)

“ printstatic.c”

#include "myprint.h"

void print_test_static_library()
{
    printf("Test Static Library..................\n");
}

“ printstatic的CMakeLists.txt”

cmake_minimum_required (VERSION 3.8)

add_library (printstatic "printstatic.c")

“ printshared.c”

#include "myprint.h"

void print_test_shared_library()
{
    printf("Test Shared Library..................\n");
}

“ printshared的CMakeLists.txt”

cmake_minimum_required (VERSION 3.8)

add_library (printshared SHARED "printshared.c")

“项目的CMakeLists.txt”

cmake_minimum_required (VERSION 3.8)

set(CMAKE_C_STANDARD 99)

project ("CMakeProjectTest")

include_directories(${PROJECT_SOURCE_DIR}/include)
add_subdirectory ("printstatic")
add_subdirectory ("printshared")
add_subdirectory ("main")

“ CMakeSettings.json”

{
    "configurations": [
        {
            "name": "Linux-Debug",
            "generator": "Unix Makefiles",
            "remoteMachineName": "${defaultRemoteMachineName}",
            "configurationType": "Debug",
            "remoteCMakeListsRoot": "/home/mary/proj/src/${workspaceHash}/${name}",
            "cmakeExecutable": "/usr/local/bin/cmake",
            "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
            "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
            "remoteBuildRoot": "/home/mary/proj/build/${workspaceHash}/build/${name}",
            "remoteInstallRoot": "/home/mary/proj/build/${workspaceHash}/install/${name}",
            "remoteCopySources": true,
            "remoteCopySourcesOutputVerbosity": "Normal",
            "remoteCopySourcesConcurrentCopies": "10",
            "remoteCopySourcesMethod": "sftp",
            "remoteCopySourcesExclusionList": [
                ".vs",
                ".git"
            ],
            "rsyncCommandArgs": "-t --delete --delete-excluded",
            "remoteCopyBuildOutput": false,
            "cmakeCommandArgs": "",
            "buildCommandArgs": "",
            "ctestCommandArgs": "",
            "inheritEnvironments": [
                "linux_x64"
            ]
        }
     ]
}

1 个答案:

答案 0 :(得分:1)

在针对ARM时,这是Intellisense中的错误。 You are not the only one

通过将项目目标切换到x64或x86,Intellisense应该正确地将代码解析为C99。如果需要以ARM为目标,则只需暂时忽略那些红线即可。

您可以通过两种方式向Microsoft提交错误报告。