1

A while back I asked a question about this subject and "solved" it by using Cygwin instead with its XWin utility, but I've come back to this issue again since the Xwin utility does not use my GPU and creates a severe bottleneck in simulations as a result. MinGW/MSYS on the other hand DOES use my GPU for rendering, which is a huge help, but there are some rough areas that need smoothing over, specifically with readlink.

Basically, the src/makefile for rebound (https://github.com/hannorein/rebound) says this:

PREDEF+= -D$(shell basename `readlink gravity.c` '.c' | tr '[a-z]' '[A-Z]')
PREDEF+= -D$(shell basename `readlink boundaries.c` '.c' | tr '[a-z]' '[A-Z]')
PREDEF+= -D$(shell basename `readlink collisions.c` '.c' | tr '[a-z]' '[A-Z]')

If my understanding is correct, this is supposed to find which version of gravity, boundaries and collisions I specified, and adds that to PREDEFS so the compiler uses the right versions of gravity, boundaries and collisions. However, it does not seem to work in MSYS. What it ends up spitting out for predefs is this:

-DOPENGL -D.C -D.C -D.C

Obviously it did not get anything back from the code above. This results in a macronames must be identifiers error, of course. I can work around this by adding any of the special options in between readlink and the filename, like -f, for instance, but then it only spits out

-DOPENGL -DGRAVITY -DBOUNDARIES -DCOLLISIONS

Which is not right because it should have extra bits, like so:

-DOPENGL -DGRAVITY_DIRECT -DBOUNDARIES_OPEN -DCOLLISIONS_NONE

Now, if I don't want any special gravity, boundaries or collisions, the workaround is okay, but only because (I'm guessing) it defaults to those if there's nothing special specified after each macroname. But if I DO want something special, like the more efficient gravity tree code, or actual collisions, the shortened name resulting from the workaround will not help it find anything, and so it causes errors in compiling as certain functions it needed from the special files obviously are missing.

And so I'm pretty stuck at the moment. I would like very much to be able to use other codes than the defaults, but MSYS is acting funny with the readlink and not finding the right stuff. As I said, it worked fine in an X windows style compiler. I feel like there must be some library I'm missing or some hidden syntax disconnect I'm overlooking that needs to be accounted for between XWin and non-Xwin compiling, but I can't find anything.

Here's an example of the links it should be reading (at least I think this is what is being read, I'm still learning makefiles):

ln -fs gravity_tree.c ../../src/gravity.c
ln -fs boundaries_open.c ../../src/boundaries.c
ln -fs collisions_none.c ../../src/collisions.c

If anyone can tell me why this would work on an Xwin command line but not MSYS, I'd greatly appreciate it.

spacemoose
  • 11
  • 5
  • What does `ls -l` say on those `src/gravity/*.c` files from whatever terminal/etc. you are running make from? If you run `make SHELL+=-x` you should be able to see the calls to `readlink` in the output and that might tell you something useful. – Etan Reisner Jul 24 '15 at 19:19
  • I'm sorry, I'm not sure if this is what you meant, but using ls -l in the folder in the src folder where all the gravity*.c files does fine gravity_direct.c, gravity_tree.c, gravity_grape.c, gravity_fft.c and a few others, though I'm not sure if this is the information you wanted. As for the make SHELL+=-x, I tried to run that in MSYS and it did not knwo what do do with -x. – spacemoose Jul 24 '15 at 19:28
  • You tried to run what exactly and what happened exactly? With newer make you need `make SHELLFLAGS+=-x` I think or possibly `make SHELLFLAGS+=' -x'`. – Etan Reisner Jul 24 '15 at 19:36
  • I asked for `ls -l` in the `../../src/` directory. – Etan Reisner Jul 24 '15 at 19:36
  • It did not find the command -x, but it did not havethat issue with `SHELLFLAGS+=-x`. However, after entering `make SHELLFLAGS+=-x`, it ran as normal, but no extra information was displayed; here's what the compiler showed: [http://i.imgur.com/U1O4qp1.png] – spacemoose Jul 24 '15 at 19:38
  • Sorry, messed up the image, here: http://i.imgur.com/U1O4qp1.png – spacemoose Jul 24 '15 at 19:45
  • What is creating those links because if the `readlink` call is happening *from* the `src` directory they are incorrect (unless the targets of the links are *also* in the `src` directory which perhaps they are). – Etan Reisner Jul 24 '15 at 19:46
  • The `SHELLFLAGS` might be getting lost in the recursive makefile call. Does the makefile use `$(MAKE)` or `make`? Can you edit that line or run the recursive make call directly? – Etan Reisner Jul 24 '15 at 19:47
  • The targets are in the `src` directory - as I understand it, it is trying to create a link to gravity_tree.c in the simulation I'm trying to use right now, which is in the `rebound-master/src` directory where this makefile with the `readlink` command is – spacemoose Jul 24 '15 at 19:49
  • Are the links there now? Can you run `readlink` on them manually? Does it work? What does `ls -l /c/rebound-master/src/{gravity,boundaries,collisions}.c` output? What do you get if you run `make -C ../../src SHELLFLAGS+=-x`? – Etan Reisner Jul 24 '15 at 19:50
  • The first makefile uses `$(MAKE)` to call the next one in the `src` directory. I added `SHELLFLAGS+=-x` to that line, but I don't see any more information than before when running the make. I tried replacing `$(MAKE)` with `make` while still keeping the `SHELLFLAGS+=-x` addition and it still did not return anymore information. – spacemoose Jul 24 '15 at 19:56
  • The output with `ls -l`: http://i.imgur.com/WzmPLQA.png If I use `readlink gravity.c` in the `src` directory, nothing happens. Same with the tree, direct, and all the other variants. Ditto for the boundaries and collisions. Here is `make -C ../../src SHELLFLAGS+=-x`: http://i.imgur.com/XhSOXu6.png – spacemoose Jul 24 '15 at 20:07
  • Okay, I put in `readlink -v` in the makefile in order to get some info, and I just get a bunch of `readlink: gravity.c: Invalid Argument` messages, though. And that goes for the boundaries and collisions too. – spacemoose Jul 24 '15 at 20:23
  • Yeah, those aren't links. Those are normal files. MSYS `ln` appears to have copied the files (assuming MSYS `ln` is what made them). Presumably it doesn't have the translation layer to make symlinks works. Can you compile in cygwin and run in MSYS? – Etan Reisner Jul 24 '15 at 20:40
  • It does not appear to let me do that - I added the cygwin files to the path after the initial complaining it did about missing dlls but it still won't go on MSYS. I can get everything to work with the latest version of rebound but the simulations I've been working on are not ported over and it would be a massive undertaking which there is not time for right now. As long as I don't need any of the special functions, it's adequate, and I suppose later work will be in the newer rebound which did away with a lot of symbolic links. Thank you for all the help, despite my cluelessness. – spacemoose Jul 24 '15 at 20:50
  • That is, the newest version of rebound compiles fine on MSYS as long as add in the proper libraries for opengl on windows. – spacemoose Jul 24 '15 at 20:51

