1

I'm trying to install a C library: ssht

I've set up the makefile and it's definitely finding the dependencies. When I make it using gcc, however, I get some warnings:

In file included from ../ssht/src/c/ssht_core.c:23:0:
../ssht/src/c/ssht_core.c: At top level:
../ssht/src/c/ssht_sampling.h:39:20: warning: inline function ‘ssht_sampling_ind2elm’ declared but never defined
extern inline void ssht_sampling_ind2elm(int *el, int *m, int ind);

And then when I make the test for the code I get the error:

"_ssht_sampling_elm2ind", referenced from:
  _ssht_test_gen_flm_complex.constprop.1 in ssht_test.o
  _ssht_test_gen_flm_real in ssht_test.o
  _ssht_test_gen_lb_flm_real in ssht_test.o
  _ssht_test_gen_flm_complex in ssht_test.o
  _ssht_test_gen_lb_flm_complex in ssht_test.o
  _main in ssht_test.o
  _ssht_core_mwdirect_inverse in libssht.a(ssht_core.o)
  ...
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [../ssht/bin/c/ssht_test] Error 1

I've haven't been able to find any solutions that I could understand. By the way my gcc version is:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin14.4.0/5.1.0/lto-wrapper
Target: x86_64-apple-darwin14.4.0
Configured with: ../gcc-5.1.0/configure --enable-languages=c++,fortran
Thread model: posix
gcc version 5.1.0 (GCC)

I've tried installing as a 32 bit installation with -m32 to see if that changed things, but I get the same error with i386 instead of x86_64.

I have installed it on a Linux machine that I also have access to with a makefile which is identical except for the location of one of the dependencies.

Please help!

ben thorne
  • 61
  • 5
  • how does `ssht_sampling_ind2elm` looks? – ead Jul 20 '16 at 14:30
  • 1
    @ead the function is just this: inline void ssht_sampling_elm2ind(int *ind, int el, int m) { *ind = el * el + el + m; } – ben thorne Jul 20 '16 at 15:22
  • Maybe you should build with GNU89 (I guess now it is building C99). See http://stackoverflow.com/questions/216510/extern-inline/216546#216546 – ead Jul 20 '16 at 15:29

1 Answers1

1

It appears that the code is broken, and the warning that you present is indeed a good clue. The standard specifies:

For a function with external linkage, the following restrictions apply: If a function is declared with an inline function specifier, then it shall also be defined in the same translation unit. If all of the file scope declarations for a function in a translation unit include the inline function specifier without extern, then the definition in that translation unit is an inline definition. An inline definition does not provide an external definition for the function [...].

[C2011, 6.7.4/7]

The warning signals a violation of the cited restriction: the header file indicated in the warning contains the given function declaration, which bears inline and extern specifiers. Because of the inline specifier, C requires that every translation unit in which that declaration appears also provide a definition; since it appears in a header file, that applies to every source file that includes that header. File ssht_core.c includes the header but does not provide a definition.

Examination of the source shows that the designated function is defined only in file ../ssht/src/c/ssht_sampling.c, but that that file does not include the corresponding header. When a C source file has a corresponding header, it is customary and useful for it to include that header, for that helps catch discrepancies between declarations. It is not obligatory to do so, however, so that omission is not wrong in itself.

In this case, however, the only declaration of ssht_sampling_ind2elm() in ssht_sampling.c is its definition, and that bears an inline specifier without extern. The second part of the above-quoted section of the standard therefore applies: the translation unit corresponding to that file does not provide an external definition of the function. That is, the definition it provides is only visible from within the same translation unit, not from others, such as the one associated with ssht_core.c.

The intention appears to be to provide a function definition in one file that can be inlined in other files, but that is not allowed, nor does it really make sense. I'd file a bug report with the library's author. One possible resolution would be to make ssht_sampling.c include its own header; that would not resolve the warning, but it ought to fix the linkage problem. You could clear the warning by also removing the inline specifiers from the function declaration in the header. Alternatively, you could remove the inline specifiers from the function in both the header and the main source, without changing which headers are included in which file.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
  • Thank you very much for the detailed response, this fixes the warnings and error! I will file a bug report with the author. – ben thorne Jul 20 '16 at 15:49
  • Removing `inline` is definitely the wrong fix, because it's a trivial function (the OP copied the definition in a comment). Instead, move the definition into the header, where all users of the function can see the definition instead of just the prototype. – Peter Cordes Jul 21 '16 at 08:10