I am trying to compile a piece of code that links several source files with a shared library. This is to avoid a name conflict with a function named Log in both the source code and shared library.
The signature in my source code is Log(int, char *, char *, ...) and the signature in the shared library is Log(int, int, char *, ...)).
The code needs to be built for different targets. When built using gcc-5.4.0 (Ubuntu 16.04), there is no conflict and the shared library correctly calls the Log function from the shared library. However when building on gcc-4.9.2 for armhf (BeagleBoneBlack), the shared library calls the Log function in my source code which is incorrect.
Specifically, the output of the nm command applied to the executable generated using gcc-4.9.2 shows the first entry in the dynamic symbol table as follows:
$ nm -D <filename>
00017590 T Log
.....
This entry for Log does not appear when compiling with gcc-5.4.0.
I have tried using objcopy for substituting the Log symbol name while the .so file is generated, but that doesn't work.
Is there some setting or flag in the Makefile that needs to be added so that any version of gcc should not add the Log function to the dynamic symbols of my final executable? Or is there something else that I am missing here?
Reproducing the Makefile settings:
CFLAGS=-fPIC -MMD -Wall -std=c99 -D_GNU_SOURCE -g -Werror=implicit
CPPFLAGS=-Iinclude
CFLAGS+=-Os -fdata-sections -ffunction-sections -flto
CPPFLAGS+=-Os -fdata-sections -ffunction-sections -flto
LDFLAGS=-Os -Wl,--gc-sections -flto