View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

Linking,compiling and executing a C code from within IRAF

smp wrote on Feb 13, 2009

hi,

I am using
a) Red Hat Enterprise Linux WS release 4 (Nahant Update 6) , x86_64
b) IRAF V2.12

I have a small C language code: add.c
I want to link,compile and run this C code from within IRAF.
I used the IRAF task "xc" for this as:

cl > xc add.c


Then I got add.o file
But I got so many error messages. One of them was like:

/usr/bin/ld: warning: i386 architecture of input file `/opt/iraf/iraf/unix/bin.redhat/libcompat.a(C_name.o)' is incompatible with i386:x86-64 output


Then I gave following command:

cl> xc -llib add.c  


and I got following message:

link:
/opt/iraf/iraf/bin.redhat/libmain.o(.text+0x0): In function `main':
: multiple definition of `main'
add.o(.text+0x0): first defined here
/usr/bin/ld: Warning: size of symbol `main' changed from 34 in add.o to 1021 in /opt/iraf/iraf/bin.redhat/libmain.o
/usr/bin/ld: cannot find -llib
collect2: ld returned 1 exit status


Please tell how to do this.
Thanks

Mike Fitzpatrick wrote on Feb 13, 2009

Compilation under 64-bit systems isn't yet supported for IRAF applications. If you're 'add.c' program is pure C code (i.e. doesn't rely on IMFORT libraries or tries to do something clever with IRAF libraries), then you can simply use a shell escape to compile using the host GCC compiler, e.g.

cl> !gcc -o add add.c


Using the XC compiler brings in all sorts of IRAF libraries automatically and isn't what you want to use for host programs. Note you can make gcc directly available without the escape by declaring it as a foreign task ('xc' is done the same way), e.g.

cl> task $gcc = $foreign


This can be added to the list of foreign tasks defined in your login.cl to make it permanent.

-Mike

smp wrote on Feb 13, 2009

Thanks Mike.
It worked.

I added gcc in my login.cl file as a foreign task and I gave these commands and I got the output "sum is = 40":

cl> gcc -o add add.c
cl> !./add
sum is = 40


Then I wrote a small procedure script like this:

procedure swapnil(filename)
string filename

begin
  edit add.c
  gcc -o add add.c
  !./add
end


(The query parameter "filename" is just accepting a file name and does nothing. Is it possible to write a procedure script without using even a single querry parameter?)

This time if run the script, I got following error message:

cl> swapnil
** Syntax error, line 9
**: gcc -o addition addition.c
^
INTERNAL ERROR on line 14: parser gagged
swapnil ()


But in the above script, if I use a shell escape instead:

!gcc  -o addition addition.c


there is no error message and output is correct.

Mike Fitzpatrick wrote on Feb 13, 2009

(The query parameter "filename" is just accepting a file name and does nothing. Is it possible to write a procedure script without using even a single querry parameter?)


Scripts aren't required to have query params, just don't put anything in the procedure declaration and declare the script with a '$', e.g.

cl> type foo.cl
procedure foo()
begin
   echo "foo"
end
cl> task $foo = /path/foo.cl


If you use emacs, then the file may not have been written with a newline following the 'end' statement, causing the parser to gag. In this case though the more likely cause is the use of "command mode" syntax in the script. A better way to write it would be


procedure swapnil(filename)
string filename

begin
  edit ("add.c")
  gcc (" -o", " add", " add.c")
  print ("!./add") | cl()
end


This is "compute mode", where the individual args are quoted as shown. See the CL Script Guide for details.

-Mike

smp wrote on Feb 13, 2009

thanks it worked.

regards

Last post on Feb 13, 2009