Intel编译器:将fortran编译的库链接到C的主程序。

时间:2021-03-05 22:49:47

So I wanted to use a special maths function but couldn't find a C library that had it, however I found an old Fortran library slatec that had implemented it, so in order to use it, I adapted these instructions to my case :http://difdop.polytechnique.fr/wiki/index.php/How_to_Bessel_Functions_in_C

所以我想使用一个特殊的数学函数,但是找不到一个C库,但是我找到了一个旧的Fortran库slatec,它已经实现了它,所以为了使用它,我将这些指令修改为:http://difdop.polytechnique.fr/wiki/index.php/How_to_Bessel_Functions_in_C。

I'm using a makefile to compile, here's an extract of its contents in the GNU case

我正在使用makefile来编译,这是它在GNU案例中的内容的摘录。

CFLAGS=-Wall -O2
CC=gcc
MPICC=mpicc -DDEBUG_INPUT
LIBS=-lm -lgfortran

THIS_DIR=$(shell pwd)

WEAKWEAK_OBJECTS=manager_weakweak.o worker_weakweak.o bunch_weak.o transform_weak.o cyclic_array.o
WEAKSTRONG_OBJECTS=manager_weakstrong.o worker_weakstrong.o bunch_strong.o fbi_weakstrong.o rw_weakstrong.o
../mbtrack-mpi : ./besselh/libamos.a mbtrack-mpi.o confmpi.o input.o test.o ${WEAKWEAK_OBJECTS} ${WEAKSTRONG_OBJECTS} bunch.o stats.o physic.o statistics.o tracking.o rw_table.o rw_new.o lagrange.o feedback.o nrutil.o
    ${MPICC} $(CFLAGS) $^ -o $@ $(LIBS) -L$(THIS_DIR)/besselh $(THIS_DIR)/besselh/libamos.a

Everything works marvelously with the GNU compilers, but I am currently trying to compile on a cluster that predominantly uses Intel Compilers, and -lgfortran is not found.

所有的一切都与GNU编译器很好地工作,但是我现在正在尝试编译一个主要使用Intel编译器的集群,而-lgfortran没有被发现。

I read up in Intel's documentation that using the -nofor-main flag should allow the linking to occur, but the compiler just complains about a linking error:

我在Intel的文档中读到,使用-nofor-main标志应该允许链接发生,但是编译器只是抱怨链接错误:

    cc -DDEBUG_INPUT -Wall -O2  -I/opt/local/include besselh/libamos.a mbtrack-mpi.o 
 confmpi.o input.o test.o manager_weakweak.o worker_weakweak.o bunch_weak.o 
 transform_weak.o cyclic_array.o manager_weakstrong.o worker_weakstrong.o 
 bunch_strong.o fbi_weakstrong.o rw_weakstrong.o bunch.o stats.o physic.o statistics.o 
 tracking.o rw_table.o rw_new.o lagrange.o feedback.o nrutil.o -o ../mbtrack-mpi -lm -
 lifcore -lifcoremt  -L/global/u1/j/jackb/work/new_rw_2/src/besselh 
 /global/u1/j/jackb/work/new_rw_2/src/besselh/libamos.a

/opt/intel/composer_xe_2013_sp1.2.144/compiler/lib/intel64/libifcore.a(for_main.o): dans la fonction « main »:

for_main.c:(.text+0x54): référence indéfinie vers « MAIN__ »
/usr/bin/ld: erreurs de lien trouvés, destruction de l'exécutable « ../mbtrack-mpi »
make: *** [../mbtrack-mpi] Erreur 1

I was wondering if there was anything as simple as the -lgfortran library flag that I used with the GNU compilers?

我想知道是否有任何东西像我与GNU编译器使用的-lgfortran库标志一样简单?

In an attempt to adapt the compilers on the cluster:

试图调整集群的编译器:

Here is the rule to compile the library:

下面是编译该库的规则:

   ./besselh/libamos.a : FORCE
               cd besselh/; $(MAKE) libamos.a

And the contents of the Makefile in the besselh directory:

以及besselh目录中Makefile的内容:

libamos.a: $(files_o)
#       ftn -nofor-main -fdefault-real-8 -fdefault-double-8 -c $(files_f)
        ar cru libamos.a $(files_o)
        ranlib libamos.a

$(files_o): $(files_f)
        ftn -nofor-main -c $(files_f)
clean: 
        rm -f $(files_o)
        rm -f libamos.a

1 个解决方案

#1


1  

If you just want Bessel functions in C, aren't those in the C99 standard enough? http://www.gnu.org/software/libc/manual/html_node/Special-Functions.html

如果你只是想要在C中使用贝塞尔函数,那么C99的标准还不够吗?http://www.gnu.org/software/libc/manual/html_node/Special-Functions.html

The correct option to disable the Fortran specific main in Intel Fortran is -nofor-main.

在Intel Fortran中禁用Fortran特定main的正确选项是-nofor-main。

libgfortran is the Fortran runtime library of gfortran. If you compiled the Fortran subroutines with gfortran and are just calling them from C source compiled with icc it should work.

libgfortran是gfortran的Fortran运行时库。如果使用gfortran编译Fortran子例程,并将它们从由icc编译的C源代码中调用,那么它应该可以工作。

If you are using Intel Fortran, then it of course doesn't have it. It has its own runtime libraries libifcore and libifcoremt. You should link them via -lifcore -lifcoremt or by linking using ifort instead of icc. But it is quite likely you will not need them.

如果你使用的是英特尔Fortran,那么它当然没有。它有自己的运行时库libifcore和libifcoremt。你应该通过-lifcore -lifcoremt或使用ifort而不是icc来链接它们。但你很可能不需要它们。

Finally, it shouldn't be a problem to find a C library. Try the GNU Scientific Library. I think the Intel's MKL contains them too.

最后,找到一个C库应该不是问题。试试GNU科学图书馆。我认为英特尔的MKL也包含它们。

#1


1  

If you just want Bessel functions in C, aren't those in the C99 standard enough? http://www.gnu.org/software/libc/manual/html_node/Special-Functions.html

如果你只是想要在C中使用贝塞尔函数,那么C99的标准还不够吗?http://www.gnu.org/software/libc/manual/html_node/Special-Functions.html

The correct option to disable the Fortran specific main in Intel Fortran is -nofor-main.

在Intel Fortran中禁用Fortran特定main的正确选项是-nofor-main。

libgfortran is the Fortran runtime library of gfortran. If you compiled the Fortran subroutines with gfortran and are just calling them from C source compiled with icc it should work.

libgfortran是gfortran的Fortran运行时库。如果使用gfortran编译Fortran子例程,并将它们从由icc编译的C源代码中调用,那么它应该可以工作。

If you are using Intel Fortran, then it of course doesn't have it. It has its own runtime libraries libifcore and libifcoremt. You should link them via -lifcore -lifcoremt or by linking using ifort instead of icc. But it is quite likely you will not need them.

如果你使用的是英特尔Fortran,那么它当然没有。它有自己的运行时库libifcore和libifcoremt。你应该通过-lifcore -lifcoremt或使用ifort而不是icc来链接它们。但你很可能不需要它们。

Finally, it shouldn't be a problem to find a C library. Try the GNU Scientific Library. I think the Intel's MKL contains them too.

最后,找到一个C库应该不是问题。试试GNU科学图书馆。我认为英特尔的MKL也包含它们。