简体   繁体   English

Ubuntu系统中具有不同内容的相同名称标头

[英]Same name headers with different content in Ubuntu system

I have two c++ projects in my Eclipse that uses same function gettimeofday() . 我的Eclipse中有两个使用相同函数gettimeofday() c ++项目。 First project compiles fine while other reports error 第一个项目编译好,而其他报告错误

error: ‘gettimeofday’ was not declared in this scope

By presing F3 on function name I found that in first project case I was navigated to /usr/include/86_64-linux-gnu/sys/time.h . 通过在函数名称上设置F3,我发现在第一个项目案例中,我被导航到/usr/include/86_64-linux-gnu/sys/time.h Second project also has #include <time.h> , but F3 navigates to sys/time.h , which has no 'gettimeofday' function. 第二个项目也有#include <time.h> ,但是F3导航到sys/time.h ,它没有'gettimeofday'函数。

Why same #include <time.h> navigates to different folders? 为什么#include <time.h>导航到不同的文件夹? Why Linux has two same names includes at all? 为什么Linux有两个相同的名称包括在内? Why both includes #include <time.h> are different? 为什么两者都包括#include <time.h>是不同的?

UPD UPD

I found that /sys/timeb.h has inclusion #include <time.h> which navigates to /usr/lib/time.h . 我发现/sys/timeb.h包含#include <time.h> ,它导航到/usr/lib/time.h I was expecting /sys/timeb.h will include /sys/timeb.h. How Eclipse and GCC decides to go 我期待/sys/timeb.h将包含/sys/timeb.h. How Eclipse and GCC decides to go /sys/timeb.h. How Eclipse and GCC decides to go /usr/lib/time.h or /sys/time.h` ? /sys/timeb.h. How Eclipse and GCC decides to go /usr/lib/time.h or / sys / time.h`?

Why "professional" /sys/timeb.h leaves ambiguity in code just by making #include <time.h> instead defining more exact path? 为什么“专业” /sys/timeb.h只是通过#include <time.h>而不是定义更精确的路径而在代码中留下歧义? I suppose <time.h> might point to both - <sys/time.h> and C <time.h> 我想<time.h>可能指向 - <sys/time.h>C <time.h>

On Linux, the function int gettimeofday(struct timeval *tv, struct timezone *tz); 在Linux上,函数int gettimeofday(struct timeval *tv, struct timezone *tz); is defined in #include <sys/time.h> . #include <sys/time.h>定义。 When using it in your code you should include it exactly like that. 在代码中使用它时,您应该完全包含它。 The other time.h is the standard C library that contains time structures and functions such as time_t and mktime . 另一个time.h是标准的C库,它包含时间结构和函数,如time_tmktime When you are using this file in a C++ program you should include it as #include <ctime> which should help you avoid this type of error in the future. 当您在C ++程序中使用此文件时,应将其包含为#include <ctime> ,以帮助您将来避免此类错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM