6

I used to compile my programs with batch scripts on windows but I recently discovered makefiles which are much more efficient.

I had this line in my .bat file that copied some dlls to the current directory at runtime and it worked perfectly.

copy C:\lib\glfw\glfw.dll 

I tried the same line in my makefile and even tried the alternative cp but my terminal prints this error even tho the file is IN the location I specified

process_begin: CreateProcess(NULL, copy C:\lib\glfw\glfw.dll, ...) failed
make (e=2): The system cannot find the file specified.
make: *** [core.exe] Error 2

Here is the full makefile that I am using. Mind you, absent the copy line it works like a charm.. what am I doing wrong or is this possible?

EXEC = core.exe
OBJS = src/obp.o

CC = g++

CFLAGS  = -W -Wall
LIBS    = -lSOIL -lglew32 -lglfw -lopengl32
LDFLAGS =

$(EXEC): $(OBJS)
    $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
    copy C:\lib\glfw\glfw.dll

clean:
    rm -f $(EXEC) $(OBJS) *~
iKlsR
  • 2,642
  • 6
  • 27
  • 45
  • Is it maybe the `copy` that can not be found? How come you are using `rm`, can it find that? Are you running this in an `MSYS` environment? – Reinier Torenbeek Aug 01 '12 at 02:26

2 Answers2

5

It looks like you are running this from an MSYS (or MinGW) environment, which does not know about copy. Instead, you can use

cp C:\lib\glfw\glfw.dll .

If you want to avoid the *nix like cp, then you could use xcopy as follows:

xcopy //Y C:\lib\glfw\glfw.dll

Note the double // which is required to escape the /.

Or you could run this in a regular MS-DOS environment, in which case your clean target will not work because rm will not be found and you should use del.

With your current setup, any built-in DOS command will not be found. See Choosing the shell to read about how make determines which shell to use.

Reinier Torenbeek
  • 16,669
  • 7
  • 46
  • 69
  • i was running it in an dos environ from start and cp doesn't work either. – iKlsR Aug 01 '12 at 03:41
  • I can think of nothing but doing some debugging steps. Do you know where it gets `rm` from? Could you do `where rm` in your command prompt? (This only makes sense if you have a somewhat newer Windows version that supports `where`). Also, what are your values of `$(SHELL)` and `$(MAKESHELL)`? You can print them from your `makefile` using something like `$(info SHELL = $(SHELL))` at the top. – Reinier Torenbeek Aug 01 '12 at 19:23
  • dunno if this helps but $(info SHELL...) returns SHELL = C:/MinGW/msys/1.0/bin//sh.exe and where rm prints C:\MinGW\msys\1.0\bin\rm.exe – iKlsR Aug 02 '12 at 08:26
  • Yes, this does help. So you are running an `MSYS` shell, without realizing it. You can see that from the paths you just printed. This means that my original answer *should* work. What error do you get when using `cp`? Did you not forget to add the period to the end of the `cp` command? – Reinier Torenbeek Aug 02 '12 at 11:03
  • X_x.. i forgot the `.` :D.. it works. thanks.. what does it do btw? – iKlsR Aug 02 '12 at 11:27
  • `cp` is the *nix variant of `copy` and it is used as `cp `. The destination is mandatory, and the `.` indicates the current directory is the destination. I updated the answer to give you some more information. – Reinier Torenbeek Aug 02 '12 at 11:59
0

You may need to double the backslashes in order for make to understand what you want:

copy c:\\lib\\glfw\\glfw.dll

Make comes from a Unix background where the file separator is /, so it's sometimes a bit awkward to use it in a Windows environment.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285