wren-lang / wren

The Wren Programming Language. Wren is a small, fast, class-based concurrent scripting language.
http://wren.io
MIT License
6.86k stars 550 forks source link

Crashing on windows with MinGW #125

Closed sbrl closed 9 years ago

sbrl commented 9 years ago

I don't really know much about C (or any compiled languages apart from C# really), but I saw this repository I thought that it looked interesting. I managed to compile it on windows after many google searches on my 64 bit Windows 7 laptop, and thought that I would share the batch file I wrote with you.

You can find it here: http://pastebin.com/WjLveE3r The resulting executable can be found here: http://s000.tinyupload.com/index.php?file_id=26581500537300048902

To use it, save the code to a .bat file in the root of the repository after you clone it. Once it has finished, you will find wren.exe located in the src\ folder. It outputs

a bunch of warnings, but it compiles ok.

This script requires the mingw gcc compiler.

MarcoLizza commented 9 years ago

I'm just forking the project and fixing the Visual Studio warnings (and also adding a Visual Studio project), if it is of some interest...

munificent commented 9 years ago

Thanks, @sbrl!

That looks fairly close to what the Makefile should be doing on Windows. Have you tried running that? I think mingw includes a version of make?

I'll close this out because there isn't an action to take here, but I appreciate you hacking on this!

sbrl commented 9 years ago

I didn't even realise that mingw came with a version of make - Thanks!

Unfortunately though, I can't get it to work. It keeps looking for a file named "prep":

  Considering target file 'prep'.
   File 'prep' does not exist.
   Finished prerequisites of target file 'prep'.
  Must remake target 'prep'.

And it tries to create a few directories that I have already created:

Creating temporary batch file C:\Users\<username>\AppData\Local\Temp\make6816-1.bat
Batch file contents:
        @echo off
        mkdir -p build/debug build/release build/release-cpp
CreateProcess(C:\Users\<username>\AppData\Local\Temp\make6816-1.bat,C:\Users\<username>\AppData\Local\Temp\make6816-1.bat,...)
Putting child 00608F70 (prep) PID 6365160 on the chain.
Live child 00608F70 (prep) PID 6365160
Main thread handle = 0000005C
The syntax of the command is incorrect.

The command I was running was "C:\Program Files (x86)\mingw-builds\x32-4.8.1-win32-dwarf-rev5\mingw32\bin\mingw32-make.exe" -d (the -d outputs debug info I think).

kmarekspartz commented 9 years ago

A fix for the prep issue was merged recently in munificent/wren#121. Can you pull and try again?

Not sure about the other one. Does mingw use Windows-style flags rather than Posix-style? If so you might have to change the -p to a /p.

sbrl commented 9 years ago

I have run git pull to get the latest changes.

mingw-make uses the posix style flags. Here is a pastebin of the help text you get with the --help flag: http://pastebin.com/kH7tXEyn

What is the correct command to get mingw-make to build the project? Sorry, I haven't a clue :D

(Note: I do have visual studio 2013 installed, but I wouldn't kow how to use it to compile it!)

If I cd to the root of the clone I have made and just call mingw-make, I get the following error:

process_begin: CreateProcess(NULL, cc -dumpmachine, ...) failed.
mingw32-make: Makefile:10: pipe: No error
The syntax of the command is incorrect.
Makefile:44: recipe for target 'prep' failed
mingw32-make: *** [prep] Error 1
kmarekspartz commented 9 years ago

Oh, I meant the parameter in mkdir -p.

I don't have a mingw system, so going back and forth like this is the best I can do.

On Wednesday, January 21, 2015, Starbeamrainbowlabs < notifications@github.com> wrote:

I have run git pull to get the latest changes.

mingw-make uses the posix style flags. Here is a pastebin of the help text you get with the --help flag: http://pastebin.com/kH7tXEyn

What is the correct command to get mingw-make to build the project? Sorry, I haven't a clue :D

If I cd to the root of the clone I have made and just call mingw-make, I get the following error:

process_begin: CreateProcess(NULL, cc -dumpmachine, ...) failed. mingw32-make: Makefile:10: pipe: No error The syntax of the command is incorrect. Makefile:44: recipe for target 'prep' failed mingw32-make: *\ [prep] Error 1

— Reply to this email directly or view it on GitHub https://github.com/munificent/wren/issues/125#issuecomment-70840591.

sbrl commented 9 years ago

Oh I see what you mean now.

mkdir in windows takes windows style flags. From it's help it says "MKDIR creates any intermediate directories in the path, if needed". So I don't think that the -p is needed on windows.

The other issue is that mkdir on windows can't create multiple directories at once. Since I don't have any experience with make, I don't know how to tweak the makefile to fix this.

kmarekspartz commented 9 years ago

You can split the command to multiple lines. There needs to be a tab at the beginning of each subsequent line:

mkdir a mkdir b To get rid of the -p, you could either manually do each mkdir in the parent chain or hoist it into a variable that gets set to the empty string on Windows so as not to break compatibility with Posix mkdir. The first is probably easier. On Wednesday, January 21, 2015, Starbeamrainbowlabs < notifications@github.com> wrote: > Oh I see what you mean now. > > mkdir in windows takes windows style flags. From it's help it says "MKDIR > creates any intermediate directories in the path, if needed". So I don't > think that the -p is needed on windows. > > The other issues is the mkdir on windows can't create multiple > directories at once. Since I don't have any experience with make, I don't > know how to tweak the makefile to fix this. > > — > Reply to this email directly or view it on GitHub > https://github.com/munificent/wren/issues/125#issuecomment-70845498.
sbrl commented 9 years ago

I think I see how the makefile works now. It has a number of things it can do, like prep, release, and so on.

I got the prep part to work by changing the makefile. I am not confident enough to create a variable yet :)

