Cross Compiling C library plugin for IOS

Questions and information about using Lua scripting with Storyboard

Moderator: jamiev

Cross Compiling C library plugin for IOS

Postby ScotSutherland » Tue Sep 08, 2015 1:40 pm

I have successfully compiled three c-code distributions as plugins for SB. They are running in the SB simulator on Mac OS X. Now I need to compile them for IOS 8 (arm7). In my SB Lua code I have:

Code: Select all
local myenv = gre.env({ "target_os", "target_cpu" })

if myenv.target_os == "macos" then  --Mac OS X
  package.path = gre.SCRIPT_ROOT .. "/" .. myenv.target_os .. "-" .. myenv.target_cpu .."/?.lua;"..package.path
  package.cpath = gre.SCRIPT_ROOT .. "/" .. myenv.target_os .. "-" .. myenv.target_cpu .."/?.so;"..package.cpath
end


The token "macos" tells SB where to find the libraries when compiling for Mac OS X. What is the token for compiling for IOS 8 (arm7)?

Here are the distros I have successfully compiled for Mac OS X:

https://github.com/diegonehab/luasocket
https://github.com/brunoos/luasec
http://viremo.eludi.net/LuaXML/

I have attempted to compile the first (Luasocket) distro by pointing the makefile to the appropriate storyboard IOS includes and libs. It successfully compiles. The next step is to export for IOS. Not sure how to accomplish this. Is there a specified name in SB for export to IOS (like "macosx")?

Thanks.

Am I missing anything. Are arm7 shared libraries .so files or something else? Are there special compiler flags I need to set?
ScotSutherland
 
Posts: 23
Joined: Mon Jul 13, 2015 3:53 pm

Re: Cross Compiling C library plugin for IOS

Postby ScotSutherland » Wed Sep 09, 2015 5:09 pm

Making progress. Luasocket compiles and deploys to the IOS Device (8.3). Not sure what to make of this console output from the device:

Code: Select all
Sep  9 15:03:01 Pondera-iPad-3 kernel[0] <Notice>: xpcproxy[1098] Container: /private/var/mobile/Containers/Data/Application/33D9B5E2-4823-44E3-9B38-5DA63BE88D1B (sandbox)
Sep  9 15:03:01 Pondera-iPad-3 sbengine_ios[1098] <Error>: assertion failed: 12F69: libxpc.dylib + 51915 [8DB46991-F182-35E3-8E95-918A4007AA7A]: 0x7d
Sep  9 15:03:01 Pondera-iPad-3 Unknown[1098] <Error>:
Sep  9 15:03:01 Pondera-iPad-3 locationd[56] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
Sep  9 15:03:01 Pondera-iPad-3 mediaserverd[19] <Error>: 15:03:01.532 EXCEPTION:  ERROR:     [com.apple.coremedia.playerserver] >va> 3121: kVirtualAudioObjectCategoryNotSupportedError: "Category cvcl is not supported."
Sep  9 15:03:01 Pondera-iPad-3 mediaserverd[19] <Error>: 15:03:01.533 EXCEPTION:  ERROR:     [com.apple.coremedia.playerserver] >va> 3064: kVirtualAudioObjectCategoryNotSupportedError: "Category cvcl is not supported."
Sep  9 15:03:01 Pondera-iPad-3 mediaserverd[19] <Error>: 15:03:01.533 EXCEPTION:  ERROR:     [com.apple.coremedia.playerserver] >va> 3356: kVirtualAudioObjectCategoryNotSupportedError: "Category cvcl is not supported."
Sep  9 15:03:01 Pondera-iPad-3 mediaserverd[19] <Error>: 15:03:01.534 EXCEPTION:  ERROR:     [com.apple.coremedia.playerserver] >va> 3064: kVirtualAudioObjectCategoryNotSupportedError: "Category cvcl is not supported."
Sep  9 15:03:01 Pondera-iPad-3 mediaserverd[19] <Error>: 15:03:01.534 EXCEPTION:  ERROR:     [com.apple.coremedia.playerserver] >va> 3193: kVirtualAudioObjectCategoryNotSupportedError: "Category cvcl is not supported."
Sep  9 15:03:01 Pondera-iPad-3 kernel[0] <Notice>: AMFI: sbengine_ios(pid 1098) - [deny-mmap] mapped file has no team identifier and is not a platform binary: /private/var/mobile/Containers/Bundle/Application/A1BDB381-FDFA-4211-80B4-5E99CF2D7DD5/FraudCast.app/application/scripts/ios-armle/socket.so
Sep  9 15:03:01 Pondera-iPad-3 sbengine_ios[1098] <Warning>: [ERROR] ERROR  [0.190]:Problem loading Lua script [callbacks.lua] error loading module 'socket.core' from file '/private/var/mobile/Containers/Bundle/Application/A1BDB381-FDFA-4211-80B4-5E99CF2D7DD5/FraudCast.app/application/scripts/ios-armle/socket.so':
      dlopen(/private/var/mobile/Containers/Bundle/Application/A1BDB381-FDFA-4211-80B4-5E99CF2D7DD5/FraudCast.app/application/scripts/ios-armle/socket.so, 2): no suitable image found.  Did find:
      /private/var/mobile/Containers/Bundle/Application/A1BDB381-FDFA-4211-80B4-5E99CF2D7DD5/FraudCast.app/application/scripts/ios-armle/socket.so: mmap() error 1 at address=0x037A1000, size=0x00006000 segment=__TEXT in Segment::map() mapping /private/var/mobile/Containers/Bundle/Application/A1BDB381-FDFA-4211-80B4-5E99CF2D7DD5/FraudCast.app/application/scripts/ios-armle/socket.so