1 Answers1

0

Why on earth do you expect readlink to work in MSYS? Where did you even get whatever readlink.exe is being invoked, (if that is what is being executed)? There is no readlink command in a standard MSYS installation. Perhaps you discovered it in MinGW.org's msys-coreutils-ext package? If this is the case, you should note the comment within the description of that package, (as seen via MinGW.org's mingw-get installer):

The msys-coreutils-bin subpackage contains those applications that were historically part of the standard MSYS installation. The associated msys-coreutils-ext subpackage contains the rest of the coreutils applications that have been (nominally) ported to MSYS -- usually these are less often used, and are not guaranteed to work: e.g. 'su.exe', 'chroot.exe' and 'mkfifo.exe' are known to be broken.

and, it seems that we may add readlink.exe to that list of "known to be broken" applications.

It may also be worth noting that readlink is not among the list of supporting tools, which a GNU Coding Standards conforming application is permitted to invoke from either its configure script, or its makefile. Thus, there is little incentive for the MinGW.org developers, (who maintain MSYS), to address the issue of making readlink.exe work, (although patches from an independent developer, with such an incentive, would be welcomed).

As a final qualification, and as one comment on the question notes, ln -s creates copies of files; it does not create symbolic links. How could it? MSYS itself dates from an era when windows didn't support symbolic links ... indeed, even today its support for them is flaky. At the time when MSYS was published, either copying the files, or creating NTFS hard links, was the best compromise MSYS could offer, in the situation where a script invoked ln -s. Consequently, it would become incumbent upon any developer submitting patches to make readlink.exe work, to also address the issue of updating ln.exe, such that it could create the symbolic links, (in an OS version dependent fashion), which readlink.exe would then read.

I'm sorry if this isn't the answer you hoped for, but unless someone devotes some effort into updating MSYS, so that it can make use of the (unreliable) symbolic link feature in more recent windows versions, then you need to find a different approach; current MSYS does not support symbolic links, even if the underlying OS now does.

Keith Marshall
  • 1,980
  • 15
  • 19
  • MSYS DOES provide a readlink command, although it is not included in the standard installation for the purpose of remaining lean. It may be found in the coreutils-ext package. On my installation, mingw-get-install doesn't show it, but the package may be downloaded directly here: http://sourceforge.net/projects/mingw/files/MSYS/Base/coreutils/coreutils-5.97-3/coreutils-5.97-3-msys-1.0.13-ext.tar.lzma/download. GnuWin32 also provides a version of readlink. Currently neither of these works for me on NTFS junction points. – stellarpower Sep 25 '15 at 17:14
  • If you read mingw-get's package description for msys-coreutils-ext, @stellarpower, you may note that the programs it provides are (mostly) untested, and definitely not guaranteed to work, so no surprise that `readlink` doesn't. Windows junction points bear absolutely no resemblance, in their implementation, to the symbolic links on the POSIX platforms for which readlink was written, so again, no surprise that it can't interpret them. The implementation which you have found is a gratuitous port which isn't expected to work, nor is this likely to change in the foreseeable future. – Keith Marshall Sep 25 '15 at 21:21
  • Thank you, I just meant to point out that as MSYS includes a readlink command, that may be where spacemoose got the command, and that as it is provided in the repositories one would believe that the port had implemented some functionality, I didn't see the description and went straight to downloading and testing, hoping it might work, but it fails for Windows symlinks too - a shame as I've found a few programs that can't handle links on Windows whereas on *nix they may be used transparently. I found the junction.exe tool provided by Microsoft useful, if piped into grep or something similar. – stellarpower Sep 25 '15 at 22:21