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

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

  •  
  •   taozhijiangscu · 2017 年 4 月 26 日 · 2629 次点击
    这是一个创建于 3183 天前的主题,其中的信息可能已经有所发展或是发生改变。
    如题,只是包含了一个简单的 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 年 4 月 27 日
    贴一下代码、编译方法和环境吧
    copen
        2
    copen  
       2017 年 4 月 27 日
    编译 c 还是 c++? 如果是 c++链接动态库了吗? -lstdc++
    taozhijiangscu
        3
    taozhijiangscu  
    OP
       2017 年 4 月 27 日
    @arakashic

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

    其实就是#include <iostream>,结果就搞到很多 C 头上面去了
    arakashic
        4
    arakashic  
       2017 年 4 月 27 日
    @taozhijiangscu 那这样,下面这个编译正常吗?
    #include <iostream>

    int main(int argc, char *argv[])
    {
    std::cout << "hw" << std::endl;
    return 0;
    }
    我猜你代码的当前目录有一个 time.h 吧
    taozhijiangscu
        5
    taozhijiangscu  
    OP
       2017 年 4 月 28 日
    @arakashic

    正常。项目中没有 time.h

    唉,蛋疼……
    cooldadiao
        6
    cooldadiao  
       2017 年 5 月 5 日
    用 g++不是 gcc
    taozhijiangscu
        7
    taozhijiangscu  
    OP
       2017 年 5 月 6 日
    @cooldadiao

    是 g++
    pright
        8
    pright  
       2017 年 5 月 9 日
    这个看起来就是引用了 ArgVector.cpp 所在目录下的 time.h,检查下项目的 makefile 里面对于头文件路径的设置。
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   966 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 22:32 · PVG 06:32 · LAX 14:32 · JFK 17:32
    ♥ Do have faith in what you're doing.