Sep  9 15:03:01 Pondera-iPad-3 sbengine_ios[1098] <Warning>: [ERROR] ERROR  [0.191]:LUA failed to load all scripts
Sep  9 15:03:01 Pondera-iPad-3 mediaserverd[19] <Notice>: '' com.ponderasolutions.FraudCast(pid = 1098) setting DiscoveryMode = DiscoveryMode_None, currentDiscoveryMode = DiscoveryMode_None
Sep  9 15:03:01 Pondera-iPad-3 mediaserverd[19] <Notice>: '' (pid = 1098) setting DiscoveryMode = DiscoveryMode_None, currentDiscoveryMode = DiscoveryMode_None
Sep  9 15:03:01 Pondera-iPad-3 SpringBoard[49] <Warning>: Application 'UIKitApplication:com.ponderasolutions.FraudCast[0x80fc]' exited voluntarily.
Sep  9 15:03:01 Pondera-iPad-3 assertiond[59] <Warning>: pid_suspend failed for <BKNewProcess: 0x125e192e0; com.ponderasolutions.FraudCast; pid: 1098; hostpid: -1>: Unknown error: -1, Unknown error: -1
Sep  9 15:03:01 Pondera-iPad-3 assertiond[59] <Warning>: Could not set priority of <BKNewProcess: 0x125e192e0; com.ponderasolutions.FraudCast; pid: 1098; hostpid: -1> to 2, priority: No such process
Sep  9 15:03:01 Pondera-iPad-3 assertiond[59] <Warning>: Could not set priority of <BKNewProcess: 0x125e192e0; com.ponderasolutions.FraudCast; pid: 1098; hostpid: -1> to 4096, priority: No such process
Sep  9 15:03:01 Pondera-iPad-3 locationd[56] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0
Sep  9 15:03:07 Pondera-iPad-3 locationd[56] <Notice>: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0


As far as I can tell this line identifies the problem:

Code: Select all
Sep  9 15:03:01 Pondera-iPad-3 kernel[0] <Notice>: AMFI: sbengine_ios(pid 1098) - [deny-mmap] mapped file has no team identifier and is not a platform binary: /private/var/mobile/Containers/Bundle/Application/A1BDB381-FDFA-4211-80B4-5E99CF2D7DD5/FraudCast.app/application/scripts/ios-armle/socket.so


