V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
taozhijiangscu
V2EX  ›  C

gcc 编译时候一个诡异的问题

  •  
  •   taozhijiangscu · 2017-04-26 22:42:39 +08:00 · 1996 次点击
    这是一个创建于 2529 天前的主题,其中的信息可能已经有所发展或是发生改变。
    如题,只是包含了一个简单的 iostream ,依赖到最后慢慢的包含了系统的 time.h ,导致无法编译通过

    In file included from /usr/include/sched.h:34,
    from /usr/include/pthread.h:25,
    from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/x86_64-redhat-linux/bits/gthr-default.h:41,
    from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/x86_64-redhat-linux/bits/gthr.h:162,
    from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ext/atomicity.h:34,
    from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/ios_base.h:41,
    from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ios:43,
    from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/ostream:40,
    from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/iostream:40,
    from ../commonutil/Config.h:124,
    from ../commonutil/ArgVector.h:4,
    from ArgVector.cpp:1:
    ./time.h:27: 错误:‘ Int64 ’未声明
    ./time.h:28: 错误:‘ Int64 ’未声明
    ./time.h:29: 错误:‘ Int64 ’未声明
    ./time.h:30: 错误:‘ time_t ’未声明
    ./time.h:31: 错误:‘ time_t ’未声明
    ./time.h:33: 错误:‘ time_t ’未声明
    ./time.h:34: 错误:‘ time_t ’未声明

    [user@centos6 test]$ find /usr -name time.h
    /usr/include/linux/time.h
    /usr/include/sys/time.h
    /usr/include/bits/time.h
    /usr/include/time.h
    find: “/usr/lib64/audit ”: 权限不够
    /usr/src/kernels/2.6.32-431.el6.x86_64/include/config/netfilter/xt/match/time.h
    /usr/src/kernels/2.6.32-431.el6.x86_64/include/linux/time.h
    /usr/src/kernels/2.6.32-431.el6.x86_64/arch/x86/include/asm/time.h
    [user@centos6 test]$


    日了狗了,有没有遇到过这种问题的?
    8 条回复    2017-05-09 22:30:25 +08:00
    arakashic
        1
    arakashic  
       2017-04-27 05:14:30 +08:00
    贴一下代码、编译方法和环境吧
    copen
        2
    copen  
       2017-04-27 14:17:44 +08:00
    编译 c 还是 c++? 如果是 c++链接动态库了吗? -lstdc++
    taozhijiangscu
        3
    taozhijiangscu  
    OP
       2017-04-27 17:26:19 +08:00
    @arakashic

    公司的东西,贴出来不太方便吧

    其实就是#include <iostream>,结果就搞到很多 C 头上面去了
    arakashic
        4
    arakashic  
       2017-04-27 22:50:50 +08:00
    @taozhijiangscu 那这样,下面这个编译正常吗?
    #include <iostream>

    int main(int argc, char *argv[])
    {
    std::cout << "hw" << std::endl;
    return 0;
    }
    我猜你代码的当前目录有一个 time.h 吧
    taozhijiangscu
        5
    taozhijiangscu  
    OP
       2017-04-28 18:25:22 +08:00
    @arakashic

    正常。项目中没有 time.h

    唉,蛋疼……
    cooldadiao
        6
    cooldadiao  
       2017-05-05 17:26:49 +08:00
    用 g++不是 gcc
    taozhijiangscu
        7
    taozhijiangscu  
    OP
       2017-05-06 08:23:53 +08:00
    @cooldadiao

    是 g++
    pright
        8
    pright  
       2017-05-09 22:30:25 +08:00
    这个看起来就是引用了 ArgVector.cpp 所在目录下的 time.h,检查下项目的 makefile 里面对于头文件路径的设置。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2808 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 15:02 · PVG 23:02 · LAX 08:02 · JFK 11:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.