I'm reading a tutorial (http://computer.howstuffworks.com/c.htm/)
and I came to the following instructions
gcc -c -g util.c
gcc -c -g main.c
gcc -o main main.o util.o
Since I have gcc.exe in C:\Dev-Cpp\bin while I have util.c, main.c in C:\Dev-Cpp\bin\htw the above didn't work until I changed it to
gcc -c -g htw\util.c -o htw\util.o
gcc -c -g htw\main.c -o htw\main.o
gcc -o htw\main.exe htw\main.o util.o
Then it went OK and produced util.o, main.o and main.exe in the htw directory.
Now the next instruction was to create the corresponding makefile file. The instructions are as follows:
"Makefiles
It can be cumbersome to type all of the gcc lines over and over again, especially if you are making a lot of changes to the code and it has several libraries. The make facility solves this problem. You can use the following makefile to replace the compilation sequence above:
into a file which I called Makefile.win which I saved into the htw folder.
Then I tried to execute it with make.exe (which is inside bin)
C:\Dev-Cpp\bin>make Makefile.win
But got the following message
make: *** No rule to make target 'Makefile.win'. Stop
Can anyone tell me what I'm doing wrong and how I should proceed instead.
I know you can use Dev-C project to make this things for you but I'm also trying to learn gcc which Dev-C uses so that I can get better feeling for what's happening.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
make automatically uses a file called "Makefile" in the current directory as its input file. Any command line arguments you pass are interpreted as target names (if they're not valid command line options). So, the command "make Makefile.win" instructs make to look for a target named "Makefile.win" in the file "Makefile" in the current directory. This isn't what you want.
In order for make to use a different input file, you need to specify it with the -f option.
So, your command becomes:
make -f Makefile.win
Paul
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
since dev-cpp comes with mingw/gcc and there are loads of experienced programmers in here, imo the chances are good that someone might know the reason why this didn't work for me.
Thanks for your suggestion, but I'm not going to search for a mailing list to get an idea why it doesn't work. I'm going to take into account that it might be a MSYS related problem as you denoted though.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
(Note the forward slash as the directory separator, instead of backslash in "htw\Makefile.win ").
Make is a unix thing, it doesn't understand "\".
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You are right that in some cases you must use forward slash / (for instance when defining macros in makefile) while in other cases it suffices with backslah . But it's seems hard to tell when to use / and when to use .
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hey,
util.o is not generated, because any target which is not a prerequisite of the first target (maybe there is a way to change this "first target" restriction, consult the make tutorial) is not, unless you call make explicitly with the target name. If you add the target for main.exe (or simply main) at the top of your makefile, you'll see that everything works.
NB
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you very much all for the help. Now it works. Here is a summary
Suppose you have yor source files util.c, util.h and main.c in a directory C:\mycode\htw. In the same directory create the file Makefile.win (the name doesn't matter) containing
Makefile.win
Observe that you must use slash instead of backslash in the macro on the next line
No, the only thing I wanted to do is to make it work when I had make.exe and gcc.exe in one directory while having source files and Makefile.win in another directory. I could as well navigated to the directory where make.exe was located but then I would have to put pathname in front of every source file and object file and that would be much more paths then putting the paths in front of make.exe and gcc.exe. In the first case I think that it ould be 15 pathnames, but in the second only 4.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm reading a tutorial (http://computer.howstuffworks.com/c.htm/)
and I came to the following instructions
gcc -c -g util.c
gcc -c -g main.c
gcc -o main main.o util.o
Since I have gcc.exe in C:\Dev-Cpp\bin while I have util.c, main.c in C:\Dev-Cpp\bin\htw the above didn't work until I changed it to
gcc -c -g htw\util.c -o htw\util.o
gcc -c -g htw\main.c -o htw\main.o
gcc -o htw\main.exe htw\main.o util.o
Then it went OK and produced util.o, main.o and main.exe in the htw directory.
Now the next instruction was to create the corresponding makefile file. The instructions are as follows:
"Makefiles
It can be cumbersome to type all of the gcc lines over and over again, especially if you are making a lot of changes to the code and it has several libraries. The make facility solves this problem. You can use the following makefile to replace the compilation sequence above:
main: main.o util.o
gcc -o main main.o util.o
main.o: main.c util.h
gcc -c -g main.c
util.o: util.c util.h
gcc -c -g util.c
Enter this into a file named makefile, and type make to build the executable. Note that you must precede all gcc lines with a tab. "
So, I entered the text
main: main.o util.o
gcc -o main main.o util.o
main.o: main.c util.h
gcc -c -g main.c
util.o: util.c util.h
gcc -c -g util.c
into a file which I called Makefile.win which I saved into the htw folder.
Then I tried to execute it with make.exe (which is inside bin)
C:\Dev-Cpp\bin>make Makefile.win
But got the following message
make: *** No rule to make target 'Makefile.win'. Stop
Can anyone tell me what I'm doing wrong and how I should proceed instead.
I know you can use Dev-C project to make this things for you but I'm also trying to learn gcc which Dev-C uses so that I can get better feeling for what's happening.
make automatically uses a file called "Makefile" in the current directory as its input file. Any command line arguments you pass are interpreted as target names (if they're not valid command line options). So, the command "make Makefile.win" instructs make to look for a target named "Makefile.win" in the file "Makefile" in the current directory. This isn't what you want.
In order for make to use a different input file, you need to specify it with the -f option.
So, your command becomes:
make -f Makefile.win
Paul
strange, I tried that with msys and a devcpp created makefile but I get the following error:
unknown@OEMI /c/cpp_projects/tabcontrol
$ make -f Makefile.win
C:\C-COMPILE\1.0\BIN\make.exe: *** No targets specified and no makefile found. Stop.
if I remove the .win ending it works well...
bump
Note that since this really is not an MSYS forum, you might do better posting to their mailing list.
Wayne
annoyed of my question Wayne? :o(
since dev-cpp comes with mingw/gcc and there are loads of experienced programmers in here, imo the chances are good that someone might know the reason why this didn't work for me.
Thanks for your suggestion, but I'm not going to search for a mailing list to get an idea why it doesn't work. I'm going to take into account that it might be a MSYS related problem as you denoted though.
Thanks Paul,
When I have util.h, util.c, main.c and Makefile.win in the folder C:\Dev-Cpp\bin (the same fglder as make.exe) the command
make -f Makefile.win
works beautifully!
However if I move the files util.h, util.c, main.c and Makefile.win in the folder C:\Dev-Cpp\bin\htw and try
make -f htw\Makefile.win
then I get the error message
main: *** No rule to make target 'main.c' needed by 'main.o'. Stop
Surely there must be a way to execute a Makefile even if it's not in the same folder as make.exe???
Instead of
make -f htw\Makefile.win
try
make -f htw/Makefile.win
(Note the forward slash as the directory separator, instead of backslash in "htw\Makefile.win ").
Make is a unix thing, it doesn't understand "\".
No / insted of \ is not the problem
in the folder htw I have util.h, util.c, main.c and Makefile.win
The file Makefile I tried now was
htw\util.o: htw\util.c htw\util.h
gcc -c -g htw\util.c -o htw\util.o
htw\main.o: htw\main.c htw\util.h
gcc -c -g htw\main.c -o htw\main.o
The strange thing is that util.o is generated in htw just as I want to, but main.o is not generated??
If I instead write
htw\main.o: htw\main.c htw\util.h
gcc -c -g htw\main.c -o htw\main.o
htw\util.o: htw\util.c htw\util.h
gcc -c -g htw\util.c -o htw\util.o
then main.o is generated but not util.o
So it seems that the first command is executed but not the second. Any help appreciated.
http://www.gnu.org/software/make/manual/html_node/make_31.html#SEC35
You are right that in some cases you must use forward slash / (for instance when defining macros in makefile) while in other cases it suffices with backslah . But it's seems hard to tell when to use / and when to use .
Hey,
util.o is not generated, because any target which is not a prerequisite of the first target (maybe there is a way to change this "first target" restriction, consult the make tutorial) is not, unless you call make explicitly with the target name. If you add the target for main.exe (or simply main) at the top of your makefile, you'll see that everything works.
NB
Thank you very much all for the help. Now it works. Here is a summary
Makefile.win
Observe that you must use slash instead of backslash in the macro on the next line
BP = C:/Dev-Cpp/bin/
main: main.o util.o
$(BP)gcc -o main main.o util.o
util.o: util.c util.h
$(BP)gcc -c -g util.c -o util.o
main.o: main.c util.h
$(BP)gcc -c -g main.c -o main.o
cd C:\mycode\htw
3.Enter the following command
C:/Dev-Cpp/bin/make -f Makefile.win
Frank
All is well, but weren't you trying to manage to make things work without navigating to the directory holding Makefile.win?
No, the only thing I wanted to do is to make it work when I had make.exe and gcc.exe in one directory while having source files and Makefile.win in another directory. I could as well navigated to the directory where make.exe was located but then I would have to put pathname in front of every source file and object file and that would be much more paths then putting the paths in front of make.exe and gcc.exe. In the first case I think that it ould be 15 pathnames, but in the second only 4.
Anyways, glad to see that you solved your problem :)
you may have to specify an 'all' target.