无法编译Fortran模块:未定义的符号_main [英] Can't compile Fortran modules: Undefined symbol _main
问题描述
我最近一直在尝试在Fotran中使用库,但是我一直不断收到此错误消息
I've been trying lately to use libraries in Fotran, but I kept on getting this error message
体系结构x86_64的未定义符号: "_main",引用自: 主可执行文件的隐式输入/启动 ld:找不到架构x86_64的符号 collect2:错误:ld返回1退出状态
Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executable ld: symbol(s) not found for architecture x86_64 collect2: error: ld returned 1 exit status
我找不到针对它的任何特定解决方案.在这种情况下,我正在使用我为测试目的编写的简单模块来构建自己的一些库(此问题发生在静态库和共享库中).
which I cound't find any specific solution to it. In this case, I was working with some libraries that I built myself (this problem happened with static and shared libraries) from simples modules I wrote for purposses of tests.
当时我决定只尝试使用模块,并且不断收到与所使用模块相同的错误消息.我想知道是否有人可以帮助我判断我是否使用了错误的语法.这是模块
I decided to try only the modules then, and I kept getting the same error message regardes of the module I used. I would like to know if someone can help me on telling if I am using incorrect syntax. Here is the module
module modulo1
IMPLICIT NONE
real, parameter:: pi=3.1415
end module modulo1
这是主要的
program teste
use modulo1
IMPLICIT NONE
real :: r = 2
write (*,*) 'Área: ', pi*r**2
end program teste
这些是我用来编译的命令
These were the commands I used for compiling
gfortran -c modulo1.f90
gfortran -c teste.f90
gfortran -o teste.o modulo1.o
推荐答案
您的编译已损坏.命令
gfortran -o teste.o modulo1.o
告诉gfortran
从名为modulo1.o
的目标文件中创建名为teste.o
的可执行文件.由于该模块文件不包含program
,因此编译器无法找到其尝试构建的可执行文件的入口点. -o
选项的参数是要生成的可执行文件的名称.
tells gfortran
to create an executable called teste.o
from the object file called modulo1.o
. Since that module file doesn't contain a program
the compiler can't find an entry point for the executable it is trying to build. The argument to the -o
option is the name of the executable to build.
您可能应该用类似的内容代替该声明
You probably ought to replace that statement with something like
gfortran -o test teste.o modulo1.o
这将生成一个名为test
的可执行文件.
which will build an executable called test
.
从长远来看,学习如何使用make
或其他构建系统.
In the longer run learn how to use make
or another build system.
这篇关于无法编译Fortran模块:未定义的符号_main的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!