Search code examples
cmakevisual-studio-2017intellisensec99

Cmake project works well. But intellisense does not work


Intellisense does not work

I am studying cmake project in visual studio 2017. It does not look like working. But Building and executing works well. Why does not intellisense work?

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 of main"

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");
}

"CMakeLists.txt of printstatic"

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");
}

"CMakeLists.txt of printshared"

cmake_minimum_required (VERSION 3.8)

add_library (printshared SHARED "printshared.c")

"CMakeLists.txt of project"

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"
            ]
        }
     ]
}

Solution

  • It's a bug in Intellisense when targeting ARM. You are not the only one.

    By switching the project target to x64 or x86, Intellisense should correctly parse the code as C99. If you need to target ARM, you just have to ignore those red lines for the time being.

    Either way you might want to file a bug report to Microsoft.