UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
175 Views
Registered: ‎02-19-2019

Compile Fortran lib.a for Linux under Zynq-7000 platform

Jump to solution

Dear all,

I have got fortran source code that I would like to interface from my embedded Linux running under a ZC706 eval board. I have managed to compile the fortran code for x86 platform usign gfortran outputting a static libFortran.a and interfaced it with a C/C++ code. I would to do the same but now to run under my embedded Linux on ZC706. I have got the set-up ready where I have my system booting with a petalinux based custom distribution and can run C/C++ applications on my target board. Only missing the fortran library compilation.

Any idea how to generate the fortran .a lib to use within my target board?

Thanks in advance for any help.

Marco Roda

 

 

0 Kudos
1 Solution

Accepted Solutions
32 Views
Registered: ‎02-19-2019

Re: Compile Fortran lib.a for Linux under Zynq-7000 platform

Jump to solution

Hi @watari ,

I have managed to croo-compile the Fortran and C code and run it on my target board. Here is how (done on the host PC running Ubuntu-16.04):

# Compile the Fortran code without linking. Outputs an object file that is later on linked to my main.o object file.
$ arm-linux-gnueabihf-gfortran-4.8 -c circle_file.f90
$ arm-linux-gnueabihf-gcc-4.8 -c main.c
# Links both object files from the C and Fortran code into an executable file. Libraries Math and ligfortran need to be linked as well. 
$ arm-linux-gnueabihf-gcc-4.8 -o out_cross.a circle_file.o main.o -lm -lgfortran

Then, I have copied my executable out_cross.a and the libgfortran.so to my target board under /home/root, export LD_LIBRARY_PATH=/home/root variable an dit worked.

Thanks a lot for your help.

Best Regards,

Marco

0 Kudos
11 Replies
Scholar watari
Scholar
167 Views
Registered: ‎06-16-2013

Re: Compile Fortran lib.a for Linux under Zynq-7000 platform

Jump to solution

Hi @marcorodasyderal 

 

I'm not sure but would you add 'FORTRAN_forcevariable = ",fortran"' in conf/local.conf file and add bbappendfile in gcc ?

 

*1)

ex. recipes-devtools/gcc/gcc-runtime_%.bbappend

 

RUNTIMEARGET += "libfortran"

 

Best regards,

0 Kudos
161 Views
Registered: ‎02-19-2019

Re: Compile Fortran lib.a for Linux under Zynq-7000 platform

Jump to solution

Hi @watari,

If I am not mistaken, the solution you are proposing is to run a fortran executable directly from the traget? It is not?.

Here, I have got already a fortran lib.a that I would like to interface with a custom C/C++ app runing on the target. I have been looking for Chapter 8 of UG1144(v2019.1). Is it not that what I need?

Thanks,

Marco

0 Kudos
Scholar watari
Scholar
156 Views
Registered: ‎06-16-2013

Re: Compile Fortran lib.a for Linux under Zynq-7000 platform

Jump to solution

Hi @marcorodasyderal 

 

My solution is to support to build elf file from fortran source code in your embedded linux.

Since you use petalinux, so I described the solution.

 

Best regards,

0 Kudos
129 Views
Registered: ‎02-19-2019

Re: Compile Fortran lib.a for Linux under Zynq-7000 platform

Jump to solution

Hi @watari 

 

>> *1)

>>ex. recipes-devtools/gcc/gcc-runtime_%.bbappend

Where can I find this dir/ recipes-devtools/gcc/gcc-runtime_%.bbappend. I am using petalinux 2019.1.

Best Regards,

Marco Roda

0 Kudos
Scholar watari
Scholar
109 Views
Registered: ‎06-16-2013

Re: Compile Fortran lib.a for Linux under Zynq-7000 platform

Jump to solution

Hi @marcorodasyderal 

 

As I already mentioned before, it's an example about bbappend file.

Since I don't know your environment, I can't exactly answer it for you.

 

BTW, this is a tips to find bbappend and gcc recip file for you.

Would you try it ?

 

$ find . | grep -e .bbappend$ | grep gcc

 

Best regards,

 

 

0 Kudos
89 Views
Registered: ‎02-19-2019

Re: Compile Fortran lib.a for Linux under Zynq-7000 platform

Jump to solution

Hi @watari ,

About my environment: I am using Petalinux v. 2019.1 to build a custom Linux distribution for my target board (ZC706). I want to interface a Fortran lib within the traget board from a C/C++ app. For now I have managed to cross-compile my Fortran code using:

$ arm-linux-gnueabihf-gfortran-4.8 -o out_fortran hello.f90

I have got an executable and when tried to run it on my target it shows:

root@amp_zynq:~# ./out_fortran
./out_fortran: error while loading shared libraries: libgfortran.so.3: cannot open shared object file: No such file or directory

Clearly the Fortran runtime library is not present on my target. 

I have tried $ find . | grep -e .bbappend$ | grep gcc under the root/ of my petalinux project but no results.

I can't find the recipes-dev-tools/gcc/.. on my folder structure. Petalinux runs on top of Yocto but seems like some Yocto feature are hidden from the Petalinux workflow. See attached my petalinux folder structure.

 

Best Regards,

0 Kudos
Scholar watari
Scholar
85 Views
Registered: ‎06-16-2013

