0

I am currently porting some software from an old Power Hawk to an iHawk Concurrent system. My fortran compiler is the Concurrent cf77 . No, I don't have the option to switch to gfortran, I need some compiler flags of this compiler.

In multiple *.f files I need the length of continuous characters let's call them "strings". In the past we had a company internal library providing me therefore a function lstr = lg(str) This function is now not available anymore. So the variables I am trying to get the length of are declared as following:

integer function number(str, state)
implicit none

character str*(*)
integer*1 z/ '30'x /
integer*2 j,i

j = lg(str) 
do i=1 , j
  num = ichar( str(i:i) ) - z
  if(num.lt.0) then
    state = 1
    return
  end if
end do
state= 0
return
end

So what I tried is this len() method instead of lg() but this gives me the compile error:

file.f: XXX undefined reference to `len_'

So I thought I am not this stupid, perhaps it is the do not add underscore problem, so for Concurrent it is sufficient to declare it as CEXTERNAL:

CEXTERNAL len

Haha , no the super not smart dev has now the following error:

file.f: XXX undefined reference to `len'

I am currently compiling / linking with the following flags:

cf77 -g --cpu=pentium -c -Nt5000 -lpthread $@
cf77 -g --cpu=pentium -o -Wl,-rpath-link=/usr/lib,-lc,/usr/lib/librt.a $@

Comment: --cpu=pentium is cross compiling for a 32-bit target machine on a 64-bit machine with a 64-bit compiler. with -Wl,-rpath-link= (...) I hand down the flags to the linker. If I leave that out like using only: -L/usr/lib -lc I get the following:

/usr/lib/librt.so: undefined reference to  `__pthread_unwind@GLIBC_PRIVATE'
/usr/lib/librt.so: undefined reference to ¸pthread_sigmask@GLIBC2.0'

etc. a bunch of them. Adding librt.a is resulting then the same. Only handing it down with -Wl,-rpath-link= arg, arg, arg is working.

Am I perhaps just missing the correct library? Is this len() method really doing what I need it for or do you have any suggestions?

Denise P
  • 81
  • 12
  • 2
    If you add `intrinsic len` early in the function `number` does that help? – francescalus May 24 '18 at 12:05
  • Does the compiler has its own runtime library in a separately linked library file? – Vladimir F Героям слава May 24 '18 at 12:10
  • Thank you so much @francescalus will you post the answer? I was not aware that I have to declare len() in this way! – Denise P May 24 '18 at 12:12
  • Often you do not have to, but it is compiler specific. – Vladimir F Героям слава May 24 '18 at 12:13
  • The compiler specific libraries are lhF77 lhI77, lhU77, lposix9 . I don't know if that helps, but declaring the method as intrinsic was sufficient. I need to hand over the librt.a to the linker, as there is a bug in the cf77 linking process. Otherwise he can't stop looking up the 64 - bit libraries and ending up finding nothing. – Denise P May 24 '18 at 12:18
  • If that does help, it would be useful if you could make the question contain a more complete example. That is, could you make a complete program? This would be good because: if there's something which "masks" the intrinsic `len` function we can address that; if there's something funny about this particular compiler we can talk about that instead. – francescalus May 24 '18 at 12:21
  • So that is pretty much the entire subroutine which contains the len() method. It is called from a function reading in a file containing different labels and later on it is used to take these labels reorder them and put them back together in another file. Was that what you thought of if you said complete program? @francescalus – Denise P May 24 '18 at 12:54
  • It's not (quite) a complete program. However, if you have a file with just that function, followed by `integer state; print*, number('2',state); end` then that could be a complete program. It will give you rubbish when run, because the function result isn't defined, but we just need to look at linking. – francescalus May 24 '18 at 12:59
  • So yesterday I gave up, as in the middle of my program the intrinsic function declaration did not work anymore , as if the compiler forgot the function. Although 20 lines before hand and the last other 800 it knew len() . This morning I had a second look. I mixed up lstr and str, so it tried to get str=len(lstr) and then thought oh this makes an int into an char somehow, that must be another function. So now with declaring instrinsic len in the beginning it works fine! – Denise P May 25 '18 at 08:19

0 Answers0