Custom Search

Tuesday, December 18, 2007

Resolving unresolved symbol error in Linux shared libraries

Frequently we used to come across a case in which when we create shared libraries on a Linux box and try dynamic loading using 'dlsym' methods - the load fails with unresolved symbols error.

InformIT hosts a wonderful article on the different techniques on resolving these errors.

Option 1:

"To generate an executable that exports all of its functions and variables dynamically, specify the compiler flag -Wl,-export-dynamic when you link your executable"

Option 2:

"Your main executable may load other shared libraries at runtime, using dlopen. By default, they cannot see each other's dynamic symbols. You can make these libraries' symbols visible to each other by specifying the bitwise or of the value RTLD_GLOBAL in the second argument to dlopen."

Specifically I like Option 1 as it makes me aware of the linking going. RTLD_GLOBAL seems too generic to me.

No comments: