I am trying to get a 'hello world' type program compiled in FreeBSD 12 with flang.
This is my source code:
PROGRAM MAIN
INTEGER :: X
PRINT *, "Please, enter a number"
READ (*, *) X
PRINT *, "The square root of ", X, " is ", SQRT(X)
END PROGRAM MAIN
I try to compile it without success using:
$ flang -o test test.f90
/usr/local/bin/ld: /tmp/test-8e54ee.o: in function `MAIN_':
/usr/home/user/test/test.f90:6: undefined reference to `sqrt_'
/usr/local/bin/ld: /usr/local/flang/lib/libflangrti.so: undefined reference to `backtrace_symbols'
/usr/local/bin/ld: /usr/local/flang/lib/libflangrti.so: undefined reference to `backtrace'
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)
It has been a long time since last time I used Fortran and it is definitively the first time I try to compile it with FreeBSD. Any help/hint is welcomed.
I was able to get around the first problem ("undefined reference to sqrt_") by declaring
XasThis makes sense, because
SQRTin Fortran is defined for real numbers (otherwise it is not clear whatKINDthe returnedREALresult would have), so flang does not resolve the call and expects that it is a reference to your own custom function defined somewhere else in the code.As for the second problem ("undefined reference to backtrace_symbols"), this seems to me as a mess in installation. I have just installed a clean FreeBSD 12 into VirtualBox and the linker is in "/usr/bin/ld", and this is where it is looked for by flang, as apparent from the verbose output: