Discussion:
[Lazarus] Building a C (or possibly C++) program into a Lazarus app
Mark Morgan Lloyd via Lazarus
2018-08-10 14:44:40 UTC
Permalink
Is it possible to link a C or possibly C++ program into a Lazarus one by
simply calling its main() function? Has anybody actually done this?

I've got a couple of C/C++ programs which are based on stdin/stdout user
interaction (no curses etc.) but have thoroughly unpleasant keyboard
requirements and odd output encoding. I find myself wondering whether
they could be given a more friendly frontend by wrapping them in a
Lazarus app, with an on-screen keyboard similar to what's found on a
tablet etc.

I would, obviously, be able to rename main() if necessary, as well as
I/O functions.
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
--
R0b0t1 via Lazarus
2018-08-10 15:10:54 UTC
Permalink
I have some posts on the forum asking about similar questions. I was
told FPC object files will link just fine with GNU tools, so you
should be able to.

To me it seemed it would be easier to keep the codebase in C++ but
then call into the LCL. Sadly that is quite a bit off.

On Fri, Aug 10, 2018 at 9:44 AM, Mark Morgan Lloyd via Lazarus
Post by Mark Morgan Lloyd via Lazarus
Is it possible to link a C or possibly C++ program into a Lazarus one by
simply calling its main() function? Has anybody actually done this?
I've got a couple of C/C++ programs which are based on stdin/stdout user
interaction (no curses etc.) but have thoroughly unpleasant keyboard
requirements and odd output encoding. I find myself wondering whether they
could be given a more friendly frontend by wrapping them in a Lazarus app,
with an on-screen keyboard similar to what's found on a tablet etc.
I would, obviously, be able to rename main() if necessary, as well as I/O
functions.
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
--
_______________________________________________
Lazarus mailing list
https://lists.lazarus-ide.org/listinfo/lazarus
--
leledumbo via Lazarus
2018-08-10 20:33:29 UTC
Permalink
Post by Mark Morgan Lloyd via Lazarus
I find myself wondering whether
they could be given a more friendly frontend by wrapping them in a
Lazarus app, with an on-screen keyboard similar to what's found on a
tablet etc.
Sounds like my non-web hobby projects with Lazarus.
Post by Mark Morgan Lloyd via Lazarus
Is it possible to link a C or possibly C++ program into a Lazarus one by
simply calling its main() function? Has anybody actually done this?
I don't do that, though. Even if technically possible, there are hidden
stuffs you have to be aware of. main() is only a specification in C
standard, where the user code starts. However, long before that, there's a
startup mechanism specific to each implementation. In GCC, this is _start,
absolutely non-portable. That's why the IMO better way is to communicate
over pipes via TProcess.



--
Sent from: http://free-pascal-lazarus.989080.n3.nabble.com/
--
Mark Morgan Lloyd via Lazarus
2018-08-10 21:33:02 UTC
Permalink
Post by leledumbo via Lazarus
I find myself wondering whether > they could be given a more friendly frontend by wrapping them in a > Lazarus app, with an on-screen keyboard similar to what's found on a > tablet etc.
Sounds like my non-web hobby projects with Lazarus.
Is it possible to link a C or possibly C++ program into a Lazarus one by > simply calling its main() function? Has anybody actually done this?
I don't do that, though. Even if technically possible, there are hiddenstuffs you have to be aware of. main() is only a specification in Cstandard, where the user code starts. However, long before that, there's astartup mechanism specific to each implementation. In GCC, this is _start,absolutely non-portable. That's why the IMO better way is to communicateover pipes via TProcess.
Thanks for that. The program I'm thinking about is actually pretty
simple and ancient- written by Ken Thompson- so I might be in with a chance.

What I'd /really/ like to do is port it- complete with UI helper- to
Android. However at that point I have to add my voice to Bo's plea of a
couple of weeks ago: what's the current situation and future plans of
Lazarus as far as Android is concerned? I see mention of Laz4Android in
e.g. http://wiki.lazarus.freepascal.org/Android_tutorial : is that
mainstream or is there some other preferred solution?
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
--
leledumbo via Lazarus
2018-08-12 19:57:53 UTC
Permalink
Post by Mark Morgan Lloyd via Lazarus
what's the current situation and future plans of
Lazarus as far as Android is concerned? I see mention of Laz4Android in
e.g. http://wiki.lazarus.freepascal.org/Android_tutorial : is that
mainstream or is there some other preferred solution?
Laz4Android is just a prepackaged Lazarus + FPC + Android NDK. You can
create Android apps using Custom Drawn Interface, but it's very incomplete
and non-native. I don't see any better way than LAMW right now, at least
it's maintained, progressing, user requests are handled (quite fast), rather
complete (just look at the demos, I don't think you need more than already
provided components for most apps) and use native look and feel.



--
Sent from: http://free-pascal-lazarus.989080.n3.nabble.com/
--
Mark Morgan Lloyd via Lazarus
2018-08-12 20:14:32 UTC
Permalink
what's the current situation and future plans of > Lazarus as far as Android is concerned? I see mention of Laz4Android in > e.g. http://wiki.lazarus.freepascal.org/Android_tutorial : is that > mainstream or is there some other preferred solution?
Laz4Android is just a prepackaged Lazarus + FPC + Android NDK. You cancreate Android apps using Custom Drawn Interface, but it's very incompleteand non-native. I don't see any better way than LAMW right now, at leastit's maintained, progressing, user requests are handled (quite fast), rathercomplete (just look at the demos, I don't think you need more than alreadyprovided components for most apps) and use native look and feel.
TFT, I'll investigate.
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
--
Loading...