Copy a file using a makefile at runtime

浪子不回头ぞ 提交于 2019-12-22 08:07:33

问题


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) *~

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/11750983/copy-a-file-using-a-makefile-at-runtime

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!