[Vm-dev] [Off-Topic] linking exported symbols into shared lib

Ben Coman btc at openinworld.com
Mon Nov 6 18:30:24 UTC 2017

Whoops, I was only half way through composing that.

I hope you don't mind my seeking on expertise here in C library linking.
I've exhausted my search-fu and this is the place people know me.  I hope
my question is low level and generic enough that what I learn could be
useful later working on opensmalltalk-vm.

PDFium is a component of Chromium/Chrome for rendering PDFS.  By default it
only builds a static library, but I found a configuration option to builds
shared library, but it seems it misses some symbols.  Now the object file
remain available and I found the required symbol exported from them. For

$ nm -A fpdfview.o | grep FPDF_Init
fpdfview.o:0000000000000000  T   FPDF_InitLibrary
fpdfview.o:0000000000000000  T   FPDF_InitLibraryWithConfig
fpdfview.o:0000000000000000   t   FPDF_InitLibraryWithConfig.part.47

IIUC, the capital "T" means the "FPDF_InitLibrary" symbol is exported and
available for another program to link against. Browsing the web, it seems
like object files can be composed into a shared library like this...

$ gcc -fPIC -shared -o libmypdf.so fpdfview.o

but I end up with the "FPDF_InitLibrary" hidden as an internal symbol...

$ nm -A libmypdf.so | grep FPDF_Init
libmypdf.so:0000000000003e60  t   FPDF_InitLibrary
libmypdf.so:0000000000003e80  t   FPDF_InitLibraryWithConfig
libmypdf.so:00000000000031f0   t   FPDF_InitLibraryWithConfig.part.47

 so I can't link my test code against it

Here is my makefile...

INC_DIR= -I ./public
LIB_DIR= -L ./out
STD_LIBS= -lpthread -lm -lc -lstdc++
PDF_LIBS= -lmypdfium
        gcc -o test test.c ${INC_DIR} ${LIB_DIR} ${PDF_LIBS} ${STD_LIBS}

Now I know the library is found, since if I change its name the linker
complains it can't find the file.

I don't think the following adds useful extra info, but for completeness...
The header file fpdfview.h has...

#if defined(_WIN32) && defined(FPDFSDK_EXPORTS)
// On Windows system, functions are exported in a DLL
#define FPDF_EXPORT __declspec(dllexport)
#define FPDF_CALLCONV __stdcall

#ifdef __cplusplus
extern "C" {


#ifdef __cplusplus

cheers -ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20171107/7994769c/attachment-0001.html>

More information about the Vm-dev mailing list