0

I am working on an assignment for class, and we are to work off of a class server where the code files are held.

I have copied the files to my home directory, and have been editing with vim (since my instructor for some reason prefers it to emacs).

But how do I actually test my code? the make file is provided, and when I type make test.c, I get back make: Nothing to be done for test.c. I don't understand why this is happening, because I have a print statement as the first line in main. Shouldn't that at least run? Also, how do I pass arguments to the main function test.c while using make??

As a side question, this server doesn't have gdb either, for some reason. I'm sure there is an alternative installed, I just don't know what it would be called to try and see if it's here.

nobody
  • 19,814
  • 17
  • 56
  • 77
pretzlstyle
  • 2,774
  • 5
  • 23
  • 40
  • Have you actually read the makefile yet? Do you understand how to invoke executables? – Ignacio Vazquez-Abrams Jan 14 '16 at 02:12
  • Do you know what "compilation" means? – Arc676 Jan 14 '16 at 02:13
  • 1
    `make` *probably* just compiles your program – rather than both compiling and running it – and you’re not using it properly, either. Look inside the `Makefile` for a list of targets (they’re at the start of their respective lines in the form `target-name:`). `make test` might be correct. Then you can run your program and pass arguments as usual, e.g. `./test some args`. – Ry- Jan 14 '16 at 02:14
  • @IgnacioVazquez-Abrams No, I don't even know what a make file is. This is my first assignment in the class and it has been extremely vague. I have a lot of experience with Python, Java, and MATLAB, but I use IDE's for all of those and don't have low-level language experience. – pretzlstyle Jan 14 '16 at 02:19
  • @RyanO'Hara I see. in my case, `make` does compile and run it. My instructor specifically told us to use the `make` file to make sure our code works. I did as you suggested and just dropped the `.c` and it works (`make test`) – pretzlstyle Jan 14 '16 at 02:20
  • First thing: you have to learn how to use make (`man make` is a good start). You can get a list of the directives contained in your makefile (one word) by pressing TAB after `make ` (make followed by space). I **guess** that `make` without arguments will compile you prog and something like `make test` will run some tests. But everything depends on your Makefile. P.S. Are you really looking for `gdb` ? It is a debugger and is normally considered much more complex than `make`... – mauro Jan 14 '16 at 02:34
  • @mauro thanks for the info, I will use the `man` command. And yes, I did mean `gdb`. The assignment is to modify some existing code and a debugger would be very helpful. I have used `gdb` before. – pretzlstyle Jan 14 '16 at 02:47

4 Answers4

2

The argument to make is usually the thing you want it to create. Since test.c already exists, make test.c doesn't do anything. make test should compile test.c to create test. make with no arguments uses a default target specified in the Makefile; in your case it's probably the same as make test.

The make command doesn't run your program; it creates an executable that you can then run.

Once you've typed make or make test, you should be able to execute your program by typing

./test

The ./ is important; without it, you'll probably invoke the shell's built-in test command, which is not what you want.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
1

Maybe what u need is only this build command:

gcc test.c -o test

Then:

./test

Have a try. ^_^

Justlike
  • 1,476
  • 10
  • 18
0

I think you need some basic knowledge in make. You should read some basic books on makefile and actually try it out. If you just try to stick concepts to your mind, but never actually try it out, you will never get it.

Check out this question. It asks for good tutorials on GNU Make. Also, so that you can go directly to the links, this and this are links mentioned in the main answers.

Community
  • 1
  • 1
Box Box Box Box
  • 5,094
  • 10
  • 49
  • 67
0

Simply save your code and then open the command prompt and write these command

  1. gcc .\fileName.c and press Enter
  2. Simply press a + tab and then print Enter and there you go.
Shishir Jha
  • 1
  • 1
  • 3