192

I am trying to install Nachos on my laptop and I have Ubuntu 11.04 on the laptop.

The code is in C and so to build it I assume I will need cross compiler. This is where my problem is. I downloaded the source code of the MIPS cross compiler using the command

  wget http://mll.csie.ntu.edu.tw/course/os_f08/assignment/mips-decstation.linux-xgcc.gz

and I unzipped it using

tar zxvf mips-decstation.linux-xgcc.gz      

This is okay, but when I try to build the source code of the nachos os, using make, I get this error -

/usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: No such file or directory compilation terminated. make: *** [bitmap.o] Error 1

I am trying to follow the instructions given over here - http://mll.csie.ntu.edu.tw/course/os_f08/217.htm and everything is working fine except when I try to use make.

VividD
  • 10,456
  • 6
  • 64
  • 111
Ashish Agarwal
  • 14,555
  • 31
  • 86
  • 125
  • 1
    Thank you for your suggestions, the program now starts to compile but I get this error _ Hi, now i have this error - /usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/libstdc++.a when searching for -lstdc++ /usr/bin/ld: cannot find -lstdc++ collect2: ld returned 1 exit status make: *** [nachos] Error 1 any ideas on how to fix this ? What should I do about this ? – Ashish Agarwal Sep 14 '11 at 20:47

13 Answers13

404

You're missing the 32 bit libc dev package:

On Ubuntu it's called libc6-dev-i386 - do sudo apt-get install libc6-dev-i386. See below for extra instructions for Ubuntu 12.04.

