4

I have a static C library libex.a that uses sscanf. Library was compiled using -std=c99

I want to use the library function in some C++ code that I am compiling using -std=c++11, but I get the following error:

lib/libex.a(srcfile.o): In function `my_function':
/srcpath/srcfile.c:215: undefined reference to `__isoc99_sscanf'

After poking around a bit, I have discovered that sscanf has issues with versions due to a backwards compatibility hack, hence the redirect to __isoc99_sscanf, so I suspect that is somehow the source of the problem. However, I checked my version of glibc and it looks recent enough that the solution suggested elsewhere (update your copy of glibc to at least 2.7) isn't helpful.

$ ldd --version
ldd (Ubuntu EGLIBC 2.19-0ubuntu6.6) 2.19

Any suggestions?

Of course, let me know if there's any additional information that would be relevant.

Thanks!

UPDATE: If I compile libex.a with -D_GNU_SOURCE the error message is changed to undefined reference to sscanf. Not sure if that will help figure out what's going wrong.

EJane
  • 53
  • 1
  • 6
  • the C++ compiler 'mangles' function names. The library, created in C, does not have mangled function names. What header files are you including in your C++ source code? Do those headers from the C language have the needed `extern "c" { ... wrappers? so they can be used in C++? – user3629249 Aug 31 '16 at 23:05
  • Yes. All headers are wrapped with extern "C" – EJane Aug 31 '16 at 23:18
  • 1
    It'd help if you could make a minimal code example, and give the exact build commands for the library and the c++ program – M.M Sep 01 '16 at 00:51
  • Good point. While trying to construct a minimal example, I was able to work out what was going on. (C++ code was linking to a nonstandard version of stdio.h that didn't support scanf). Thanks! – EJane Sep 01 '16 at 18:31
  • Also see question: http://stackoverflow.com/q/3660826/39648 – Sandeep Datta Feb 20 '17 at 08:45

1 Answers1

1

In case anyone else runs into this problem:

The Makefile for the C++ code disabled the standard libraries and start files using flags -nostdlib -nodefaultlibs -nostartfiles. It instead linked to the version of stdio.h included in the Intel SGX SDK for running inside enclaves. That version deprecates sscanf.

EJane
  • 53
  • 1
  • 6