static lib global value got reset after call from DLL - c

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.

Related

How to check if a static library is linked properly?

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?

Using Lua as a Static lib in Application and a Lua Load module

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.

Partial Linking in IAR for ARM for Hiding Symbols

I want to distribute a static library which consists of many source files and therefore, when compiled, consists of many object files. Within the object files there are some static functions and some functions which are not static. The non-static functions are needed because functions in one object file may need to be called from other objects.
I have one of the objects which is basically the API into the library and it has an associated header file which the application developer would include in their project in order to use the library. I want the symbols in that header file to be the only ones exposed to the application using the library.
I use IAR to compile my code into .a file, then include the public API header into my application and link the .a to my application.
The problem is that the non-static functions in my library which are supposed to only be called by other objects in the library are visible to the application using the library. This is an issue if the application tries to define a function with the same name as one of my library's functions (by accident, coincidence or intentionally). I cannot make every function static (and therefore visible to only their compilation unit) because then that function would be unusable to the rest of the library.
Basically I want to hide symbols from the application who is using the library.
I have a way to fix this in Keil already which works:
In Keil, I can do partial linking by actually linking my library using the flags
-ldpartial --privacy --no_locals --no_comment_section
and by providing a steering file through the option
--edit=steering.txt
to selectively choose what symbols I show and hide.
Example of a steering file:
HIDE *
SHOW my_public_func1
SHOW my public_func2
Is there any way to do this in IAR. I.e. is there a way to partially link a library and then link that library into an application.
What I have tried: https://www.iar.com/support/tech-notes/linker/hiding-symbols-from-a-library-using-isymexport-with-a-steering-file/
This is a good idea, but it requires loading my library separately onto the device when what I want to do is link it right into the application. Ideally, I would want to link the generated .out file from the above iar.com link into the application instead of loading it separately.

Call static lib function embedded in DLL

Let's say the following architecture:
A static library is used/linked within a DLL
The DLL is loaded (either implicitly or explicitly) by an executable
Is it possible from the executable code to access code of the static library without relinking it explicitly nor inserting wrapper functions in the DLL?
In other terms, I am looking for a way to make a dll export of dependant static library code.
Given your constraints, the answer is no.
The reason is that the executable doesn't have any visibility into the dependencies or "call-ees" of the DLL. As far as the executable is concerned, he's just knows about the DLL itself: at link time, the executable knows only about those exports it is consuming from the DLL. He's going to LoadLibrary() against the DLL (which will fail if the dependencies of said DLL aren't resolvable), then call the exports of said DLL.
If you can't statically link with the library used by the DLL for some reason, another approach is to wrap the calls to said static library. This can be a pain of there are lots of calls, but there are automated tools which others have created to help. In particular I've used this before to create a wrapper for a DLL which exported hundreds of functions when I wanted to intercept a particular one: http://www.codeproject.com/KB/DLL/CreateYourProxyDLLs.aspx
The answer may easily be: Yes.
The only requirement is:
In your static LIB file you must define __declspec(dllexport) for all what you want to export.
When you then include this LIB file into your DLL project all the functions that you have declared as __declspec(dllexport) will be automatically DLL Exports and can be accessed from your Exe.

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.

Resources