static-libraries

Can I build a shared library by linking static libraries?

做~自己de王妃 提交于 2019-11-28 23:32:10
I have a bunch of static libraries (*.a), and I want to build a shared library (*.so) to link against those static libraries (*.a). How can I do so in gcc/g++? You can (just extract all the .o files and link them with -shared to make a .so ), but whether it works, and how well it works, depends on the platform and whether the static library was compiled as position-independent code (PIC). On some platforms (e.g. x86_64), non-PIC code is not valid in shared libraries and will not work (actually I think the linker will refuse to make the .so ). On other platforms, non-PIC code will work in

Loading time for shared libraries vs static libraries

天涯浪子 提交于 2019-11-28 23:24:02
问题 I have a question on shared libraries vs static libraries loading time. Assume that i have a executable foo.exe which uses liba, libb, libc. Also at a given time there are more than 10 instances of the executable running on the machine. Now if the above 3 libraries were shared libraries : 1st Insance is loaded into RAM : The time taken will be time taken by main() of foo.exe to be loaded memory (assuming its negligible) + time to load liba + time to load libb + time to load libc 2nd instance

static library, but I still need headers?

放肆的年华 提交于 2019-11-28 23:05:27
I have a bunch of projects that all could share a "common" static library of classes. What confuses me is if I make a static library out of these classes and link against it in my projects that I still need the headers of the classes in the static library in my main projects. What is the benefit of the static library then? How do companies like Adobe deal with this? Static libraries allow you to create a library and use that library in many projects. The need for header files: Since the project using the library is programmed and compiled independent of the library, that program needs to know

“undefined reference” when linking against a static library

◇◆丶佛笑我妖孽 提交于 2019-11-28 22:51:39
g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5 I have the following static library called sdpAPI.a. I am having problems trying to link it with my test application. Just wondering if I am doing something wrong. The static library has been built with g++; My directory is as follows: /projects/unit_test/main.c /projects/unit_test/sdp/inc/sdpAPH.h /projects/unit_test/sdp/lib/sdpAPI.a My source code is this: #include <stdio.h> #include "sdpAPI.h" int main(void) { printf("----- TEST SDP ------\n"); try { sdpSessionDescription sdp; sdp.clear(); } catch(...) { printf("----- TEST FAILED --------\n");

What is the difference between .LIB and .OBJ files? (Visual Studio C++)

此生再无相见时 提交于 2019-11-28 22:49:15
I know .OBJ is the result of compiling a unit of compilation and .LIB is a static library that can be created from several .OBJ, but this difference seems to be only in the number of units of compilation. Is there any other difference? Is it the same or different file format? I have come to this question when wondering if the same static variable defined in two (or more) .LIBs is merged or not during linking into the final executable. For .OBJs the variables are merged. But is it the same in .LIBs? A .LIB file is a collection of .OBJ files concatenated together with an index. There should be

Static library loaded twice

一个人想着一个人 提交于 2019-11-28 21:59:59
I have shared object A.so which statically links to libssl.a & another shared object B.so which also statically links libssl.a . A.so & B.so has symbols from libssl.a in GLOBAL scope. I checked this by readelf -s A.so I have an executable a.out which loads A.so and B.so. When a.out terminated I get a double free error in one of the symbols from libssl.a in A.so. Even though libssl.a is statically linked to each shared object, since they are exposed globally is it possible that the same symbol is shared instead of picking it's local copy. What is the workaround this ? How to make the symbols

Proper way to link a static library using GCC

江枫思渺然 提交于 2019-11-28 21:11:08
问题 Why is it that some static libraries (lib*.a) can be linked in the same way that shared libraries (lib*.so) are linked (ld -l switch), but some can not? I had always been taught that all libraries, static or not, can be linked with -l..., however I've run into one library so far (GLFW), which does nothing but spew "undefined reference" link errors if I attempt to link it this way. According to the response on this question, the "proper" way to link static libraries is to include them directly

CMake: How to create alias for installing different targets?

你。 提交于 2019-11-28 20:48:16
Suppose that I've got the following libraries: add_library(myLib_static STATIC ${SRC_FILES}) add_library(myLib SHARED ${SRC_FILES}) # installing header files install(FILES ${H_FILES} DESTINATION ${INSTDIRHEADER}) # installing binaries install(TARGETS myLib_static DESTINATION ${INSTDIRBIN}) install(TARGETS myLib DESTINATION ${INSTDIRBIN}) If I execute the following command, both shared and static libraries will be installed: make install How can I have separate install commands for each of them? Something like this: make install-static make install-shared Update : Header files should also be

Hiding symbol names in library

孤者浪人 提交于 2019-11-28 19:00:24
I want to hide symbol names which are not relevant to the last user and make visible only APIs in my shared or static library. I have a simple code like that: int f_b1(){ return 21 ; } int f_b3(){ return f_b1() ; } I applied the all methods stated here such as using __attribute__ ((visibility ("hidden"))) and static data but got no successful result. My operating system is Ubuntu and x86_64 GNU/Linux processor. Do we use special options while compiling with gcc? I am listing modules and function of libraries with nm command. In my example above I only want to make visible f_b3 function. When I

C++ global variable not initialized when linked through static libraries, but OK when compiled with source

旧城冷巷雨未停 提交于 2019-11-28 18:21:32
I have created a system that automatically registers function objects (functors) into a map based on the constructor of an global instance. In each cpp file that defines the functor, there's a global instance of the registrar class instance to register the functor to a singleton std::map<int, std::function<...> > object. This is the definition of registrar class: template < typename map_type, typename handler_type > struct registrar { registrar ( map_type& map_object, boost::uint16_t cmd_code, const handler_type& handler ) { map_object.insert(std::pair<boost::uint16_t, handler_type>(cmd_code,