Adding libraries to IOS Externals

Are you developing an External using the LiveCode Externals SDK?

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Adding libraries to IOS Externals

Post by Nakia » Mon Aug 19, 2013 2:30 am

Hi,

I found the below IOS library a few days back now and I am going to try and build an IOS External using it so I can finally (and hopefully easily) have the ability
to embed a FTP Server into a LiveCode IOS Application.

http://www.pureftpd.org/project/pure-ftpd/news

Reading through the documentation in the download it has a comprehensive how-to in terms of adding the libpureftpd.a file to the Xcode Project and the other dependencies but when I run a build I am getting the following error..

"linking step of external dylib build failed, probably due to missing framework or library references - check the contents of the iosftpserver.ios file"

I believe it is telling me that I haven't defined the framework for the library in the .ios file but how do I find out what framework the library requires?

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: Adding libraries to IOS Externals

Post by Nakia » Mon Aug 19, 2013 6:44 am

Seems adding the systemConfiguration Framework stopped the build error.

Now I can get it to build it I have placed it into a test application but it crashes the application when I try to start the FTP Server.

My .mm file below
//
// iosftpserver.mm
// iosftpserver
//
// Created by Nakia Brewer on 19/08/13.
// Copyright 2013 __MyCompanyName__. All rights reserved.
//

void pureftpd_start(void)
{
pureftpd_start();
}


void pureftpd_shutdown(void)
{
pureftpd_shutdown();

}

My .lcidl file below
//
// iosftpserver.lcidlc
// iosftpserver
//
// Created by Nakia Brewer on 19/08/13.
// Copyright 2013 Nakia Brewer. All rights reserved.
//

// The name of the external (note external name must be all lowercase!)
external iosftpserver

use c++-naming
use objc-objects

command pureftpd_start

command pureftpd_shutdown

The documentation for the library states all I really need to do to start the FTP server is call "pureftpd_start()" which is what I have attempted to do..

Any idea's would be greatly appreciated!

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Location: Thailand
Contact:

Re: Adding libraries to IOS Externals

Post by dave_probertGA6e24 » Mon Aug 19, 2013 8:27 am

Hi,

Just as a check - can you actually call a function from within itself like this?

Code: Select all

void pureftpd_start(void)
{
  pureftpd_start();
}

void pureftpd_shutdown(void)
{
  pureftpd_shutdown();
}
I would have thought that you would have a startup function of some other name (eg. main() !!) that would then call the purftpd functions.

Code: Select all

void main(argc, argv)
{
  pureftpd_start();
}

void closemedown()
{
 pureftpd_shutdown();
}
Maybe I'm wrong about this - it's been a while since I did any real C coding.

Cheers,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: Adding libraries to IOS Externals

Post by Nakia » Mon Aug 19, 2013 11:07 am

Dave,

You are probably right..I know ZERO about any form of C so I am trying to learn as I go
(I have a book coming which should help me...)

I will try your suggestion and respond back...

is there a piece missing from your provided suggestion?

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Location: Thailand
Contact:

Re: Adding libraries to IOS Externals

Post by dave_probertGA6e24 » Mon Aug 19, 2013 1:22 pm

Hi Nakia,

Not sure if there's anything missing as such, but it might not be the best C code ;)

Basically make a couple of functions that are not the same name as the pureftpd_ ones and then call the pureftpd_ functions from within them.

You might also be able to trigger the pureftpd_ directly from the ios lcidlc file thingy (I know nothing as yet about creating externals - that's why I'm following how you are getting along ;) )

Just think of it this way (in Livecode):-

Code: Select all

on myHandler
  myHandler
end myHandler
then call myHandler...
that would be VERY bad and would very likely make Livecode crash even quicker than normal!!

You can do this :-

Code: Select all

on myTrigger
  myHandler
end myTrigger

on myHandler
  answer "foo"
end myHandler
then call myTrigger...
which leads to a single call to the myHandler bit and all is Ok :)

Unless the compiler is really clever and can read minds (or some such) it would not really know that you are trying to call a 'different' function called 'pureftpd_start' from within your function 'pureftpd_start'. Therefore it'll get confused. It's basically a recursive function call - which is not what you want here.

So, the two stage approach would work ok as long as the names are not the same :)

Hope that helps a bit more,

Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: Adding libraries to IOS Externals

Post by Nakia » Tue Aug 20, 2013 2:49 am

Dave,

As the .lcidl file can complete tasks on startup and shutdown (according to the LC Youtube video) I think I may just try placing something like below in the .lcidl file as you suggest.
What are the thoughts on trying this?


on startup pureftpd_startup()
on shutdown pureftpd_shutdown()

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: Adding libraries to IOS Externals

Post by Nakia » Tue Aug 20, 2013 3:47 am

Okay so I treid that but the external just does not compile, it says its built but it doesn't actually build anything!

So, back to the orginal method.

In my .lcidl file I have defined the following commands
command CrankItUp
command ShutItOff

Now, my MM file for start but xCode is complaining about use of undeclared indentifier 'pureftpd_start'
void CrankItUp(void)
{
pureftpd_start();
}

Any Ideas

Could you explain to me your method you mentioned above using the main stuff

dave_probertGA6e24
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 328
Joined: Mon Dec 05, 2011 5:34 pm
Location: Thailand
Contact:

Re: Adding libraries to IOS Externals

Post by dave_probertGA6e24 » Tue Aug 20, 2013 6:32 am

Hi Nakia,

In general you would need to '#include' the headers for the pureftpd stuff, make sure that the files (.c/.cpp/.mm/etc) are in the right places so that the compiler can see them and add them to the make process and then make sure that the compiler knows to link to the created library file.

The use of main was just an example. main() is the starting point for virtually all 'C' programs (think of it as the openStack handler for the mainStack in LC ). I don't know of any programs that will work without a 'main' (in my limited experience - I'm sure that there are though!), so I used it as an example only.

At this point in time I haven't actually made any externals for LC so I cannot talk from a state of knowledge - Monte would be better at that. But in general I would suggest getting the hang of some more of the basics of C-Programming before heading into the complicated world of external making. I'm not suggesting a few years of meditation and knowledge absorbing - just get the standard understanding of 'hello world' and how the compiler/linker works. After that it will become a lot easier for most projects - hopefully!

A very simple intro into the coding of basic C stuff can be found here: http://www.learn-c.org/.

I will probably have a go at creating a simple external myself soon, but other business has to take priority first.

Have fun,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.

Nakia
Posts: 425
Joined: Tue Feb 21, 2012 8:57 am

Re: Adding libraries to IOS Externals

Post by Nakia » Tue Aug 20, 2013 8:51 am

Thanks Dave,

I'm slowly piecing bits together and even managed to figured out how to include the headers.
I will take a look at your link, I have been looking for a starting point for learning c!

Thanks for your help, ill be sure to get back when I get it going.

Kia

Post Reply

Return to “Building Externals/Plugins”