74444

Possible to statically link shared object libraries?

Question:

I'm building a library that needs to be dynamically linked to my project. The output is a .so file, so I think I'm on the right track. I'm concerned by the way it's being linked at compile time - by specifying the location of its makefile and depending on a bunch of macros, which I've never encountered before.

Can I assume that since I'm building a .so library (rather than a .a) that I'm in fact dynamically linking? Or is it possible for .so libs to be statically linked, in which case I need to rip apart the make/config files to better understand what's going on?

Thanks,

Andrew

Answer1:

I'm not familiar with internal structure of executables and shared objects, so I could only give some practical hints.

Assuming you use gcc, it should have -shared option when linking object files into library - this way ld (called by gcc) makes shared object instead of executable binary.

gcc -shared -o libabc.so *.o ...

When you link some application with this libabc.so it should link without errors and after that with ldd command you should be able to see libabc.so among its dependencies.

$ ldd app ... libabc.so => ...............

Recommend

  • How is a header file being compiled into the executable file?
  • Macro to call a function
  • GCC vs Microsoft : Undefined reference to `_chkstk'?
  • Index on every Foreign Key?
  • Disable check for override in gcc
  • Issue with std::thread when using g++ in 32-bit MinGW 4.8.0
  • Unable to use dot layout (graphviz as a library)
  • SCons libraries and sub-libraries
  • How do I obtain a list of files that changed from svn over a date range?
  • integrate POCO library in android ndk
  • Alamofire and Reachability.swift not working on xCode8-beta5
  • cordova is not defined - cordova.js has already been loaded :: Ionic
  • Hibernate to update table schema
  • jQuery: add elements until a particular height is reached
  • Combining two different ActiveRecord collections into one
  • Looking for good analogy/examples for monitor verses semaphore
  • Adjust width of select element according to selected option's width
  • WPF - CanExecute dosn't fire when raising Commands from a UserControl
  • How to use carriage return with multiple line?
  • How to match http request and response using Jersey ContainerRequestFilter and ContainerResponseFilt
  • Installing Apache MyFaces 2 on WildFly 8.2.0
  • Using jQuery closest() method with class selector
  • What is the “return” in scheme?
  • Array.prototype.includes - not transformed with babel
  • Running a C# exe file
  • Akka Routing: Reply's send to router ends up as dead letters
  • SVN: Merging two branches together
  • Invalid access key error using credentials redeemed from an amazon open id token
  • Numpy divide by zero. Why?
  • Circular dependency while pushing http interceptor
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • How do I rollback to a specific git commit
  • Is there a mandatory requirement to switch app.yaml?
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • What are the advantages and disadvantages of reading an entire file into a single String as opposed
  • Busy indicator not showing up in wpf window [duplicate]
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • UserPrincipal.Current returns apppool on IIS
  • Why do underscore prefixed variables exist?