Closed jaxxstorm closed 2 years ago
I get something similar for this simple test case:
brew install json-fortran
test.f90:
program test
use json_module
implicit none
type(json_core) :: json
call json%initialize()
if (json%failed()) error stop 'error'
end program test
gfortran test.f90 -o hello -I /opt/homebrew/Cellar/json-fortran/8.2.5/include/
gives:
Undefined symbols for architecture arm64:
"___json_value_module_MOD___vtab_json_value_module_Json_core", referenced from:
_MAIN__ in ccr11AMx.o
"___json_value_module_MOD_json_failed", referenced from:
_MAIN__ in ccr11AMx.o
"___json_value_module_MOD_json_initialize", referenced from:
_MAIN__ in ccr11AMx.o
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
System:
I don't normally use json-fortran from Home-brew though. Did this used to work? Maybe it broke at some point?
Oh, you forgot to actually link with the library. So something like this:
gfortran test.f90 -o hello -I /opt/homebrew/Cellar/json-fortran/8.2.5/include/ /opt/homebrew/Cellar/json-fortran/8.2.5/lib/libjsonfortran.a
That works for me.
Or, you add the lib path and you can do it like this:
gfortran test.f90 -o hello -I /opt/homebrew/Cellar/json-fortran/8.2.5/include/ -L /opt/homebrew/Cellar/json-fortran/8.2.5/lib -ljsonfortran
That got it! For anyone else who comes across this:
gfortran example.f90 -o hello -I $(brew --prefix)/Cellar/json-fortran/8.2.5/include/ $(brew --prefix)/Cellar/json-fortran/8.2.5/lib/libjsonfortran.a
Hi,
Can anyone help me with this issue I have when I was compiling Fortran code on my Mac (M1)? It looks like a similar issue as @jaxxstorm post but I still really cannot figure it out. I'm very new to compiling Fortran code:
so I have the following Fortran code (.f) files. They are main and subroutine code files of a model that I want to run on my Mac.
so I firstly use the following to get .o files
gfortran -c sutra_3_0.f fmods_3_0.f lmods_3_0.f lsubs_3_0.f ssubs_3_0.f usubs_3_0.f
then I tried to use the .o files to compile the code so I can run the model (using sutra3_mac), as below:
gfortran -o sutra3_mac fmods_3_0.o lmods_3_0.o lsubs_3_0.o ssubs_3_0.o usubs_3_0.o
but it gave me this error
I'm still not clear about how to link the library. I located the library of gfortran installed on my Mac:
and under /usr/local/gfortran/lib folder it has the following:
and under /usr/local/gfortran/lib/gcc/aarch64-apple-darwin22/12.2.0 it has the following:
Can someone provide any guidance on compiling the code? Thanks a lot!
I installed the lib from homebrew, and trying to compile my first program:
I'm new to fortran, any idea what I've done wrong here?