我有一个libDinosaurs-ios.a
库,它是由C ++和Objective-C代码结合而成的,是为iOS构建的。我还有另一个与此库链接的C ++项目,显然尝试调用其函数。
Objective-C代码位于:
// Utils.mm
const char* findApplicationPath()
{
NSString* appDirectory = [[NSBundle mainBundle] resourcePath];
return [appDirectory UTF8String];
}
调用的C ++代码位于:
// 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;
}
该库看似正确地编译到上述.a
文件中。当我将新项目链接到该库时,问题出现。所有最初在Objective-C代码中的函数都会产生以下链接错误:
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)
为了使工作更困难,我没有一个要尝试构建的项目的Xcode项目,只有CMake文件。是什么导致此错误,我该如何解决?我尝试了链接器标志-ObjC
,但并没有解决问题:
set_target_properties(DinosaurZoo PROPERTIES LINK_FLAGS "-ObjC" )