Duplicate Symbols with a static library - understand the duplicate symbol error message

844 views Asked by At

I'm integrating an external library in my iOS project. I get 11 duplicate symbols when I try to compile.

Here's an excerpt of the output:

duplicate symbol _serviceCallReturn in:
/Path/to/my/project/Classes/PointEngine/Device/libPointEngineSDK.a(PointEngineSDKUser.o)
/Path/to/my/project/Classes/PointEngine/Device/libPointEngineSDK.a(PointEngineSDKScanner.o)

duplicate symbol _serviceCallType in:
/Path/to/my/project/Classes/PointEngine/Device/libPointEngineSDK.a(PointEngineSDKScanner.o)
/Path/to/my/project/Classes/PointEngine/Device/libPointEngineSDK.a(PointEngineSDKProof.o)

What does it mean? What is the relation between, say, PointEngineSDKUser.o and libPointEngineSDK.a? Any idea what kind of misconfiguration can lead to this?

When I create an empty iOS Project and integrate the library into it, it works like a charm. The problem must be in my existing project configuration.

1

There are 1 answers

6
Eugeniu Rosca On

In short:

  • The *.o files are relocatable ELFs. They are products of the compiler, which always uses source files as input for doing its job.
  • The *.a files are the ar archives. They are product of the so called ar program, which always use relocatable ELF objects as input for doing its job.

Now, to resolve the first issue from the two (duplicate symbol _serviceCallReturn):

  1. Go to and open the PointEngineSDKUser.c and PointEngineSDKScanner.c files from which the corresponding *.o objects have been built.
  2. You should find the serviceCallReturn variable definition in both of them, which is not correct and that's why you see the linker complaining.
  3. If the original intention was to use the same variables in both .c files, then one of them should be defined using the extern keyword. Otherwise, use a different name for one of the variables.