Technical article 100781

I get a relocation error when loading my DLL using dlopen(S).

OpenServer 5.0.0

Written · Last revised

Problem

I have created my own Dynamically Linked Library (DLL) and I am using dlopen(S) with the RTLD_LAZY flag to open the library in a program.

When I run the program I get the error:

Error while loading <dll_name.so>: dynamic linker: test: relocation error: symbol not found: <symbol_name>

Cause

Your DLL was not built with Position Independent Code.

Solution

Compile your DLL using the -Kpic cc(CP) compiler switch as follows:

cc -o dll_name.o -Kpic -b elf -c dll_name.c
cc -o dll_name.so -G dll_name.o

where dll_name.c is the original Dynamically Linked Library source and dll_name.so is the position independent DLL.

From the Xinuos technical article database, record 100781. Reproduced with permission. The original is at www.sco.com/ta/100781, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.