On Red Hat distros, the package name is glibc-devel.i686 (Thanks to David Gardner's comment).

On CentOS 5.8, the package name is glibc-devel.i386 (Thanks to JimKleck's comment).

On CentOS 6 / 7, the package name is glibc-devel.i686.

On SLES it's called glibc-devel-32bit - do zypper in glibc-devel-32bit.

On Gentoo it's called sys-libs/glibc - do emerge -1a sys-libs/gcc [source] (Note : One may use equery to confirm this is correct; do equery belongs belongs /usr/include/gnu/stubs-32.h)

On ArchLinux, the package name is lib32-glibc - do pacman -S lib32-glibc.


Are you using Ubuntu 12.04? There is a known problem that puts the files in a non standard location. You'll also need to do:

export LIBRARY_PATH=/usr/lib/$(gcc -print-multiarch)
export C_INCLUDE_PATH=/usr/include/$(gcc -print-multiarch)
export CPLUS_INCLUDE_PATH=/usr/include/$(gcc -print-multiarch)

somewhere before you build (say in your .bashrc).


If you are also compiling C++ code, you will also need the 32 bit stdc++ library. If you see this warning:

.... /usr/bin/ld: cannot find -lstdc++ ....

On Ubuntu you will need to do sudo apt-get install g++-multilib

On CentOS 5 you will need to do yum install libstdc++-devel.i386

On CentOS 6 you will need to do yum install libstdc++-devel.i686

Please feel free to edit in the packages for other systems.

noraj
  • 3,964
  • 1
  • 30
  • 38
Timothy Jones
  • 21,495
  • 6
  • 60
  • 90
  • 2
    Maybe the reason I didn't find that package is that my laptop is 32 bit...I did however find `libc-dev-amd64`. My bad. – Keith Layne Sep 14 '11 at 07:28
  • 1
    Yeah, I'd say he's probably on a 64 bit machine, which is why the file is missing. On my 64 bit machine, stubs.h (which he has) is in libc6-dev, while stubs-32.h (which he doesn't) is in libc6-dev-i386. Good tip about apt-file - I didn't know about it :) – Timothy Jones Sep 14 '11 at 07:32
  • 2
    There is a known problem on Ubuntu 12.04 that puts this file in a non-standard directory after installation. This solution worked for me in the end http://gcc.gnu.org/ml/gcc/2012-02/msg00314.html. – Eric Chen Sep 19 '12 at 23:20
  • Thanks @e_x_p. I've added these extra instructions. – Timothy Jones Oct 10 '12 at 05:36
  • on fedora 19 i had to install glibc-devel.i686 instead (i686 vs i386). – Emmanuel M. Smith Sep 20 '13 at 08:36
  • What if you are not su on your machine? – Bernhard Feb 27 '14 at 15:12
  • To avoid linker error you'll also need a 32 bits libgcc (`libgcc.i686` on fedora) – toasted_flakes Jul 24 '14 at 20:39
  • so, is it not the case that the OP would just need to direct the installation to use the 64-bit version of stubs that's already present? the OP needs to install the 32-bit version even though the installation is (potentially) taking place on a 64-bit machine? – abcd Oct 10 '15 at 21:42
  • 1
    **fedora** `sudo dnf install glibc-devel.i686` – Nick Dong Dec 12 '22 at 14:42
58

From the GNU UPC website:

Compiler build fails with fatal error: gnu/stubs-32.h: No such file or directory

This error message shows up on the 64 bit systems where GCC/UPC multilib feature is enabled, and it indicates that 32 bit version of libc is not installed. There are two ways to correct this problem:

  • Install 32 bit version of glibc (e.g. glibc-devel.i686 on Fedora, CentOS, ..)
  • Disable 'multilib' build by supplying "--disable-multilib" switch on the compiler configuration command
ignis
  • 8,692
  • 2
  • 23
  • 20
9

Try doing a sudo apt-get install libc6-dev.

apt-file tells me that the file in question belongs to that package.

Keith Layne
  • 3,688
  • 1
  • 24
  • 28
  • This is not sufficient on a multiarch machine since you'll still get this error even if you have the latest version of libc6-dev installed. – jeremiah Mar 20 '12 at 15:34
7

This is now in the GCC wiki FAQ, see http://gcc.gnu.org/wiki/FAQ#gnu_stubs-32.h

Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521
2

Hmm well I am on ubuntu 12.04 and I got this same error when trying to compile gcc 4.7.2

I tried installing the libc6-dev-i386 package and got the following:

Package libc6-dev-i386 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'libc6-dev-i386' has no installation candidate

I also set the correct environment variables in bash:

export LIBRARY_PATH=/usr/lib/$(gcc -print-multiarch)
export C_INCLUDE_PATH=/usr/include/$(gcc -print-multiarch)
export CPLUS_INCLUDE_PATH=/usr/include/$(gcc -print-multiarch)

however, I was still getting the error then I simply copied stubs-32.h over to where gcc was expecting to find it after doing a quick diff:

vic@ubuntu:/usr/include/i386-linux-gnu/gnu$ diff ../../gnu ./
Only in ./: stubs-32.h
Only in ../../gnu: stubs-64.h
vic@ubuntu:/usr/include/i386-linux-gnu/gnu$ sudo cp stubs-32.h ../../gnu/
[sudo] password for vic: 
vic@ubuntu:/usr/include/i386-linux-gnu/gnu$ diff ../../gnu ./
Only in ../../gnu: stubs-64.h
vic@ubuntu:/usr/include/i386-linux-gnu/gnu$

It's compiling now, let's see if it complains more ...

Victor Parmar
  • 5,719
  • 6
  • 33
  • 36
  • Odd. That package is definitely available in 12.04 (Precise) see http://packages.ubuntu.com/precise/libc6-dev-i386 – Timothy Jones Mar 27 '13 at 01:28
  • I faced this issue while running on VS Code in linux. Adding "/usr/include/x86_64-linux-gnu" to c_cpp_properties.json file's includePath array worked perfect for me. Thanks to your answer I found the location of this file. – Sahin Dec 28 '20 at 23:27
2

I was getting following error on a fedora 18 box:


1. /usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: No such file or directory compilation terminated.

I Installed glibc.i686 and glibc-devel.i686, then compilation failed with following error:

2. /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.7.2/libgcc_s.so when searching for -lgcc_s /usr/bin/ld: cannot find -lgcc_s collect2: error: ld returned 1 exit status

Solution:

I installed (yum install) glibc.i686 glibc-devel.i386 and libgcc.i686 to get rid of the compilation issue.

Now compilation for 32 bit (-m32) works fine.

AndreyAkinshin
  • 18,603
  • 29
  • 96
  • 155
0

gnu/stubs-32.h is not directed included in programms. It's a back-end type header file of gnu/stubs.h, just like gnu/stubs-64.h. You can install the multilib package to add both.

0

# sudo apt-get install g++-multilib

Should fix this error on 64-bit machines (Debian/Ubuntu).

0

If you are facing this issue in Mac-OSX terminal with python, try updating the versions of the packages you are using. So, go to your files in python and where you specified the packages, update them to the latest versions available on the internet.

D.Bhatia
  • 1
  • 1
0

On Debian/Ubuntu use:

sudo apt-get install g++-multilib libc6-dev-i386

Keivan
  • 1,300
  • 1
  • 16
  • 29
0

If you are on Arch Linux like me. You can try

  • sudo pacman -S lib32-gcc-libs

It worked for me.

0

FWIW, it smells like an error (or at least a potential source of future pain) to be using files from /usr/include when cross-compiling.

user47559
  • 1,201
  • 8
  • 9
0

Hi,I encountered the same question. When I add '-D__TARGET_ARCH_x86' in MAKEFILE, it worked!

The the error message is like:

In file included from /usr/include/string.h:26:
In file included from /usr/include/bits/libc-header-start.h:33:
In file included from /usr/include/features.h:452:
/usr/include/gnu/stubs.h:7:11: fatal error: 'gnu/stubs-32.h' file not found
# include <gnu/stubs-32.h>nter code here

The content in stubs.h is

#if !defined __x86_64__
# include <gnu/stubs-32.h>
#endif
#if defined __x86_64__ && defined __LP64__
# include <gnu/stubs-64.h>
#endif
#if defined __x86_64__ && defined __ILP32__
# include <gnu/stubs-x32.h>
#endif

you could find the real reason is the missing of macro definition x86_64. The compilor has to find stubs-x32.h. So you can install glibc with 32bits to solve the question. But the better way is to specific the arch as 64bits。You only need to add '-D__TARGET_ARCH_x86' in gcc&g++ command in MAKEFILE.

Shang Dong
  • 21
  • 2