0

I'm having trouble building a project that attempts to check for the presence of shm_open and shm_unlink. The relevant lines of configure.ac are:

# Avoid adding rt if absent or unneeded
AC_CHECK_LIB(rt, shm_open, [EXTRA_LIBS="$EXTRA_LIBS rt" CFLAGS="$CFLAGS -lrt"])

# needs -lrt on linux
AC_CHECK_FUNCS([shm_open shm_unlink])

The AC_CHECK_LIB line succeeds, however AC_CHECK_FUNCS fails for both. Looking in config.log, I see

configure:4133: checking for shm_open in -lrt
configure:4158: /usr/bin/gcc -o conftest  -fno-stack-protector         -Wl,--hash-size=31 -Wl,--reduce-memory-overheads   conftest.c -lrt   >&5
configure:4158: $? = 0
configure:4167: result: yes
configure:4178: checking for shm_open
configure:4178: /usr/bin/gcc -o conftest  -fno-stack-protector    -lrt      -Wl,--hash-size=31 -Wl,--reduce-memory-overheads   conftest.c  >&5
/tmp/ccg0yu56.o: In function `main':
conftest.c:(.text+0xa): undefined reference to `shm_open'
collect2: ld returned 1 exit status

It appears that the only difference between the two checks is the position of the -lrt argument. When I try running gcc on a simple file manually, I get the same behavior, i.e. linking succeeds only when -lrt comes after the source file input.

So, what do I need to do so configure will determine that shm_open and shm_unlink exist? I suspect this is something particular to my system, as the project I'm configuring is pretty widely used (the unix package bundled with the ghc compiler), and it used to work (when I built this package on a different system with gcc-4.4.5, it worked, however that environment is no longer available). My preferred solution would be either a change to the system/environment or some combination of flags to configure, however if there's a standard modification for configure.ac that I could send upstream, that's acceptable also.

I've tried various combinations of CFLAGS and LDFLAGS, but the -lrt flag always appears before the input file, so the check still fails.

My system is Ubuntu 12.04 (precise)

$gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
$ uname -a
Linux hostname 3.2.0-26-generic #41-Ubuntu SMP Thu Jun 14 17:49:24 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

Thanks!

John L
  • 27,937
  • 4
  • 73
  • 88

1 Answers1

0

Macro have full form:

AC_CHECK_LIB (library, function, [action-if-found], [action-if-not-found], [other-libraries])

Please note other-libraries. This option is useful specifically for cases you described -- to pass -lm, -lrt and other common guys to avoid unresolved references in linker ordering.

Check doc page for more information on AC_CHECK_LIB macro

Konstantin Vladimirov
  • 6,791
  • 1
  • 27
  • 36
  • Thanks, but unfortunately this is insufficient. `AC_CHECK_LIB` works because it's testing for librt. The following call to `AC_CHECK_FUNCS` then fails. It gets called with `-lrt`, but the flag is too early. – John L Feb 19 '13 at 01:18