[SOLVED] Why do I not always have to explicitly include a system library for it to compile?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Why do I not always have to explicitly include a system library for it to compile?
Newb question. I am having to switch between two computers (Centos 5.8 and Centos 6.2) and I have noticed that on the CentOS 5 system I do not need to explicitly include the string library while on the CentOS 6 system I do, such as the following:
Newb question. I am having to switch between two computers (Centos 5.8 and Centos 6.2) and I have noticed that on the CentOS 5 system I do not need to explicitly include the string library while on the CentOS 6 system I do, such as the following:
This will compile fine on the CentOS 5 system but on the CentOS 6 system i receive the following:
Code:
stringtest.cpp: In function ‘int main()’:
stringtest.cpp:5: error: ‘strlen’ was not declared in this scope
Could this be a compiler or gcc version difference? Thanks for any tips!
It is probably due to the implementation of iostream. In older versions, it probably included <cstring> or some other header which did, whereas in current versions it does not.
We had a similar problem in my office recently; someone made code changes and only tested the compilation on RHEL5. But on RHEL6, it would not compile.
Just for the sake of accuracy, C/C++ header files are not libraries. They are source code. Libraries are bound to your application at link time, by a linker (and again at runtime, in the case of shared object libraries). Header files are commonly associated with libraries, as they can be used to describe to the compiler how the library content can be accessed. The libraries are already separately compiled, so the compiler can only know about their content by including source code statements that describe the content.
--- rod.
"As detailed here (Header dependency streamlining), many of the standard C++ library include files have been edited to only include the smallest possible number of additional files. As such, many C++ programs that used std::memcpy without including <cstring>, or used std::auto_ptr without including <memory> will no longer compile.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.