0

I use Ubuntu 15.10 64 bit. gcc-5-multilib, g++-5-multilib, libc6-i386, kernel headers and all build toolchain are installed. When I try to compile 32 bit library (for linux) like:

gcc -m32 -fPIC -shared -Wl,-soname,mylib.so -o mylib.so mylib.c

I get an error:

/usr/include/bits/socket.h:345:24: fatal error: asm/socket.h: No such file or directory

What can I do to compile a code with #include <sys/socket.h> on 64 bit for 32 bit linux?

Роман Коптев
  • 1,555
  • 1
  • 13
  • 35
  • See this comment: http://stackoverflow.com/questions/16496635/fatal-error-sys-socket-h-no-such-file-or-directory-on-32bit?rq=1#comment23677965_16496635 – alk Mar 03 '16 at 07:10
  • Also see this answer: http://stackoverflow.com/a/1272420/694576 – alk Mar 03 '16 at 07:15
  • [THIS](http://unix.stackexchange.com/a/208594) may help – LPs Mar 03 '16 at 07:31

1 Answers1

2

You need to provide the path of asm. Just check the path and link like this. Depending on system path may vary. Most of the time downloading gcc-multilib solve this issue.

$cd /usr/include
$sudo ln -s asm-generic/ asm

OR

$cd /usr/include
$sudo ln -s x86_64-linux-gnu/asm asm
Rocoder
  • 1,083
  • 2
  • 15
  • 26
  • @alk I think he is facing path issue. It may resolve the problem. – Rocoder Mar 03 '16 at 07:11
  • The is a *cross* compile question. I for example doubt the x64 assembler snippets would help to compile 32bit programs – alk Mar 03 '16 at 07:11
  • @Rocoder It compiles and seems working, but I don't sure yet if it works correct – Роман Коптев Mar 03 '16 at 07:26
  • It may work after installing 32 bit library and will have to mention full path. – Rocoder Mar 03 '16 at 07:27
  • @Rocoder I have gcc-5-multilib installed. I can't install gcc-multilib, it will delete all crosscompilers. But with `sudo ln -s x86_64-linux-gnu/asm asm` I have comiled th library. It is linkable to 32 bit application on my system and do the staff. May be on real 32 bit it will not work. – Роман Коптев Mar 03 '16 at 07:55
  • @РоманКоптев I have gcc version 5.2.1 20151010. and i faced same issue while compiling the server code using -m32. I updated gcc-mulitlib it started working. you may try this command to get the arch info `file mylib.so`. – Rocoder Mar 03 '16 at 09:03
  • See https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1300211 for how this is a multilib/multiarch issue with (currently) no clear correct solution to support both. – proximous Jun 23 '17 at 17:26