简体   繁体   English

Makefile中未找到命令错误

[英]Command not found error in Makefile

I am trying to write a Makefile. 我正在尝试编写一个Makefile。 This is what I have written. 这就是我写的。

CC='/buildtools/toolchain/wr-x86/3.0FCScg/bin/i586-wrs-linux-gnu-gcc --sysroot=/buildtools/toolchain/wr-x86/3.0FCScg/sysroot'
IDIR =../../../include
CFLAGS=-I$(IDIR)

LDIR =../../../../../../../../.debug/lib.out/public/
LIBS= -lmylib1 -lmylib2 -lmylib3

myexec: my_code.c
    $(CC) $(CFLAGS) -o myexec my_code.c

This when run throws an error 运行时抛出错误

make: /buildtools/toolchain/wr-x86/3.0FCScg/bin/i586-wrs-linux-gnu-gcc --sysroot=/buildtools/toolchain/wr-x86/3.0FCScg/sysroot: Command not found

However, it works when I run the compile command manually in terminal. 但是,当我在终端中手动运行编译命令时,它可以工作。

export CC='/buildtools/toolchain/wr-x86/3.0FCScg/bin/i586-wrs-linux-gnu-gcc --sysroot=/buildtools/toolchain/wr-x86/3.0FCScg/sysroot'
$CC -I ../../../include -L ../../../../../../../../.debug/lib.out/public/ -lmylib1 -lmylib2 -lmylib3 -o myexec my_code.c

Change the definition in the Makefile to this: Makefile的定义更改为:

CC=/buildtools/toolchain/wr-x86/3.0FCScg/bin/i586-wrs-linux-gnu-gcc --sysroot=/buildtools/toolchain/wr-x86/3.0FCScg/sysroot

With the quotes, make uses the whole definition as the name of the executable to look for. 使用引号, make使用整个定义作为要查找的可执行文件的名称。

The reason it works when you define CC outside the Makefile is the rules for handling quotes are different for the shell and the Makefile. Makefile外部定义CC时它起作用的原因是处理引号的规则对于shell和Makefile是不同的。

A more common convention is to use CFLAGS for all compilation flags. 更常见的约定是将CFLAGS用于所有编译标志。 As a matter of facts, I strongly suggest you add Wall -W to your CFLAGS definition. 事实上,我强烈建议您在您的CFLAGS定义中添加Wall -W

Regarding the libraries, you should expand $LIBS after the source and object files on the cc or ld command line. 关于库,您应该在ccld命令行上的源文件和目标文件之后展开$LIBS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM