-4

I found a program on github I'm trying to compile and run but can't seem to figure out how and was hoping someone could walk me through the steps on it. Is it something I would have to use the command line for?

The program is located here Compiler. It's a c-minus compiler aimed at the Tiny Machine Virtual Machine I'm trying to have some fun with. The instructions on how to compile and use are a bit foggy to me.

I am extremely new to this type of thing, so step by step, dumbed down instructions would be most appreciated!

Bob
  • 1,344
  • 3
  • 29
  • 63

2 Answers2

3

If you use a linux system or MacOS, the steps are rather easy:

  • Clone the project with git clone https://github.com/koyabr/C-Compiler.git
  • cd C-Compiler
  • remove files main and tm. These should not be under source control
  • patch the files AST.h and AST.c, change the words ID to id.
  • run make

The patch is required because flex generates preprocessor macros that conflict with function argument names in AST.c and AST.h

This toy language is the basis of computer courses in various universities, other sources can be found:

chqrlie
  • 131,814
  • 10
  • 121
  • 189
  • what do I do with `main` and `tm`? aren't those needed to make it work? – Bob Mar 15 '16 at 21:56
  • `main` and `tm` are executables. Unless you run the same platform as the author, they will not run on your system. You should build your own version from the sources by running the `make` command. What system do you use? – chqrlie Mar 15 '16 at 21:58
  • Use the last link, https://github.com/codedhead/cminus in visual studio 2010 (there will be problems in 2015). I just confirm it builds with one click. – zeromus Mar 15 '16 at 22:01
  • 64-bit windows, ohh I think I understand. Get rid of the executables but keep the main.c and tm.c? – Bob Mar 15 '16 at 22:01
  • In case you can't read, everything he wrote was predicated on linux or osx, which you're not, I assume, since your question is tagged visual studio. Removing `main` and `tm` is not even a very big deal, pointless for you to be stuck on, not solving any of your real problems, and actually completely irrelevant for you on windows. – zeromus Mar 15 '16 at 22:02
  • Of course keep the source code! The executables should not be stored on github, it is a mistake by koyabr, but no bad consequences. – chqrlie Mar 15 '16 at 22:03
  • Also all these compilers are homework projects, so if they're buggy, youll know why. People who commit executables on accident dont make trustworthy code. – zeromus Mar 15 '16 at 22:03
  • @zeromus: I understand. Trying to work on this on a Windows PC is going to be a bit complicated, definitely install `cygwin` and a decent programmers editor, getting this project to run with Visual Studio is non trivial. – chqrlie Mar 15 '16 at 22:05
1

https://github.com/zeromus/C-Compiler


The instructions are foggy because it's the easiest possible software to build, not requiring any instructions nor even any work--except on windows. Building some kinds of software is extremely difficult in visual studio. You need to search for general advice on how to build unix software in windows, and give up the dream of using visual studio.

But since I build unix software in windows for relaxation, here's how I did it.

run the x86 installer from here https://www.cygwin.com/ search for and include:

gcc-g++   flex   bison  make   (all in the devel category)

run the installed cygwin.bat; run these commands

cd c:/path/to/c-compiler
make

congratulations, you now have parse.c, parse.h, and scan.c. Moreover you have main.exe--if all you want to do is run the program, you're done.

The final step is to STOP! Don't try to use visual studio.

If you insist on hacking on it in visual studio 2015, then you're in big trouble. This requires high level skills. You're essentially asking how to tow a boat with a motorcycle. It requires rebuilding your motorcycle into a truck. I'll write down the steps so you can see how much trouble you're in.

Make a new win32 console application, check Empty project, uncheck SDL checks, drag in all the .c and .h files.

Now, rightclick the project in solution explorer, do properties, change configuration to go to debug, go to c/c++, preprocessor, and add

_CRT_SECURE_NO_WARNINGS;_CRT_INSECURE_NO_DEPRECATE 

to Preprocessor Definitions.

Now, rightclick the project in solution explorer, do properties, change configuration to go to debug, go to c/c++, general,and add . (just a dot) to additional include directories

go here Is there a replacement for unistd.h for Windows (Visual C)? and get the contents of unistd.h. Create it next to the vcxproj visual studio's created.

go here http://www.codeproject.com/Articles/157001/Full-getopt-Port-for-Unicode-and-Multibyte-Microso to get getopt sources. Yes, you have to login. Codeproject is a pile of suck.

Dearchive it alongside your vcxproj. Drag the .h and .c into your project. Remove tm.c from your project.

Now use visual studio to build it.

congratulations, you now have the compiler.

REPEAT IT ALL AGAIN WITH OTHER DIRECTORIES; but remove main.c at the end.

congratulations, you now have the machine.

There's better ways to do all this, but they're even more complicated.

Community
  • 1
  • 1
zeromus
  • 1,648
  • 13
  • 14
  • I've been using cygwin for another class, I tried it and this is what i got `User@User-HP /cygdrive/c/Users/User/Desktop/C-Compiler-master/C-Compiler-master $ make -bash: make: command not found ` – Bob Mar 15 '16 at 21:29
  • Sorry, I left `make` out of the deps list. In general if youre in cygwin and it says X: command not found, you might consider looking for X in the cygwin installer....... – zeromus Mar 15 '16 at 21:57
  • Do i select for `src` as well as `bin`? – Bob Mar 15 '16 at 22:08
  • Okay I've gotten make to work, it created the `main.exe` but am getting a error saying it can't start because `cygwin1.dll` is missing from my computer? – Bob Mar 15 '16 at 22:14
  • run it from cygwin, dont doubleclick it from explorer. that's the price you pay for using cygwin. I just added a github fork that has this set to build in vs2015 – zeromus Mar 15 '16 at 22:19
  • Were you able to run it in vs2015? I keep receiving errors – Bob Mar 15 '16 at 22:33
  • I wrote about 10KB of text about how to fix errors. I doubt you've followed those steps yet. Yes, I was able to run it in vs2015, since I made the fork. Since I made the fork, I'm not paying attention to this anymore. – zeromus Mar 15 '16 at 22:36
  • I'm sorry man, I'm just really new to all of this and I'm trying to learn. I tried to run the fork but am getting errors on `strdup` and cannot include file `unistd.h` – Bob Mar 15 '16 at 22:44
  • I keep getting `1>scan.c(537): fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory` even though I added unistd.h to the project – Bob Mar 15 '16 at 23:16
  • *then take the issues to the github fork* – zeromus Mar 15 '16 at 23:29