Re: Compile Fortran lib.a for Linux under Zynq-7000 platform

Jump to solution

Hi @marcorodasyderal 

 

Did you turn on a recipe of gcc by petalinux-config ?

If no, would you do it first ?

Pherhaps, if you find a recipe of fortran, it might succeed.

 

Best regards,

 

0 Kudos
Scholar watari
Scholar
83 Views
Registered: ‎06-16-2013

Re: Compile Fortran lib.a for Linux under Zynq-7000 platform

Jump to solution

Hi @marcorodasyderal 

 

If you use cross compile platform to build your application, I suggest you to build libfortran.so and deply it or build your elf file as static link with libfortran.so.

 

Best regards,

0 Kudos
56 Views
Registered: ‎02-19-2019

Re: Compile Fortran lib.a for Linux under Zynq-7000 platform

Jump to solution

Hi @watari ,

So, I have managed to interface fortran code with C on my target board: here is how:

I am compilling the fortran code and linking the object file with the c file. I can copy the executable and it runs on my target. 

 

$ arm-linux-gnueabihf-gfortran-4.8 -c circle_file.f90
$ arm-linux-gnueabihf-gcc-4.8 -c main.c
$ arm-linux-gnueabihf-gcc-4.8 -o out_crossi.a circle_file.o main.o -lm -lgfortran

 

my main.c and circle_file.f90:

 

#include "stdio.h"
extern float area_of_circle_(float *val);

int main(void) {
        printf("hello assembly interface! \n");
        float val, ret = 0;
        val = 4.0;
        ret = area_of_circle_(&val);
        printf("val = %f\n", ret);
        return 0;
}

 

! this function computes the area of a circle with radius r  
function area_of_circle (r)

! function result     
implicit none

   ! dummy arguments        
   real :: area_of_circle

   integer :: i

   ! local variables 
   real :: r
   real :: pi

   pi = 4 * atan (1.0)
   area_of_circle = 2 * (pi * r**2)

end function area_of_circle

 

 

... however

If I add another function to "write_to_file" as follow: 

 

function write_to_file ()
   real, dimension(100) :: x, y
   real, dimension(100) :: p, q
   integer :: i

   ! data  
   do i=1,100
      x(i) = i * 0.1
      y(i) = sin(x(i)) * (1-cos(x(i)/3.0))
   end do

   ! output data into a file 
   open(1, file = 'data1.dat', status = 'new')
   do i=1,100
      write(1,*) x(i), y(i)
   end do
   close(1)

end function write_to_file
#include "stdio.h"

extern float area_of_circle_(float *val);
extern void write_to_file_(void);

int main(void) {
        printf("hello assembly interface! \n");

        float val, ret = 0;
        val = 4.0;

        ret = area_of_circle_(&val);
        printf("val = %f\n", ret);

        printf("calling write_to_file!!\n");
        write_to_file_();
        return 0;
}

 

Compiles just fine but when tried to run it on my target it complains:

./out_crossi.a: error while loading shared libraries: libgfortran.so.3: cannot open shared object file: No such file or directory

I have checked and there is a ligfortran on my gcc-cross/ dir under /usr/lib/gcc-cross/arm-linux-gnueabihf/4.8, so I have tried linking my cross compiled library:

$ arm-linux-gnueabihf-gcc-4.8 -o out_crossi.a circle_file.o main.o -L/usr/lib/gcc-cross/arm-linux-gnueabihf/4.8 -lm

but no success.

Question: Can I link and include the ligfortran under /usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/libgfortran.so, so then my executable gets all the pre defined libraries from fortran?

Thanks for your help.

Best Regards,

Marco

 

0 Kudos
Scholar watari
Scholar
45 Views
Registered: ‎06-16-2013

Re: Compile Fortran lib.a for Linux under Zynq-7000 platform

Jump to solution

Hi @marcorodasyderal 

 

I'm not familier with fortran and its environment.

But if you can prepare static link library for fortran, you can build elf with static library.

 

Would you add "-static" option to an argument of gcc ?

 

 /usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/libgfortran.so

 

Would you execute the following command ?

 

$ file  /usr/lib/gcc-cross/arm-linux-gnueabihf/4.8/libgfortran.so

 

After that, if this library file is suitable, I suggest you to copy this dynamic link library to suitable directory on your target device.

You will resolve it.

 

Best regards,

0 Kudos
33 Views
Registered: ‎02-19-2019

Re: Compile Fortran lib.a for Linux under Zynq-7000 platform

Jump to solution

Hi @watari ,

I have managed to croo-compile the Fortran and C code and run it on my target board. Here is how (done on the host PC running Ubuntu-16.04):

# Compile the Fortran code without linking. Outputs an object file that is later on linked to my main.o object file.
$ arm-linux-gnueabihf-gfortran-4.8 -c circle_file.f90
$ arm-linux-gnueabihf-gcc-4.8 -c main.c
# Links both object files from the C and Fortran code into an executable file. Libraries Math and ligfortran need to be linked as well. 
$ arm-linux-gnueabihf-gcc-4.8 -o out_cross.a circle_file.o main.o -lm -lgfortran

Then, I have copied my executable out_cross.a and the libgfortran.so to my target board under /home/root, export LD_LIBRARY_PATH=/home/root variable an dit worked.

Thanks a lot for your help.

Best Regards,

Marco

0 Kudos