Hi,
> I have a question with llvm-gcc and llvm-gfortran.
> Is it possible that llvm-ld can combine different bc files
> compiled from C programme and Fortran Programme together?
yes you can, but you will need to link in the appropriate
libraries when producing the final executable.
> For example:
> Compile a c program into llvm bc file by the task:
> # llvm-gcc -emit-llvm test.c -c -o test.bc
> and then compile a fortran program into llvm bc file by the task:
> # llvm-gfortran -emit-llvm testf.f -c -o testf.bc
> And then use llvm-ld to combine two bc files into a single bc file as
follows:
> # llvm-ld test.bc testf.bc -o testp.bc
Here you have produced a new bitcode file rather than
a native executable (use the -native option if you want
a real executable).
> # ./testp.bc
> ERROR: Program used external function '_gfortran_st_write' which
could not be resolved!
You need to provide libgfortran. If you link a Fortran program
using llvm-gfortran then it automatically adds libgfortran to the
link line.
> I have also tried to link gfortran dynamic libraries like this and here is
a error message:
> # llvm-ld test.bc testf.bc -lgfortran
> llvm-ld: error: Cannot find library 'gfortran'
> Note:gcc can find library 'gfortran'.
There are most likely two problems here: (1) llvm-ld can't
find libgfortran - it is not in the search path. Use the
-L option. For example, on my machine libgfortran is
/usr/local/gnat-llvm/lib64/libgfortran.a
so I could either specify that file with a full path, or
use -L/usr/local/gnat-llvm/lib64/ -lgfortran
(2) Since libgfortran does not contain bitcode but normal
object code, supplying it to llvm-ld will not have much
effect unless you give llvm-ld the -native option.
Best wishes,
Duncan.