Reputation: 1
I want to use C++ static library which was built in Eclipse in Xcode 4:
For example, I have a very simple library:
hello.h
class Test{ public: static int getX();};
hello.cpp
#include "hello.h"
int Test::getX(){return 10;}
So after building in Eclipse, I have a library .a. Now, I import .a file and the header to an Xcode app. The problem is that in the .mm file (I created), I cannot call "int x = Test::getX();", it show 2 errors:
Undefined symbols for architecture i386: "Test::getX()", referenced from: -[LibFetching onlyfortest] in LibFetching.o
ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Do you know how can I fix it? Thank you very much.
Upvotes: 0
Views: 1533
Reputation: 1226
From the Question it seems that you are trying to link C++ static library to an Objective C++ project
Go to project -> Build Settings ,search for C++ Language Dialect and C++ Standard Library. Select options "Compiler Default" for both of them and it should work
Also check if you have to set the other linker flag to -lstdc++
Upvotes: 3
Reputation: 627
You will need to drag your static library to your Xcode project. Then select the project you want to add the library to in the left navigator bar, the select the project target (or the target that needs the library if you have more than one).
Then click on Build Phases, and in the Link Binary with Libraries section (create one if it doesn't already exist), add your library, also, add it to your target dependency section as well.
You may need to to enter the path to you library headers in Header Search Path of your build settings.
Upvotes: 0