Cmdstan won't compile if there is a model.r file present

(I am asking here before opening an issue in case it is something trivial)

Using cmdstan master (e45ceca604c0af), the makefile does not work when there is an .r file present with the same name as the .stan file. Instead, it calls the f77 compiler for some reason.

tamas@tamas-fedora ~/src/cmdstan % mkdir /tmp/test    
tamas@tamas-fedora ~/src/cmdstan % touch /tmp/test/test.r
tamas@tamas-fedora ~/src/cmdstan % touch /tmp/test/test.stan
tamas@tamas-fedora ~/src/cmdstan % make /tmp/test/test
f77         -Wl,-L,"/home/tamas/src/cmdstan/stan/lib/stan_math/lib/tbb"   -Wl,-rpath,"/home/tamas/src/cmdstan/stan/lib/stan_math/lib/tbb"      /tmp/test/test.r        -ltbb   -o /tmp/test/test
getopt: invalid option -- 'W'
getopt: invalid option -- 'l'
getopt: invalid option -- ','
getopt: invalid option -- '-'
getopt: invalid option -- 'W'
getopt: invalid option -- 'l'
getopt: invalid option -- ','
getopt: invalid option -- '-'
getopt: invalid option -- 'l'
Ignoring -rpath,/home/tamas/src/cmdstan/stan/lib/stan_math/lib/tbb
invalid parameter -t
invalid parameter bb
/usr/bin/f77: line 292: ratfor: command not found
make: *** [<builtin>: /tmp/test/test] Error 127

Operating System: Fedora 41
Interface Version: cmdstan 2.36.0 / master e45ceca604c0af
Compiler/Toolkit: make 4.4.1

1 Like

Haha this is a funny one. Some guesses

  • because your target had the same root as the .r file, something goes wrong with pattern substitution and somehow the .r file is compiled
  • .r is a file extension for Fortran 77 files that contain ‘ratfor’ rational Fortran extensions
  • for the above reason, the gnu tool chain calls f77, which wants to invoke ratfor but can’t find it, hence your final error
2 Likes

I took a look. I can reproduce it. This is some surprising (to me) make behaviour and nothing to do with Stan. If you do,

mkdir test_make_behaviour
cd test_make_behaviour
touch foo.r
make foo

you will see:

f77    foo.r   -o foo

That is, make automatically tries to compile the *.r as f77. Similar things happen with other file types. I never knew this. But it turns out that make has some implicit rules that are applied (even in this case when we have no makefile). You can see them by

make -p

We can disable implict rules by placing the empty target

# disable implicit rules
.SUFFIXES:

in the cmdstan-2.3.5/makefile. The implicit rule that causes this is indeed this one for Ratfor.

We could be more specific in cancelling the implicit rules (see here), but cancelling them all might be best.

Alternatively, if people see these weird things, they could just run

make --no-builtin-rules <target>

instead.

4 Likes

Thanks for looking into it! I did not know about implicit rules either.

Will you make a PR?

Yes I think I will. This shows that the implicit rules can interact badly with the match anything rule used in Stan.

3 Likes

Thanks for reporting, @tpapp—that’s a really nasty interaction for stats code.

Calling @syclik, who wrote a lot of the makefile code or @WardBrian and @stevebronder, who’ve been managing a lot of it since.

1 Like

Disabling the implicit suffix behavior would be great, we’d need to check that something like SUNDIALS doesn’t rely on it

2 Likes

This should be fixed in the next version. Thanks for reporting and thank you to @andrewfowlie for chasing down why it was happening!

3 Likes

@WardBrian: thanks. Can you please link the issue/PR? I could not find it.