How to check if a static library is linked properly? - linker

I think I'm linking an external static library properly to my team's codebase, but I am running into undefined reference to... errors (to functions defined in the static library). I'm not well versed with the build system, so I'm not positive it is linked properly.
Is there a way to check from the executable if a static library is linked?

Related

verify generated library for the encapsulation

I have two C projects prepared under Visual Studio 2015. First project is simply a static library project whereas the second one is a console application which uses the static library file generated by the first project.
I checked the static library file with DUMPBIN tool in Windows and saw that there are many variables and functions exposed to outside which is very bad for the encapsulation issues.
My question is how can I be sure that I don't expose the functions which are supposed to be private. Do I need to check every time with that tool? My question is also covering the variables. All my static global variables are also exposed to outside. How can I force them to be private?
I don't think that presence in dumpbin output can be considered an "exposing". All your static global variables require some space allocation and probably an initialization at runtime. So it's only natural for them to be present in dumpbin output. Also if you are compiling with link-time code generation then everything is actually "exposed".

Program linked against libraries that share symbol names runs wrong implementation

This a bit difficult to understand but I'm doing my best.
On Red Hat 6.4 with gcc 4.4.6 & ld 2.20.51,
I am linking into a binary executable PROGRAM code from one shared library (.so) and a static library (.a).
The shared library exposes an API invoked directly by PROGRAM. The implementation of this shared library is compiled & linked against a static library static lib1.
The static library also exposes its own API which is invoked directly by PROGRAM. And some of its implementation is based on a subset of the static lib1's files that were copied directly into it.
None of the APIs (of either library) actually expose a data type or a function implemented by static lib1.
Because the code was copied the symbols are identical.
During runtime I see this behaviour:
If the order of libraries to the linker is shared library, static library, then calls to the shared library API and calls to the static library* API will both use the implementation in the **static lib1.
If the order of libraries to the linker is static library, shared library, then calls to the shared library API and calls to the static library API will both use the implementation in the static library 1 - code from lib1 modified.
How do I get all calls to the static library API to run the implementation in code from lib 1 modified and those in the shared library API run the implementation in static lib1?

static lib global value got reset after call from DLL

I have c++ libary in wince 6.0, There is some global variable. that libary has been linked with DLL which is c++. when i exected application and called DLL. first its intilized all global variable of static libary but when control come back to DLL to static lib. Its reset all glbal value. Do anyone have idea about that.
If you have linked two DLLs with the static library, this means that you have two copies of all the code and variables in the library.
To solve this issue you should convert the static library into a DLL. This can be done with a simple project consisting of a module.def file, and a linker call.
Then instead of linking your DLLs with the static library, link them with your DLL.
Alternatively, instead of having two dlls, combine the project to have a single DLL.
Note that it can be OK to link two modules with the same static library, provided that you understand and accept that the data will NOT be shared.

How do I change all shared libraries used in my programe to static libraries in windows?

The shared library is causing much trouble for me, and disk space is far less expensive than the trouble itself.
How can I convert all shared libs(.dll) to static libs(.lib) and make my programe use them instead of using shared libs?
Note some .dlls are not directly refered to by my programe,e.g. my programe requires libpng,and libpng requires zlib.dll.
Is there a solution that wraps up all these cases?
You cannot convert a shared library (dll) to a static library (lib). The dll contains headers, exports, and such things that make it completely impossible to do.
If you have access to the source, you can usually recompile it as a static library. Otherwise, you will have to get your hands on the static library yourself.
There is no practical way to convert DLLs to static libraries. You will either need to find the actual static libraries, or you will need to build them from source.

Linking against multiple shared libraries that all linked against a common static library

Say you have 2 share libraries, lib1.so and lib2.so, that both have libcommon.a statically linked into them. Would the compiler complain about ambiguous symbol reference if you were to dynamically link both lib1.so and lib2.so? Or would be the compiler be smart enough to know libcommon symbols are shared between lib1 and lib2 and allow you to dynamically link against both?
There won't be a conflict because when you link to shared libraries, the linker will use the definition from the first shared library which provides the symbol and won't look further at the other shared libraries. Symbols included from the .a will be exported in both shared libraries but won't conflict.
The static library would be used to resolve the links internally but the external linkage would not be propagated to the shared library interface, so there would be no conflict. Each shared library would include its own copy of the static library code.
Suppose the two shared libraries linked with the different static libraries. But the static libraries both contain a function with the same name. There would be conflict.
I'm sure of that because I have a tcl/tk application, it load two tcl libraries(.so). Both of the libraries are static linked with the openssl library. but with different version.
A segmentation fault occurred when I run the tcl application. I trace it into the openssl. There is a function implementation changed in the new version.

Resources