taozhijiangscu
V2EX  ›  C

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

  •  
  •   taozhijiangscu · Apr 26, 2017 · 2818 views
    This topic created in 3317 days ago, the information mentioned may be changed or developed.
    如题,只是包含了一个简单的 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 replies    2017-05-09 22:30:25 +08:00
    arakashic
        1
    arakashic  
       Apr 27, 2017
    贴一下代码、编译方法和环境吧
    copen
        2
    copen  
       Apr 27, 2017
    编译 c 还是 c++? 如果是 c++链接动态库了吗? -lstdc++
    taozhijiangscu
        3
    taozhijiangscu  
    OP
       Apr 27, 2017
    @arakashic

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

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

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

    正常。项目中没有 time.h

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

    是 g++
    pright
        8
    pright  
       May 9, 2017
    这个看起来就是引用了 ArgVector.cpp 所在目录下的 time.h,检查下项目的 makefile 里面对于头文件路径的设置。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1614 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 16:29 · PVG 00:29 · LAX 09:29 · JFK 12:29
    ♥ Do have faith in what you're doing.