" __ gfortran_pow_c8_i4"从g ++和gfortran使用g ++连接.o文件时出错 [英] "__gfortran_pow_c8_i4" error when linking .o files from g++ and gfortran using g++
问题描述
g ++ - 我试图链接使用g ++生成的.o文件和使用gfortran生成的另一个.o文件。 c mycppcode.cpp
生成文件 mycppcode.o
和命令
gfortran -c myfortrancode.f
生成文件 myfortrancode.o
当我链接这两个文件得到一个输出文件
g ++ -O mycppcode.o myfortrancode.o
我得到以下错误:
架构x86_64的未定义符号:
__gfortran_pow_c8_i4,引用自:
有人可以帮忙我和这个?我应该使用其他编译器吗?另外,我想知道哪些函数或子程序调用了__gfortran_pow_c8_i4,以便我可以尝试在将来避免fortran中的这些函数或子程序。 解决方案
以下假设您使用的是GNU编译器工具。如果你使用其他编译器,情况可能会有所不同。
你可以使用编译器将两者连接在一起,但你需要提供合适的库。 >
通常,您可以使用
gfortran fortobj.o cppobj.o - lstdc ++
或
g ++ fortobj.o cppobj.o -lgfortran
这里假定您正在使用设置两个编译器都知道彼此的库(例如,如果你通过一个Linux库安装)。
OP编译器来自XCode, gfortran
来自自制软件 。在这种情况下, gfortran
知道 g ++
库(因为它们用于编译编译器),但 g ++
不知道 gfortran
库。这就是为什么使用 gfortran
进行链接的原因,如上所述。但是,要连接 g ++
,需要在使用 -L
标志,如
g ++ fortobj.o cppobj.o -L / path / to / fortran / libs -lgfortran
如果由于某种原因您的 gfortran
编译器不知道你的 g ++
libs,你会这样做
gfortran fortobj.o cppobj.o -L / path / to / c ++ / libs -lstdc ++
< hr>
请注意,最终的可执行文件不应该有任何区别。我不是编译器专家,但我的理解是,使用编译器将对象链接在一起可以方便地调用链接器(在类UNIX操作系统上的 ld
)适当的库与您正在使用的语言相关联。因此,只要包含正确的库,使用一个编译器或其他链接即可,无关紧要。
I am trying to link a .o file generated using g++ and another .o file generated using gfortran.
g++ -c mycppcode.cpp
produces the file mycppcode.o
and the command
gfortran -c myfortrancode.f
produces the file myfortrancode.o
When I link these two files to get an output file
g++ -O mycppcode.o myfortrancode.o
I get the following error
Undefined symbols for architecture x86_64:
"__gfortran_pow_c8_i4", referenced from:
Could some one help me with this? Should I use another compiler? Also, I would like to know what functions or subroutines call "__gfortran_pow_c8_i4", so that I can try to avoid these functions or subroutines in fortran in future.
The following assumes you are using the GNU compiler tools. Things may be slightly different if you are using other compilers.
You can use either compiler to link the two together, but you need to provide the appropriate libraries.
Typically, you can use either
gfortran fortobj.o cppobj.o -lstdc++
or
g++ fortobj.o cppobj.o -lgfortran
This assumes that you are using a setup where both compilers know about each other's libraries (like if you installed through a linux repository).
In the case of the OP the C compilers came from XCode and gfortran
is from homebrew. In that case, gfortran
knows about the g++
libraries (since they were used to compile the compiler), but g++
doesn't know about the gfortran
libraries. This is why using gfortran
to link worked as advertised above. However, to link with g++
you need to add the path to libgfortran.* when you call the linker using the -L
flag, like
g++ fortobj.o cppobj.o -L/path/to/fortran/libs -lgfortran
If for some reason your gfortran
compiler is unaware of your g++
libs, you would do
gfortran fortobj.o cppobj.o -L/path/to/c++/libs -lstdc++
Note that there shouldn't be any difference in the final executable. I'm no compiler expert, but my understanding is that using the compiler to link your objects together is a convenience for calling the linker (ld
on UNIX-like OS's) with the appropriate libraries associated with the language you are using. Therefore, using one compiler or the other to link shouldn't matter, as long as the right libraries are included.
这篇关于" __ gfortran_pow_c8_i4"从g ++和gfortran使用g ++连接.o文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!