11

I recently upgraded from Kubuntu 12.04 to 13.04, a complete reinstall.

Using gcc 4.7.3. I compiled some programs to discover there is no /usr/include/sys directory. That is, types.h, stat.h, etc, are absent. They exist in the include/linux directory but not include/sys.

What's going on?

  • What's the error message that GCC prints? Please edit the question to provide this and other information related to your problem. – edwin Feb 1 '14 at 16:09
  • 1
    Do you have build essential installed? – Seth Feb 1 '14 at 16:17
  • The couple of programs I have tried compile fine so there is no error message from gcc. I just can't figure where the header is coming from. I have an editor that builds references to functions and syscall and the like and it isn't happy that it can't find the directory. – Duck Feb 1 '14 at 16:20
  • 1
    Yes, build-essential is up to date. – Duck Feb 1 '14 at 16:22
11

If you use Ubuntu on 64-bit (I can't text exactly right now on a 32-bit system), then the directory from the question is:

/usr/include/x86_64-linux-gnu/sys

Now, having this information, you can create symbolic links to those files if you really need them at that location (/usr/include/sys) using this on a terminal:

sudo ln -s /usr/include/x86_64-linux-gnu/sys/types.h /usr/include/sys/types.h
sudo ln -s /usr/include/x86_64-linux-gnu/sys/stat.h /usr/include/sys/stat.h

# ...etc
  • Yes, 64 bit. I read something similar elsewhere and it seems like everything is in that directory but I am not certain how the headers are getting included from the "#include sys/stat.h" to the x86_64/sys directory. Is this some new fangled gcc injection feature? Off-hand I don't see any symlinks or the like that would (externally) lead to this behavior. – Duck Feb 1 '14 at 16:37
  • Looks like we passed each other in the wind. So the bottom line is that the compiler is doing some magic but I may need to use some symlink hacks to make my editor happy? – Duck Feb 1 '14 at 16:39
  • @Duck I just edited my answer before 2 min of your comments :) – Radu Rădeanu Feb 1 '14 at 16:44
5

install libc6-dev-amd64 if you working on a 64-bit linux. Type the following command on the ubuntu terminal:

sudo apt-get install libc6-dev-amd64
1

Let's check what gcc's default include search path is. From this answer, we get this command:

gcc -xc -E -v -

At the end of the output, I see this on my machine:

ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include

Notice the second-to-last line. That means that when you compile a C file with #include <sys/stat.h>, gcc will look for /usr/include/x86_64-linux-gnu/sys/stat.h before trying /usr/include/sys/stat.h, without us having to symlink anything.

0

the sys directory is a unix/linux system header directory with a lots of system commands. Different brands/version linux may put it in different places. The following command can help you:

find /usr/include -type d -name sys
On my ubuntu 16 got the two
/usr/include/bsd/sys
/usr/include/x86_64-linux-gnu/sys

The first one is home to BSD unix system headers.
The second one is a directory containing Linux 64 bits system heads.

I run into problems with cmake not being able to find the sys/stat.h file. My temporary solution is to make a symbolic link

/user/local/include/sys/stat.h from /usr/include/x86_64-linux-gnu/sys/stat.h

I don't want to pollute the /usr/include directory, and I am only making a link to one particular header file and not the whole sys directory. I think this is a defect of cmake, so making minimal impact by making only one link. Hope this may help those who are suffering from the same problem.

0

Since my architecture is amd64 there is no libc6-dev-amd64. The package to install is libc6-dev-i386.

That fixed the dependency for a CPAN-package.

  • 'Since my architecture is amd64 there is no libc6-dev-amd64': what do you mean? – Marc Vanhoomissen Jan 22 '18 at 11:50
  • What I mean is, that on x86_64 architecture, libraries/kernel/etc. packages have amd64 architecture. So, libc6-dev-amd64 is not available to install. Still the problem persists, some software expect to see /usr/include/sys/. – Jari Turkia Jan 22 '18 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.