目标c:如何在库中调用main方法?

时间:2017-02-22 20:55:44

标签: ios objective-c xcode

我有一个我从另一个团队继承的图书馆,因为它被其他人使用而无法修改。该库有一个主要方法,可以开始处理。

图书馆的主要内容     int main(int argc,char * argv [])

我的应用程序的main.m

int main(int argc, char * argv[])

是否可以在我的目标c项目中重命名main并在应用启动时启动?

在C#中,我可以这样做:

private delegate void mainDelegate(int argc, string[] argv);
public Delegate LoadFunction<T>(string dllPath, string functionName)
{
    var hModule = LoadLibrary(dllPath);
    if (hModule == IntPtr.Zero)
    {
      throw new Win32Exception();
    }
    var functionAddress = GetProcAddress(hModule, functionName);
    return Marshal.GetDelegateForFunctionPointer(functionAddress, typeof(T));
}

// initialize with
main = (mainDelegate)LoadFunction<mainDelegate>(AppFile, "main");

// call with 
main(0x0, null);

如果没有,是否可以调用特定库的主要方法而不与我的相撞?

1 个答案:

答案 0 :(得分:1)

根据Apple docs,“每个基于C的应用程序的入口点是main功能,iOS应用程序也不例外。”

据此,我理解只能有一个main函数。