I am having difficulty getting a simple C++ test linking in XCode2. I created a sample test where I have a Dynamic library that uses a class contained within a Static library. This results in an "undefined symbols" link error. Relevant code:
The target JNITest has as a dependency target: BSDSample
The link error I get is:
Undefined symbols:
__ZNK7BSDTest8getLocalEv
__ZNK7BSDTest9getStaticEv
internal link edit command failed
In the terminal, I verified that these are exported via:
nm libBSDSample.a
which returns:
libBSDSample.a(BSDSample.o):
00000024 D __ZN7BSDTest10sm_nStaticE
00000000 T __ZNK7BSDTest8getLocalEv
00000000 A __ZNK7BSDTest8getLocalEv.eh
00000008 T __ZNK7BSDTest9getStaticEv
00000000 A __ZNK7BSDTest9getStaticEv.eh
Any ideas on how to get this to link?
Thanks!
Dustin
Code:
[Target: JNITest (dynamic library)]
--FILE: JNITest.cpp
#include "BSDSample.h"
int shared_function(const char *arg)
{
BSDTest test( 5 );
printf( "[BSDTest] Local: %d Static: %d", test.getLocal(), test.getStatic() );
return 0;
}
[Target: BSDSample (static library)]
--FILE: BSDSample.h
class __attribute__((visibility("default"))) BSDTest
{
private:
static int sm_nStatic;
int m_nLocal;
public:
BSDTest(int nNum) : m_nLocal( nNum ) {}
int getLocal() const;
int getStatic() const;
};
--FILE: BSDSample.cpp
#include "BSDSample.h"
int BSDTest::sm_nStatic = 10;
int BSDTest::getLocal() const { return m_nLocal; }
int BSDTest::getStatic() const { return sm_nStatic; }
The target JNITest has as a dependency target: BSDSample
The link error I get is:
Undefined symbols:
__ZNK7BSDTest8getLocalEv
__ZNK7BSDTest9getStaticEv
internal link edit command failed
In the terminal, I verified that these are exported via:
nm libBSDSample.a
which returns:
libBSDSample.a(BSDSample.o):
00000024 D __ZN7BSDTest10sm_nStaticE
00000000 T __ZNK7BSDTest8getLocalEv
00000000 A __ZNK7BSDTest8getLocalEv.eh
00000008 T __ZNK7BSDTest9getStaticEv
00000000 A __ZNK7BSDTest9getStaticEv.eh
Any ideas on how to get this to link?
Thanks!
Dustin