Attempting to build netcode server.c example using visual studio for linux. During compilation I am receiving the following error:
netcode.c(5194,24): error : ‘CLOCK_MONOTONIC_RAW’ undeclared (first use in this function)
Which is coming from the following source:
// linux
#include <unistd.h>
void netcode_sleep( double time )
{
struct timespec ts;
ts.tv_sec = (time_t) time;
ts.tv_nsec = (long) ((time - (double) ( ts.tv_sec )) * 1000000000.0);
nanosleep( &ts, NULL );
}
double netcode_time()
{
static double start = -1;
if ( start == -1 )
{
struct timespec ts;
clock_gettime( CLOCK_MONOTONIC_RAW, &ts );
start = ts.tv_sec + ( (double) ( ts.tv_nsec ) ) / 1000000000.0;
return 0.0;
}
struct timespec ts;
clock_gettime( CLOCK_MONOTONIC_RAW, &ts );
double current = ts.tv_sec + ( (double) ( ts.tv_nsec ) ) / 1000000000.0;
return current - start;
}
I have successfully built this project on windows, as well as DIRECTLY on a linux machine before with no issue. I'm a little perplexed as I wasn't expecting to run into any issues since from what I can tell visual studio for linux is really just syncing sources with a linux host and sending a g++ command for everything to be compiled on the host...so not real sure why this is happening. Any ideas?
EDIT
Solution was to include #define _POSIX_C_SOURCE 199309L
in the source file of the library. For some reason this is not required when building directly on the linux machine, but visual studio for linux is requiring it. I'm guessing that maybe the compile command generated by visual studio for linux is possibly doing something to ommit the build from using _POSIX_C_SOURCE? Maybe? (making this assumption based on the fact the project built successfully directly on the linux machine using a basic g++ command: g++ server.c netcode.a -lsodium
)
Can anyone identify such a switch/option that would be causing that from the below (which is generated by visual studio)
"g++" -W"switch"
-W"no-deprecated-declarations"
-W"empty-body"
-W"conversion"
-W"return-type"
-W"parentheses"
-W"no-pointer-sign"
-W"no-format"
-W"uninitialized"
-W"unreachable-code"
-W"unused-function"
-W"unused-value"
-W"unused-variable"
-std=c++11
-Wall -fno-strict-aliasing
-g2 -gdwarf-2 "g++" -O0 "3600000" -fthreadsafe-statics
-W"switch"
-W"no-deprecated-declarations"
-W"empty-body"
-W"conversion"
-W"return-type"
-W"parentheses"
-W"no-format"
-W"uninitialized"
-W"unreachable-code"
-W"unused-function"
-W"unused-value"
-W"unused-variable"
-frtti -fno-omit-frame-pointer -std=c11 -fexceptions -o "C:\dev\project<different options>