代码之家  ›  专栏  ›  技术社区  ›  whitwhoa

Visual Studio Linux找不到主机全局设置?

  •  0
  • whitwhoa  · 技术社区  · 6 年前

    netcode 使用visualstudioforlinux的server.c示例。在编译过程中,我收到以下错误: netcode.c(5194,24): error : ‘CLOCK_MONOTONIC_RAW’ undeclared (first use in this function)

    其来源如下:

    // 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;
    }
    

    我已经成功地在windows上构建了这个项目,而且在linux机器上也没有问题。我有点困惑,因为我没想到会遇到任何问题,因为据我所知,visualstudioforlinux实际上只是将源代码与linux主机同步,并发送一个g++命令,以便在主机上编译所有内容……所以不太清楚为什么会发生这种情况。有什么想法吗?

    #define _POSIX_C_SOURCE 199309L in the source file of the library . 由于某些原因,在linux机器上直接构建时不需要这样做,但是visualstudioforlinux需要它。我猜,也许visualstudioforlinux生成的compile命令可能是在使用POSIX_C_SOURCE对构建进行操作?也许 吧?(这个假设是基于项目使用一个基本的g++命令直接在linux机器上构建的: g++ server.c netcode.a -lsodium

    "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>
    
    0 回复  |  直到 6 年前