How do I compile + link C++ code in Xcode in an Objective-C project?

579 views Asked by At

I have an iOS project with lots of Obj-C sources and a few .cpp files. There is one C++ class CalibrationFileReader, which I created in Xcode 6, which has a .h and a .cpp file. I can use that class from my Objective-C code.

I have a second pair of C++ files (stereo_v3.hpp, stereo_v3.cpp) which do not include a class, but only static functions. Those I added to the project from outside. When I try to use one of the functions (computePoseDifference), it compiles fine but Xcode refuses to link, complaining

Undefined symbols for architecture arm64:
  "computePoseDifference(cv::Mat const&, cv::Mat const&, cv::Mat&, cv::Mat&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:

Things I tried:

  1. Creating the files in Xcode and pasting the original code in them
  2. Manually add the .cpp file to Compile Sources in Build Phases for my target (see image). enter image description here

Neither resolved the problem.

1

There are 1 answers

0
oarfish On BEST ANSWER

Well, turns out Xcode was not the culprit, but the static modifier I prefixed the function's declaration with. So the question was premature. I should've known, but of course, the static linkage makes them invisible for other translation units.