Is it possilble to link .so file into .a file - gcc

Is it possilble to link .so file into .a file
A 3rd party only offer a so
Our .a lib depend on it.
And we don't want to give customer too much dependency

No, you can't convert a shared lib back to a static lib. There is information in the .o files that gets discarded when they are welded together into a .so file. If you really want static linking, you'll have to persuade the third party to also ship you an archive.

Related

Class library lib and dll files

To use class library I must have header file and lib file that I suppose contains compiled library code. So, why and when I need dll file? I have breath understanding that in case of dynamic linking I must use dll and in case of static linking there is no need to use dll.
You can have a library project or a DLL project. A DLL is good if it will be used by multiple exes. A lib is good if you want it to become part of an exe.
DLL projects generate both a DLL file and a lib file. The import lib file is very small and just contains a jump table so the exe can be compiled.
When your library is dynamic library i.e, .dll, .lib file have exports table. .h header file have function prototype.
Export table is table of all exported functions from dll.

Two different static libs with the same .obj file

I'm working with visual studio,
and I have two different static libs which share the same .obj file, but that .obj file is newer in one of them.
I need both of these libs so i can't exclude one of them,
How can I "make" the linker to take this specific .obj file from the static lib I want him to?
It's either that or i will have to add the .obj file every time he has been changed, cause it's location is based on the version number while the lib file is in a global location.
Unless there's other solution.

Should I include stdafx.h within my static library? What format should my library be?

I am creating a static library. I have gone through the win32 application, static library, no precompiled headers. The file is a .cpp I am assuming that I can export this to the actual .lib file, or is it suppose to be .lib from the start?
Also, I keep getting the cannot open source file stdafx.h, which I have included within my main static library .cpp file. Tell me, am I suppose to do this?
Thanks

Why do I need ILK, PDB and EXP files?

I have downloaded some dll files and with it came also pdb, exp and ilk files. Now I need to know do I need to put them in my system file, or not and what is the purpose of each of them in the general?
PDB files contain debug information and are useful if you need to step through the DLL's code at any point.
ILK files are used by the linker. They are not needed unless the DLL is to be recompiled.
EXP files contain information about things exported from the DLL
.ilk files are intermediary files created by the linker during the development cycle. .ilk files serve the purpose of incremental linking. If the linker does not find and .ilk file when trying to do incremental linking, then it will do a full linking and reproduce the .ilk file. Incremental linking is meant to speed up the linking process. You can safely delete .ilk files.
.exp files are for developers too. .exp files are created for .exe and .dll files that export some symbols. Their purpose is similar to .lib import libraries, but there is a subtle difference. .exp files are always created, even if the creation of the corresponding .exe or .dll fails at link time. By contrast, .lib import libraries are created only when the corresponding .exe or .dll linkage succeeds. .exp files help linking interdependent components. For example, an .exe might provide access to its common resources for its plugins by exporting some functions. The plugins also provide exports for the .exe to call. Interdependencies like this cannot be successfully linked. The .exe linkage will fail, because the import .lib for the .dll is missing. Consequently no .lib for the .exe will be created. The linkage of the .dll will fail because the import library for the .exe is missing. Export files however will be created even if linkage failed, so the .dll could link against the .exp file rather than the .lib file for successful linkage.

What do you need in a static library?

I want to try making a simple game engine. Just something that handles states, assets, characters/actors and their stats and an inventory. Most of the code I can take from other games I've wrote, but I'm confused on how I then turn it into a static library. Do I need a main.cpp? If so what has to go in it? Under Linux I'm guessing I compile it to .so and add the headers to my include directory and then just link to the .so but what do I do on Windows and Mac?
A .so is not a static library, it's a dynamic one. A static library is, in its most basic, a .o file compiled from a single C file, or a .a file which is simply a collection of .o files.
A static library is different from a shared one in that the object code is linked directly in to the final executable, requiring no dependencies at run time.
Under Unix, the ar(1) command is used to bundle .o files in to a composite .a file. I do not know the comparable utility for Windows.
Once you have the .a file, you will simply need the combination of the .a file and the .h files to build your code. You use the .h files for compiling, and then link against the .a file.
Shared libraries have a specific advantage over static libraries in that if you have multiple, yet different, programs relying on the same libraries, the code from the shared libraries can be shared among all of the programs at the same time, so in that sense they lower the overall impact on the system. Their downside is slower start up times (though that's pretty marginal nowadays). Statically linked libraries can not be shared across independent programs, but if you run the same executable several times, its code will be shared.

Resources