2

While building a C++ project, we have serveral targets: 32 and 64 bits.

On some 64 bit machines, while building 32 bit target we are getting a failures because g++-multilib is missing:

/usr/include/features.h:374:25: fatal error: sys/cdefs.h: No such file or directory 

My question is this:

What is the best way to query if the current machine is able to generate a 32 bit image, in terms of compiler and glibc packages installed.

One solution could be, for example, generating a simple C file that contains multiple glibc includes and see if I am able to compile the mock file.

This does not seem the elegant solution.

Instead, I would like to query the machine to see if all the nesscary packages are installed.

P.S:

We are using WAF as a build infrastructure.

Thanks,

Itay

Itay Marom
  • 801
  • 6
  • 15
  • Maybe [this](http://serverfault.com/questions/54736/how-to-check-if-a-library-is-installed) will help? – Glapa Sep 02 '15 at 07:35

3 Answers3

5

checking for the existence of a given package is usually not a good idea, as it relies on specific distributions (e.g. Fedora) and specific package names (e.g. libc6-dev-i386); other distributions (or other versions of the same distributions) will have different package names and tools to interact with the package manager (e.g. apt vs rpm vs ...)

the well-established autotools way is to run tests for the things that you actually need (e.g. include a given header file) rather than check for things that might provide the things you need (e.g. a certain package)-

e.g. if your actual code requires to include features.h, then you should test (in a pre-build step) whether it is possible to include this file without errors.

the following autotools example will stop with an error if features.h cannot be used; which allows the user to fix the problem by installing the correct packages (e.g. as hinted in your README) before starting a time-consuming build process.

 #snippet from configure.ac
 #stop configure process if we cannot use foo.h
 AC_CHECK_HEADERS([foo.h],,AC_ERROR([cannot include foo.h - try installing libfoo-dev])

if instead of failing the configure step you would rather simply disable parts of your build, you might want to do something like this:

configure.ac:

 have_bar_h="no"
 AC_CHECK_HEADERS([bar.h],[have_bar_h="yes"])
 AM_CONDITIONAL([BAR]) [ test "x${have_bar_h}" = "yes" ]

and Makefile.am

 if BAR
 # only do the 32bit build if we have bar.h
 bin_PROGRAMS+=coolapp32
 ebduf

sorry that this answer is very autotools specific, but i'm sure that waf has similar ways; check the section about Configuration helpers in the WAF documentation.

umläute
  • 28,885
  • 9
  • 68
  • 122
0

It might help,

try to install libc6-dev-i386 on your machine which is Embedded GNU C Library: 32-bit development libraries for AMD64.

MKR Harsha
  • 105
  • 9
0

You would like to query the machine to see if all the necessary 32 bit packages are installed...

rpm -qa --queryformat 'libc6-dev-%{ARCH}\n' | grep 'i[6543]86' | cut -d' ' -f1
user1
  • 4,031
  • 8
  • 37
  • 66