CLOCK_REALTIME Is Undefined In Visual Studio But Can Run in Linux Target

Yik Heng Yong 0 Reputation points
2025-01-15T07:03:40.5366667+00:00

Question:

Aside from just adding the error to the ignore list in Visual Studio, is there a way to get Visual Studio to recognize POSIX-related functions?

Visual Studio Version: Community 2022 (64-bit) v17.12.3

Workload: Linux development with C++

Code Snippet:

#include <stdio.h>
#include <time.h>
int main()
{
    struct timespec ts;
    double time;
    
    clock_gettime(CLOCK_REALTIME, &ts);
    time = ts.tv_sec + (ts.tv_nsec / 1e9);
    printf("Time:%f\n", time);
    return 0;
}

Error Code:Error Code

Linux Terminal Result:

pi@bpi-iot-ros-ai:~/projects/ConsoleApplication1$ ./main
Time:1736924024.770033

Troubleshooting Steps That Taken By Myself:

I tried to Update but the error persisted.

Update

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,359 questions
Visual Studio Extensions
Visual Studio Extensions
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Extensions: A program or program module that adds functionality to or extends the effectiveness of a program.
243 questions
Visual Studio Setup
Visual Studio Setup
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Setup: The procedures involved in preparing a software program or application to operate within a computer or mobile device.
1,073 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.