0

I have a library libDinosaurs-ios.a that was build from a combination of C++ and Objective-C code, build for iOS. I have another C++ project that links against this library and obviously tries to call its functions.

The Objective-C code lives in:

// Utils.mm
const char* findApplicationPath()
{
  NSString* appDirectory = [[NSBundle mainBundle] resourcePath];
  return [appDirectory UTF8String];
}

The C++ code that calls is lives in:

// Dinosaurs.cpp
FILE* Dinosaurs::openFile(char const* pInFileName)
{
 char applePath[IOS_PATH_MAX];
 strcpy(applePath, findApplicationPath());
 strcat(applePath, "/");
 strcat(applePath, pInFileName);
 FILE* pFile = fopen(applePath, "rb")
 return pFile;
}

The library compiles seemingly correctly into the aforementioned .a file. The problem arrises when I link a new project against this library. All functions that were originally in the Objective-C code produce the following link error:

Undefined symbols for architecture armv7:
"findApplicationPath()", referenced from:
  Dinosaurs::openFile(char const*) in libDinosaurs-ios.a(Dinosaurs.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

To make stuff more difficult, I do not have an Xcode project for the project I'm trying to build, only a CMake file. What is causing this error, and how do I fix it? I tried the linker flag -ObjC but that didn't solve it:

set_target_properties(DinosaurZoo PROPERTIES LINK_FLAGS "-ObjC" )
Yellow
  • 3,955
  • 6
  • 45
  • 74
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Matthieu Brucher Jan 21 '19 at 17:05
  • Obviously it's not in the library. Probably not the proper architecture. – Matthieu Brucher Jan 21 '19 at 17:05
  • @MatthieuBrucher that thread is so general it's really not very useful. This problem concerns a very specific problem of linking a library with Objective-C and C++ functions. Could you be more specific wrt "not the proper architecture"? – Yellow Jan 21 '19 at 17:24
  • `Undefined symbols for architecture armv7`: are you sure you have the symbol for that platform? (`findApplicationPath`) – Matthieu Brucher Jan 21 '19 at 17:26
  • I am not sure how for one specific platform, the library could have compiled all the other (C++) functions but not the Objective-C ones, without giving an error – Yellow Jan 21 '19 at 17:35
  • And where does `findApplicationPath` come from? – Matthieu Brucher Jan 21 '19 at 17:36
  • I change the post to address your question – Yellow Jan 22 '19 at 14:59
  • Obviously this objective-C fucntion is not visible by the C++ code. Why? No clue, I don't know Objective C. The way the library is created is wrong somewhere (a static library doesn't check anything, it's just an archive, it always "links" fine). – Matthieu Brucher Jan 22 '19 at 15:01
  • Can you post the .h file or declaration which `Dinosaurs::openFile` uses to call findApplicationPath? Also maybe the command you're building the .a with? – Jesse Rusak Jan 22 '19 at 15:12
  • Try the basic right now. Verify the armv7 slice truly exists. Run `lipo -archs static.a` where "static.a" is the name of the C++ library. If you don't see armv7, then there is your answer. In that case you need to re-build the static if you truly need the armv7 slice (which you probably do). – Mobile Ben Jan 23 '19 at 00:39

0 Answers0