call c/c++ function from unix shell scripts
am 01.12.2007 17:22:40 von Rahul
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!!!
Re: call c/c++ function from unix shell scripts
am 01.12.2007 18:48:08 von Icarus Sparry
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.
Re: call c/c++ function from unix shell scripts
am 03.12.2007 18:37:44 von Edward Rosten
On Dec 1, 9:22 am, Rahul 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