Unix Shell - call c/c++ function from unix shell scripts

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > December 2007 > call c/c++ function from unix shell scripts





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author call c/c++ function from unix shell scripts
Rahul

2007-12-01, 1:22 pm

Hi Everyone,

I have the a object file having the definition of functions written
in c/c++ programming language. I need to invoke them from unix shell
scripts, is there any way to do so?

Thanks in advance!!!
Icarus Sparry

2007-12-01, 1:22 pm

On Sat, 01 Dec 2007 08:22:40 -0800, Rahul wrote:

> Hi Everyone,
>
> I have the a object file having the definition of functions written
> in c/c++ programming language. I need to invoke them from unix shell
> scripts, is there any way to do so?
>
> Thanks in advance!!!


Skipping quickly over the obvious - link your object file into an
executable and then call the executable.....

Some shells such as bash and ksh93 can load shared libraries. If you can
get your code into one of these then you may be able to. In general C++
will be a lot harder, as most shells are written in C and therefore will
not have called any C++ runtime startup code.

ksh93
builtin --man
and look at the '-f' option.
bash
man bash
and look at the 'enable -f' command.

In both cases you will need to add some glue code, as the shells deal
mostly with strings, and it is a fair bet that your object code will deal
with numbers, structures etc.

You may find it simpler to add your code to something other than the
shell. TCL was originally designed to be a "glue language", which could
be used to add scripting to an application. These days Lua would be
another good choice, or you can embed perl, Python etc. If you go this
route, you should probably consider SWIG (http://www.swig.org) which can
write most of the glue code for you for lots of scripting languages.
Maxwell Lol

2007-12-03, 1:28 pm

Icarus Sparry <usenet@icarus.freeuk.com> writes:

> Some shells such as bash and ksh93 can load shared libraries.


Perl can as well.
Edward Rosten

2007-12-03, 1:28 pm

On Dec 1, 9:22 am, Rahul <sam_...@yahoo.co.in> wrote:

> I have the a object file having the definition of functions written
> in c/c++ programming language.


Which is it? C or C++? C++ mangles names, so you'll need to declare
them extern C to make them easily accessible.

> I need to invoke them from unix shell
> scripts, is there any way to do so?


You will have to be more specific. What arguments to they take? What
output do you expect? In C++, you can deduce this from the mangled
name, but you can't in C. Can't you just link them in to an
executable?

-Ed

--
(You can't go wrong with psycho-rats.) (http://mi.eng.cam.ac.uk/
~er258)

/d{def}def/f{/Times findfont s scalefont setfont}d/s{11}d/r{roll}d f 2/
m
{moveto}d -1 r 230 350 m 0 1 179{1 index show 88 rotate 4 mul 0
rmoveto}
for /s 12 d f pop 235 420 translate 0 0 moveto 1 2 scale show
showpage
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com