V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
angel725
V2EX  ›  问与答

这个错误要怎么办 unknown type name 'clock_t'

  •  
  •   angel725 · 2018-10-05 17:21:54 +08:00 · 4167 次点击
    这是一个创建于 2240 天前的主题,其中的信息可能已经有所发展或是发生改变。
    [zz@localhost trunk]$ x86_64-w64-mingw32-gcc word2vec.c -o word2vec.exe
    word2vec.c:19:10: error: #include expects "FILENAME" or <FILENAME>
     #include pthread.h
              ^
    word2vec.c:46:1: error: unknown type name 'clock_t'
     clock_t start;
     ^
    word2vec.c: In function 'TrainModelThread':
    word2vec.c:368:3: error: unknown type name 'clock_t'
       clock_t now;
       ^
    word2vec.c:381:63: error: 'CLOCKS_PER_SEC' undeclared (first use in this function)
              word_count_actual / ((real)(now - start + 1) / (real)CLOCKS_PER_SEC * 1000));
                                                                   ^
    word2vec.c:381:63: note: each undeclared identifier is reported only once for each function it appears in
    word2vec.c: In function 'TrainModel':
    word2vec.c:547:3: error: unknown type name 'pthread_t'
       pthread_t *pt = (pthread_t *)malloc(num_threads * sizeof(pthread_t));
       ^
    word2vec.c:547:20: error: 'pthread_t' undeclared (first use in this function)
       pthread_t *pt = (pthread_t *)malloc(num_threads * sizeof(pthread_t));
                        ^
    word2vec.c:547:31: error: expected expression before ')' token
       pthread_t *pt = (pthread_t *)malloc(num_threads * sizeof(pthread_t));
                                   ^
    word2vec.c:556:84: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
       for (a = 0; a < num_threads; a++) pthread_create(&pt[a], NULL, TrainModelThread, (void *)a);
                                                                                        ^
    
    [zz@localhost trunk]$ x86_64-w64-mingw32-gcc word2vec.c -o word2vec.exe
    word2vec.c:46:1: error: unknown type name 'clock_t'
     clock_t start;
     ^
    word2vec.c: In function 'TrainModelThread':
    word2vec.c:368:3: error: unknown type name 'clock_t'
       clock_t now;
       ^
    word2vec.c:381:63: error: 'CLOCKS_PER_SEC' undeclared (first use in this function)
              word_count_actual / ((real)(now - start + 1) / (real)CLOCKS_PER_SEC * 1000));
                                                                   ^
    word2vec.c:381:63: note: each undeclared identifier is reported only once for each function it appears in
    word2vec.c: In function 'TrainModel':
    word2vec.c:556:84: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
       for (a = 0; a < num_threads; a++) pthread_create(&pt[a], NULL, TrainModelThread, (void *)a);
                                                                                        ^
    

    第一次在 centos 下编译 exe。

    出现这种错误,不知道怎么办??

    直接 make 出来的,可以运行。但我想要在 win 下的。

    谢谢

    第 1 条附言  ·  2018-10-05 20:12:52 +08:00

    有pthread.h

    [zz@localhost trunk]$ x86_64-w64-mingw32-gcc word2vec.c -o word2vec.exe
    word2vec.c:46:1: error: unknown type name 'clock_t'
     clock_t start;
     ^
    word2vec.c: In function 'TrainModelThread':
    word2vec.c:368:3: error: unknown type name 'clock_t'
       clock_t now;
       ^
    word2vec.c:381:63: error: 'CLOCKS_PER_SEC' undeclared (first use in this function)
              word_count_actual / ((real)(now - start + 1) / (real)CLOCKS_PER_SEC * 1000));
                                                                   ^
    word2vec.c:381:63: note: each undeclared identifier is reported only once for each function it appears in
    word2vec.c: In function 'TrainModel':
    word2vec.c:556:84: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
       for (a = 0; a < num_threads; a++) pthread_create(&pt[a], NULL, TrainModelThread, (void *)a);
                                                                                        ^
    
    

    这是加了pthread.h后的错误。

    4 条回复    2018-10-06 08:53:37 +08:00
    visitant
        1
    visitant  
       2018-10-05 17:52:13 +08:00 via iPad
    看起来是需要链接 pthread 库啊,windows+pthread 搜索一下吧
    visitant
        2
    visitant  
       2018-10-06 01:33:34 +08:00 via iPad
    clock_t 这个类型好像在标准库里就有,试下包含 windows.h 头文件,而且直接在 win 下编译不好吗,非要交叉编译不可?
    msg7086
        3
    msg7086  
       2018-10-06 04:35:30 +08:00
    其实我还是建议你先在 Windows 版的 mingw 里试试……
    shiyouming91
        4
    shiyouming91  
       2018-10-06 08:53:37 +08:00 via iPhone
    include time.h 了么?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1129 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 18:46 · PVG 02:46 · LAX 10:46 · JFK 13:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.