Building C Shared Library gives undefined symbol

Why creating a static library (.a) does not give errors and works correctly:

$(LIBRARY): assertion.o
    $(AR) $(OUTPUT_STATIC_LIB_DIR)/$(LIBRARY) $(OUTPUT_DIR)/assertion.o

      

At the same time, when creating a shared library (.so), the following error occurs:

$(SHARED_LIBRARY): assertion.o
    $(CC) $(CFLAGS) -shared -o $(OUTPUT_LIB_DIR)/$(SHARED_LIBRARY) $(OUTPUT_DIR)/assertion.o

      

Error message:

Undefined symbols for architecture x86_64:
  "_float_cmp_func", referenced from:

      

+3


source to share


1 answer


Your library code refers to "_float_cmp_func", which you need to find at runtime.

But a static library is not expected to be a sufficient binary, it is just a collection of object code that is intended to be included in subsequent build / reference steps (along with other object code and libraries).



In contrast, a shared library is a "ready-to-use" binary, so its dependencies must be resolved at the linking stage. Thus, in this case, you must add some module (s) to your link level, where "_float_cmp_func" is implemented

0


source







All Articles