背景
在unity4.2版本中可以在Android中使用的so链接库,在Unity4.5中使不了~~
[DllImport("libclient.so", EntryPoint = "readFifo")] private static extern int readFifo(int clientFd);
原因
最初一直以为是So的编译问题,结果测试几个之后还是一样,代码什么都不动,转换到4.5发布之后就不行。昨天发现这段话:
If you have control over the library name, keep the above naming conventions in mind and don’t use a platform-specific library name in the DllImport statement. Instead, just use the library name itself, without any prefixes or suffixes, and rely on the runtime to find the appropriate library at runtime. For example: [DllImport ("MyLibrary")] private static extern void Frobnicate (); Then, you just need to provide MyLibrary.dll for Windows platforms, libMyLibrary.so for Unix platforms, and libMyLibrary.dylib for Mac OS X platforms.
翻译过来就是不用对每个平台使用DLLIMPORT的时候使用不同的DLL名字,只需要使用DLL库本身的名字,不加任何的前缀或者后缀,系统会自动根据DLL名字和平台去搜索。比如:"MyLibrary" 在windows平台需要MyLibrary.dll , 在Android中需要libMyLibrary.so,在IOS中需要libMyLibrary.dylib .
我的工程中实际名字是:libclient.so,所以可以这样写:
[DllImport("client", EntryPoint = "readFifo")] private static extern int readFifo(int clientFd);
细雨标记: unity dll