The compiled c library is socket.so. Does it need to be code signed, or perhaps added to a platform?

Any thoughts would be appreciated?
ScotSutherland
 
Posts: 23
Joined: Mon Jul 13, 2015 3:53 pm

Re: Cross Compiling C library plugin for IOS

Postby Evan » Mon Sep 14, 2015 10:05 am

Hi Scott,

All custom libraries must be codesigned before they can be accessed in an iOS application. This is likely the issue you are facing, since you indicated you did not codesign your socket.so. You can flag custom libraries that you want to use so that Storyboard is aware of them and will codesign them for you.

First, pull the ios-armle folder from scripts up a level to the application root, as codesigning only seems to work from there (I'm not completely sure why yet, but you can test this out to see for yourself). Next, create a text file called 'user_libs.txt'. This should also be placed at the application root, and it should simply contain the names of any folders with libraries you wish to add to the codesign process on each line. Once that is done, your custom .so will be codesigned on export and available to be used inside the application.

This is also explained in our documentation, along with pictures of the proper setup: http://www.cranksoftware.com/cranksoftw ... /ch17.html
Let me know if this solves your problem or if you have any further questions.
Evan
 
Posts: 20
Joined: Wed Aug 27, 2014 7:29 am

Re: Cross Compiling C library plugin for IOS

Postby ScotSutherland » Tue Sep 15, 2015 3:00 pm

Still getting a code signing error. We have an Enterprise Apple Account. Could that have anything to do with this?

Code: Select all
Sep 15 12:50:36 Pondera-iPad-3 kernel[0] <Notice>: AMFI: sbengine_ios(pid 1364) - [deny-mmap] mapped file has no team identifier and is not a platform binary: /private/var/mobile/Containers/Bundle/Application/AF00B932-D8D8-4EF2-8809-76167337BEBD/NetTest.app/application/ios-armle/ssl.so
Sep 15 12:50:36 Pondera-iPad-3 sbengine_ios[1364] <Warning>: [ERROR] ERROR  [1.049]:Problem loading Lua script [callbacks.lua] error loading module 'ssl.core' from file '/private/var/mobile/Containers/Bundle/Application/AF00B932-D8D8-4EF2-8809-76167337BEBD/NetTest.app/application/scripts/../ios-armle/ssl.so':
      dlopen(/private/var/mobile/Containers/Bundle/Application/AF00B932-D8D8-4EF2-8809-76167337BEBD/NetTest.app/application/ios-armle/ssl.so, 2): no suitable image found.  Did find:
      /private/var/mobile/Containers/Bundle/Application/AF00B932-D8D8-4EF2-8809-76167337BEBD/NetTest.app/application/ios-armle/ssl.so: mmap() error 1 at address=0x040C1000, size=0x0011A000 segment=__TEXT in Segment::map() mapping /private/var/mobile/Containers/Bundle/Application/AF00B932-D8D8-4EF2-8809-76167337BEBD/NetTest.app/application/ios-armle/ssl.so


otooling indicates the added library has been coded signed when exported, and the App installs on the device.

Code: Select all
Scots-MacBook-Pro:ios-armle Sutherland$ ls
ssl.so
Scots-MacBook-Pro:ios-armle Sutherland$ pwd
/Users/Sutherland/workspace/NetTest/NetTest.app/ios-armle
Scots-MacBook-Pro:ios-armle Sutherland$ otool -l ssl.so
ssl.so:
Load command 0
      cmd LC_SEGMENT
  cmdsize 396
  segname __TEXT
   vmaddr 0x00000000
   vmsize 0x0011a000
  fileoff 0
 filesize 1155072
  maxprot 0x00000005
 initprot 0x00000005
   nsects 5
    flags 0x0
Section
  sectname __text
   segname __TEXT
      addr 0x00001090
      size 0x000e0888
    offset 4240
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x80000400
 reserved1 0
 reserved2 0
Section
  sectname __stub_helper
   segname __TEXT
      addr 0x000e1918
      size 0x000007ec
    offset 923928
     align 2^2 (4)
    reloff 0
    nreloc 0
     flags 0x80000400
 reserved1 0
 reserved2 0
Section
  sectname __cstring
   segname __TEXT
      addr 0x000e2110
      size 0x0001f5bf
    offset 925968
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000002
 reserved1 0
 reserved2 0
Section
  sectname __const
   segname __TEXT
      addr 0x001016d0
      size 0x0001868c
    offset 1054416
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __symbolstub1
   segname __TEXT
      addr 0x00119d5c
      size 0x00000298
    offset 1154396
     align 2^2 (4)
    reloff 0
    nreloc 0
     flags 0x80000408
 reserved1 0 (index into indirect symbol table)
 reserved2 4 (size of stubs)
Load command 1
      cmd LC_SEGMENT
  cmdsize 464
  segname __DATA
   vmaddr 0x0011a000
   vmsize 0x0001e000
  fileoff 1155072
 filesize 110592
  maxprot 0x00000003
 initprot 0x00000003
   nsects 6
    flags 0x0
Section
  sectname __lazy_symbol
   segname __DATA
      addr 0x0011a000
      size 0x00000298
    offset 1155072
     align 2^2 (4)
    reloff 0
    nreloc 0
     flags 0x00000007
 reserved1 166 (index into indirect symbol table)
 reserved2 0
Section
  sectname __nl_symbol_ptr
   segname __DATA
      addr 0x0011a298
      size 0x000002ec
    offset 1155736
     align 2^2 (4)
    reloff 0
    nreloc 0
     flags 0x00000006
 reserved1 332 (index into indirect symbol table)
 reserved2 0
Section
  sectname __const
   segname __DATA
      addr 0x0011a590
      size 0x0000fee4
    offset 1156496
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __data
   segname __DATA
      addr 0x0012a480
      size 0x0000a244
    offset 1221760
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __bss
   segname __DATA
      addr 0x001346d0
      size 0x00002bc8
    offset 0
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000001
 reserved1 0
 reserved2 0
Section
  sectname __common
   segname __DATA
      addr 0x00137298
      size 0x0000002c
    offset 0
     align 2^2 (4)
    reloff 0
    nreloc 0
     flags 0x00000001
 reserved1 0
 reserved2 0
Load command 2
      cmd LC_SEGMENT
  cmdsize 56
  segname __LINKEDIT
   vmaddr 0x00138000
   vmsize 0x00058000
  fileoff 1265664
 filesize 360336
  maxprot 0x00000001
 initprot 0x00000001
   nsects 0
    flags 0x0
Load command 3
          cmd LC_ID_DYLIB
      cmdsize 32
         name ssl.so (offset 24)
   time stamp 1 Wed Dec 31 16:00:01 1969
      current version 0.0.0
compatibility version 0.0.0
Load command 4
            cmd LC_DYLD_INFO_ONLY
        cmdsize 48
     rebase_off 1265664
    rebase_size 7440
       bind_off 1273104
      bind_size 212
  weak_bind_off 0
 weak_bind_size 0
  lazy_bind_off 1273316
 lazy_bind_size 2944
     export_off 1276260
    export_size 99212
Load command 5
     cmd LC_SYMTAB
 cmdsize 24
  symoff 1384528
   nsyms 7057
  stroff 1471288
 strsize 137524
Load command 6
            cmd LC_DYSYMTAB
        cmdsize 80
      ilocalsym 0
      nlocalsym 2026
     iextdefsym 2026
     nextdefsym 4858
      iundefsym 6884
      nundefsym 173
         tocoff 0
           ntoc 0
      modtaboff 0
        nmodtab 0
   extrefsymoff 0
    nextrefsyms 0
 indirectsymoff 1469212
  nindirectsyms 519
      extreloff 0
        nextrel 0
      locreloff 0
        nlocrel 0
Load command 7
     cmd LC_UUID
 cmdsize 24
    uuid E63B57FD-485A-3A6F-9006-CDC171D10B52
Load command 8
      cmd LC_VERSION_MIN_IPHONEOS
  cmdsize 16
  version 6.0
      sdk 8.4
Load command 9
      cmd LC_SOURCE_VERSION
  cmdsize 16
  version 0.0
Load command 10
          cmd LC_LOAD_DYLIB
      cmdsize 84
         name /System/Library/Frameworks/Foundation.framework/Foundation (offset 24)
   time stamp 2 Wed Dec 31 16:00:02 1969
      current version 1144.17.0
compatibility version 300.0.0
Load command 11
          cmd LC_LOAD_DYLIB
      cmdsize 80
         name /System/Library/Frameworks/OpenGLES.framework/OpenGLES (offset 24)
   time stamp 2 Wed Dec 31 16:00:02 1969
      current version 1.0.0
compatibility version 1.0.0
Load command 12
          cmd LC_LOAD_DYLIB
      cmdsize 56
         name @loader_path/../lib/libsblua.so (offset 24)
   time stamp 2 Wed Dec 31 16:00:02 1969
      current version 0.0.0
compatibility version 0.0.0
Load command 13
          cmd LC_LOAD_DYLIB
      cmdsize 52
         name /usr/lib/libSystem.B.dylib (offset 24)
   time stamp 2 Wed Dec 31 16:00:02 1969
      current version 1214.5.1
compatibility version 1.0.0
Load command 14
      cmd LC_FUNCTION_STARTS
  cmdsize 16
  dataoff 1375472
 datasize 7420
Load command 15
      cmd LC_DATA_IN_CODE
  cmdsize 16
  dataoff 1382892
 datasize 1592
Load command 16
      cmd LC_DYLIB_CODE_SIGN_DRS
  cmdsize 16
  dataoff 1384484
 datasize 44
Load command 17
      cmd LC_CODE_SIGNATURE
  cmdsize 16
  dataoff 1608816
 datasize 17184
Scots-MacBook-Pro:ios-armle Sutherland$
ScotSutherland
 
Posts: 23
Joined: Mon Jul 13, 2015 3:53 pm

Re: Cross Compiling C library plugin for IOS

Postby Evan » Wed Sep 16, 2015 2:08 pm

Re-reading my response, I was a little ambiguous in one area. Pulling ios-armle up to the application root and creating the user_libs.txt file will tell Storyboard to create a copy of the specified folder and put it directly inside 'NetTest.app' for it to be codesigned. This is what I meant by application root. In the Navigator view inside Storyboard, you can expand 'NetTest.app' and you should see a copy of your ios-armle folder right there. This is the one that gets codesigned, not the one in the application folder.

To summarize, you should be referencing 'NetTest.app/ios-armle/' from inside your application rather than 'NetTest.app/application/ios-armle'. Sorry for the confusion.
Evan
 
Posts: 20
Joined: Wed Aug 27, 2014 7:29 am

Re: Cross Compiling C library plugin for IOS

Postby ScotSutherland » Thu Oct 01, 2015 12:08 pm

Just wanted to complete the thread. All the relevant libraries are working now with our application. There were complexities with paths internal to the c distributions that we paid Crank Software to sort out for us. Evan delivered the working libraries in a couple of days.

Would it be of interest to other users of Storyboard to have the distros for basic networking libraries with modified make files made available by Crank Software? I am not suggesting that Crank provide working binaries, but the tools to more easily compile the libraries for the platforms supported by Crank. Of course if Crank wants to provide working binaries, I won't complain.
ScotSutherland
 
Posts: 23
Joined: Mon Jul 13, 2015 3:53 pm


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 2 guests

cron