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?
Related
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?
I am using Lua 5.3 as a Static lib in my application. I have a Lua module written as C Dll which also using Lua 5.3 as a static lib.
In the Loaded Module i am registering a function which returns a table of values. Table contains string as key and integer as value.
I am observing a random crash calling that function several times and the crash is showing on lua_gc.
I compiled lua as a dll with stub library and linked my application and the Lua Module using that. I don't observe crash after that.
So is it not recommended to have the Lua C module linking to Lua Statically?
Short answer is just do not do this.
Logn ansewer.
1. You have to be sure your that both Lua libraries compiled with same flags (alignment, base type sizes).
2. Memory allocator has to be shared. If one Lua static lib allocate buffer other should be able free it) (With MSVC link with same dynamic runtime.
Do not link with static msvcrt.lib).
Other depend on OS.
On Windows you can export Lua API from your application and link module DLL with this executable. (Ru SciTE team do this)
But again just link with dynamic Lua library.
Update
There exists one more variant.
You can statically link all needed Lua modules as whell.
So it should be safe.
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.
After searching I couldn't find any example that a LKM uses a static or dynamic libraries.
I want to create static and dynamic libraries (may be use standard C library or any other libraries), then develop a LKM that uses my own static and dynamic libraries.
How to link a LKM (loadable kernel module) to static or dynamic libraries?
I'm afraid you have a major misconception - Linux kernel modules cannot be linked with standard user space libraries, such as the C library, either static or dynamic. This is because the C library and the dynamic linker (that implements dynamic linking) actually calls the kernel to do its job.
You can write a static C library and link it to a kernel module and an LKML is actually a form of a kernel dynamic library. See the Documentation/kbuild/ directory for details
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.