0

I have a strange problem linking c++ with Leptonica. Normal function invocation works fine, but I need functions from the library which were originally not exposed in the .so library. So I have searched for the two interesting functions in the source, removed the static keyword, so they look similar to exposed ones. I have remade the full library after a make clean. The .so file looks OK:

nm liblept.so.5.0.0
...
000000000009d010 T dewarpGetMeanVerticals
000000000009d160 T dewarpGetTextlineCenters
000000000009d8f0 T dewarpIsLineCoverageValid

Compiling to .o file and observing it:

g++ -c -std=c++11 -I../leptonica/src/src/ preproc.cpp -L../leptonica/src/.libs/ -llept -o preproc
nm preproc
...
U dewarpGetMeanVerticals
U dewarpIsLineCoverageValid

While the same compiling without -c flag results in

/tmp/ccCPqS1R.o: In function `_dewarpGetTextlineCenters(Pix*, int)':
preproc.cpp:(.text+0x3d5): undefined reference to `dewarpGetMeanVerticals'
/tmp/ccCPqS1R.o: In function `_dewarpBuildPageModel(L_Dewarp*, char const*)':
preproc.cpp:(.text+0x81d): undefined reference to `dewarpIsLineCoverageValid'
collect2: error: ld returned 1 exit status

What do I do wrong?

Thank you in advance: Balázs

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
Bámer Balázs
  • 169
  • 1
  • 9
  • I notice that you're showing us what's in liblept.so.5.0.0 and linking against liblept.so. Is it possible that you need to update a symbolic link so that you're linking against the correct .so file? – cleblanc Jan 04 '17 at 20:53
  • `nm` is not the best tool here, try `readelf --dyn-syms -W`. – yugr Jan 04 '17 at 21:12
  • 1
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – too honest for this site Jan 04 '17 at 21:20
  • Have you made correct declarations of your newly-external functions visible to the client code? – John Bollinger Jan 04 '17 at 21:20
  • Sorry for the post, I have found the problem: there was an old instance of the .so in /usr/local/lib which I forgot. Removing it fixed the problem. Thank Cleblanc for the hint! – Bámer Balázs Jan 05 '17 at 08:28

1 Answers1

0

I think you may need the extern "C" keywords around those functions if you want to expose them in the so. Since the names don't appear to be mangled by the C++ compiler in the .so this is probably not the case.

I notice that you're showing us what's in liblept.so.5.0.0 and linking against liblept.so. Is it possible that you need to update a symbolic link so that you're linking against the correct .so file?

cleblanc
  • 3,678
  • 1
  • 13
  • 16