简体   繁体   中英

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

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). 在此处输入图片说明

Neither resolved the problem.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM