The issue is resolved by insert #define _POSIX_C_SOURCE 199309L.
Reference: https://developercommunity.visualstudio.com/t/CLOCK_REALTIME-Is-Undefined-In-Visual-St/10843559
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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:
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.
The issue is resolved by insert #define _POSIX_C_SOURCE 199309L.
Reference: https://developercommunity.visualstudio.com/t/CLOCK_REALTIME-Is-Undefined-In-Visual-St/10843559
The issue is resolved by adding #define _POSIX_C_SOURCE 199309L.
Reference: https://developercommunity.visualstudio.com/t/CLOCK_REALTIME-Is-Undefined-In-Visual-St/10843559