The prep but now looks like this:

prep:
    @mkdir build\debug
    mkdir build\release
    mkdir build\release-cpp

I had to change the forward slashes to backward slashes because mkdir didn't like forward slashes for some reason.

What does the $(CC) mean? THe next error I got was this:

       Finished prerequisites of target file 'build/release/main.o'.
      Must remake target 'build/release/main.o'.
cc -c -std=c99 -Wall -Werror -fPIC -Os -Iinclude -o build/release/main.o src/main.c
CreateProcess(NULL,cc -c -std=c99 -Wall -Werror -fPIC -Os -Iinclude -o build/release/main.o src/main.c,...)
process_begin: CreateProcess(NULL, cc -c -std=c99 -Wall -Werror -fPIC -Os -Iinclude -o build/release/main.o src/main.c, ...) failed.
Putting child 021984B8 (build/release/main.o) PID 35291824 on the chain.
Live child 021984B8 (build/release/main.o) PID 35291824
make (e=2): The system cannot find the file specified.
Reaping losing child 021984B8 PID 35291824
Makefile:76: recipe for target 'build/release/main.o' failed
mingw32-make: *** [build/release/main.o] Error 2
Removing child 021984B8 PID 35291824 from chain.

(Full output: http://pastebin.com/9BMg9LTL)

I think the problem is that it is trying to call a command called cc, but the compiler is actually called gcc.

munificent commented 9 years ago

It sounds like you're running the default Windows mkdir and not the one in MSYS that comes with MinGW. See this answer on SO. Can you try that and let me know if it helps?

What does the $(CC) mean?

It means "look up the variable 'CC' and put its value here". Since the C compiler's executable name varies from machine to machine (it might be gcc or clang or tinycc or who knows what else) the convention is to refer to it using a variable named "CC". Make itself will then implicitly define it for you with the name of the default C compiler on the machine.

Here, it's expanding it to "cc" which is the default name. It's not finding that, likely for the same reason it's using the wrong mkdir. Once MSYS is on your PATH, I think it will find cc in there too.

sbrl commented 9 years ago

Since I installed MinGW a while ago, I completed uninstalled it and downloaded the new installer. I made sure to check the msys box this time. It comes with so many helpful tools! These will be helpful when doing other things too.

This time I am also installing it to the default directory.

Now that I have done all that, I typed mingw32-make after cding to the repository. It output a bunch of stuff (full output here: http://pastebin.com/4egQZhm2). It created the directories in build/ correctly, and it created wren.exe in the root of the repository.

When I tried to run this version of wren though, it crashed. That version of wren can be found here: http://s000.tinyupload.com/download.php?file_id=48039727544545612497&t=4803972754454561249791848

The one I compiled earlier was 164KB, and the new one is only 146KB. Could something be missing?

munificent commented 9 years ago

Now that I have done all that, I typed mingw32-make after cding to the repository. It output a bunch of stuff (full output here: http://pastebin.com/4egQZhm2).

Yup, that output is exactly right!

When I tried to run this version of wren though, it crashed.

:cry:

Can you try running make debug and then running wrend.exe? That does a debug build which may hopefully give you more information about where it's going bad.

sbrl commented 9 years ago

Ran make debug and it works fine.... (output: http://pastebin.com/U6n1TxBC)

The size of the resulting executable is 262KB. It can be found here: http://s000.tinyupload.com/download.php?file_id=87285999477609478063&t=8728599947760947806394889

I retried the building of the normal one just to make sure, and yes, it still crashes.

kmarekspartz commented 9 years ago

Can you try changing this line: https://github.com/munificent/wren/blob/master/Makefile#L7 to -O0 instead of -Os?

sbrl commented 9 years ago

Yep, that fixes it. (make output: http://hastebin.com/fawojuquxe.avrasm)

That gives a 172KB executable that works. Download link: http://s000.tinyupload.com/download.php?file_id=06328225875972386030&t=0632822587597238603012098

kmarekspartz commented 9 years ago

Can you try -01? I'm trying to narrow down which optimization is breaking it.

edit: Oops, I meant O1, but you figured that out, thanks.

kmarekspartz commented 9 years ago

For reference, mingw-gcc should just have be an older/forked version, I think: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html

sbrl commented 9 years ago

I don't understand the second of your two posts.

kmarekspartz commented 9 years ago

The C compiler chooses various optimizations to perform according to the optimization level. I had to look up exactly what -Os entailed, so I put it there. Additionally, I believe mingw-gcc is a fork of an older version of gcc, so the optimizations listed in that reference may not be exactly what mingw-gcc is doing.

munificent commented 9 years ago

You're probably running into #128, which I just fixed. Can you pull down latest and see if it's better?

sbrl commented 9 years ago

Yep, pulling down the latest source code fixed the issue. The result is 146KB. make output: http://hastebin.com/uxiseqiqot.tex

Thank you very much - I have learnt so much about compiling things since starting this issue :)

munificent commented 9 years ago

\o/