duplicate symbol error for symbol in static library which should be invisible
duplicate symbol error for symbol in static library which should be invisible
- Subject: duplicate symbol error for symbol in static library which should be invisible
- From: Stuart Smith <email@hidden>
- Date: Tue, 22 Dec 2009 16:27:41 -0800
- Thread-topic: duplicate symbol error for symbol in static library which should be invisible
Title: duplicate symbol error for symbol in static library which should be invisible
I am using Xcode 3.2.1. I’m compiling for i386 & PPC against the 10.4u SDK using gcc 4.0, but my problem also occurs with a small test project using the 10.6 SDK and gcc 4.2.
I have some third-party code, written in C++, which I’d like to encapsulate, because it contains classes and functions whose names I don’t have control over, and I want to do minimal editing of it. Therefore, I want to build a static library out of it, and expose only those symbols required for that library’s interface. To this end, I’ve turned on “Symbols Hidden by Default” and even “Inline Methods Hidden” in the target settings for my library.
I have one class which provides the interface to my library, let’s call it VisibleClass. It is declared like this:
class __attribute__((visibility("default"))) VisibleClass
If I run the nm tool on my library, I see more-or-less what I expect (the text below has been edited for brevity)
nm -m libtest-library.a | c++filt
libtest-library.a(test-library.o):
00000034 (__TEXT,__text) external VisibleClass::SomeFunctionVisible(int)
00000000 (absolute) external [no dead strip] __ZN12VisibleClass19SomeFunctionVisibleEi.eh
00000012 (__TEXT,__text) external VisibleClass::VisibleClass()
00000000 (absolute) external [no dead strip] __ZN12VisibleClassC1Ev.eh
00000000 (__TEXT,__text) external VisibleClass::VisibleClass()
00000000 (absolute) external [no dead strip] __ZN12VisibleClassC2Ev.eh
0000002c (__TEXT,__text) external VisibleClass::~VisibleClass()
00000000 (absolute) external [no dead strip] __ZN12VisibleClassD1Ev.eh
00000024 (__TEXT,__text) external VisibleClass::~VisibleClass()
00000000 (absolute) external [no dead strip] __ZN12VisibleClassD2Ev.eh
00000078 (__TEXT,__text) private external InvisibleClass::SomeFunctionInvisible(int)
00000000 (absolute) private external [no dead strip] __ZN14InvisibleClass21SomeFunctionInvisibleEi.eh
00000056 (__TEXT,__text) private external InvisibleClass::InvisibleClass()
00000000 (absolute) private external [no dead strip] __ZN14InvisibleClassC1Ev.eh
00000044 (__TEXT,__text) private external InvisibleClass::InvisibleClass()
00000000 (absolute) private external [no dead strip] __ZN14InvisibleClassC2Ev.eh
00000070 (__TEXT,__text) private external InvisibleClass::~InvisibleClass()
00000000 (absolute) private external [no dead strip] __ZN14InvisibleClassD1Ev.eh
00000068 (__TEXT,__text) private external InvisibleClass::~InvisibleClass()
00000000 (absolute) private external [no dead strip] __ZN14InvisibleClassD2Ev.eh
000000bc (__TEXT,__text) private external DuplicatedClass::SomeFunctionDuplicated(int)
00000000 (absolute) private external [no dead strip] __ZN15DuplicatedClass22SomeFunctionDuplicatedEi.eh
0000009a (__TEXT,__text) private external DuplicatedClass::DuplicatedClass()
00000000 (absolute) private external [no dead strip] __ZN15DuplicatedClassC1Ev.eh
00000088 (__TEXT,__text) private external DuplicatedClass::DuplicatedClass()
00000000 (absolute) private external [no dead strip] __ZN15DuplicatedClassC2Ev.eh
000000b4 (__TEXT,__text) private external DuplicatedClass::~DuplicatedClass()
00000000 (absolute) private external [no dead strip] __ZN15DuplicatedClassD1Ev.eh
000000ac (__TEXT,__text) private external DuplicatedClass::~DuplicatedClass()
00000000 (absolute) private external [no dead strip] __ZN15DuplicatedClassD2Ev.eh
In the application which hosts the library, I have a declaration and definition of a class called DuplicatedClass. I don’t expect this to cause problems with the class of the same name inside my library, because DuplicatedClass is hidden inside the library. However, when I get to the link stage of the application, I get a link error:
ld: duplicate symbol DuplicatedClass::DuplicatedClass()in test-library/build/Debug/libtest-library.a(test-library.o) and test-host/build/test-host.build/Debug/test-host.build/Objects-normal/i386/DuplicateClass.o
Why is that? Is my expectation of what “Symbols Hidden by Default” does, and what “private external” means, completely wrong? I thought “private external” meant “private to the library, but visible outside this particular compilation unit”. Can someone correct me? Indeed, if anyone has any suggestions as to how else I could hide all but the interface of a library from a hosting application, those are welcome too.
thanks, Stuart
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden