问题
I am trying to create an executable with .o ,.so, .a files.
Here is my build command:-
pkgs/gcc/v4.8.3/bin/gcc -L/usr/X11R6/lib -O2 -DUSE_FLEX -Wall -Wno-char-subscripts -fPIC -DLINUX -DG_DISABLE_CONST_RETURNS -fno-strict-aliasing -o ../build/kl/Release/test/bin/pure.exe -L../build/kl/Release/test/modules ../build/kl/Release/test/maker/constrfunc.TCL.o ../../build/kl/Release/test/maker/pvdbprocs.TCL.o .. ../build/kl/Release/test/maker/maker/memmaker.TCL.o .. ../build/kl/Release/test/maker/modules/libdenbase.a .. ../build/kl/Release/test/maker/guibase.o -litk3.2 -litcl4.0.0 -ltk8.3 -lcdnviptcl8.4 -litclstub4.0.0 -ldenbase -lglib-2.0 -ldenbase -lX11 -ldl -lm -lviputil -lvippli -lcdsCommonMT_sh -lpthread -L/home/dlb/extlibs/arm/lib
I have libraries which have definitions of the functions at path "-L/home/dlb/extlibs/arm/lib" . Still it is throwing error below.
Error:
../build/kl/Release/test/maker/guibase.o: In function `decodeAddrList':
tree234.c:(.text+0xc): undefined reference to `ptritclStubsPtr'
tree234.c:(.text+0x20): undefined reference to `ptrlitclStubsPtr'
tree234.c:(.text+0x12c): undefined reference to `ptrlitclStubsPtr'
tree234.c:(.text+0x140): undefined reference to `ptrlitclStubsPtr'
I have the symbol in library which is at path /home/dlb/extlibs/arm/lib :-
Command:-
readelf -s libitcl4.0.0.so | grep ptrlitclStubsPtr
348: 0000000000060f10 8 OBJECT LOCAL DEFAULT 24 ptrlitclStubsPtr
Am I missing some thing here?
Note, OP has provided more info in a repost of the same question;
quote from comment by OP:
"Due to some privacy issues...I am renaming the symbols.. It was edited by me... It was typo...I just corrected it...:)"
I.e. the identifiers in the error message and the grep line and the output of the grep line have been manually altered.
回答1:
It looks like the functions you're asking about are local to the file where they were defined. That is, it looks like they were explicitly intended not (and not even allowed) to be called externally.
That is, somewhere within the source for the shared library libitcl4.0.0.so
probably appears a declaration like:
static tclStubs *ptrlitclStubsPtr;
That keyword static
indicates that the visibility of the resulting symbol ptrlitclStubsPtr
is confined to its own source file.
I infer all of this from the fact that your reported readelf
output includes the line
348: 0000000000060f10 8 OBJECT LOCAL DEFAULT 24 ptrlitclStubsPtr
That flag LOCAL
indicates that the symbol is local. If it were global, intended (and able) to be called externally, the flag GLOBAL
would appear instead.
Why are variables made private (static
) like this, so you can't use them? It's a software engineering thing, "information hiding", intended to reduce the "width" of the interface between you and a library like libitcl4
. Symbols that are private are more intimately tied to the implementation decisions within libitcl4
, decisions which are not supposed to be visible to, or any concern of, the callers. It's thought that, if callers were to have access to those symbols, callers would also have to know other implementation details, meaning that the author of libitcl4
would then be unable to change those implementation details without breaking (invalidating) the calling code. So to prevent that situation, the choice is usually made to make it impossible for the caller to become dependent in this way.
In this situation you basically have three paths forward:
Remove the
static
tags from the variable declarations in the sources tolibitcl4.0.0.so
. (This obviously requires that you have access to the sources tolibitcl4.0.0.so
, and the ability to rebuild it. It's also probably a very bad idea. As I've explained, those symbols were probably made static for a good reason.)Add a new function within
libitcl4.0.0.so
which does whatever you need done, and which, by virtue of its placement within the same source file, does have access to those symbols. (This, too, requires that you have access to and the ability to rebuild ``libitcl4.0.0.so`.)Find some other way of doing whatever you need done, using the existing public facilities of
libitcl4.0.0.so
.
来源:https://stackoverflow.com/questions/50445789/undefined-reference-to-function-issue-even-after-linking-the-library-which-has