没有规则将目标设置为"openmp"吗? [英] No rule to make target 'openmp'?
问题描述
在makefile中定义了以下内容:
CXX = g++
CXXFLAGS = -std=c++11
我想用OpenMP指令编译我的代码,而不更改原始的makefile(运行良好).该手册提出了一种方法,可以通过在命令行上进行更改来实现.但是,当我跑步时,
make CXXFLAGS=-std=c++11 -fopenmp
弹出前面提到的错误.有人可以帮助我了解我在做什么错吗?
这里的问题是-std=c++11
和-fopenmp
之间的空格.它将这两个参数拆分开,并且-fopenmp
被解释为选项-f
,然后openmp
被解释为makefile
,由于在当前目录中找不到它,所以make
试图对其进行构建. /p>
您需要使用引号("
)之类的
make
$ make CXXFLAGS="-std=c++11 -fopenmp"
这会将CXXFLAGS= -std=c++11 -fopenmp
传递给make
.我们可以通过以下简单的makefile
看到这种行为.
CXX = g++
CXXFLAGS = -std=c++11
all:
@echo $(CXXFLAGS)
运行make
将产生输出
$ make
-std=c++11
运行make CXXFLAGS="-std=c++11 -fopenmp"
将产生
$ make
-std=c++11 -fopenmp
正确的输出以及我们希望实现的目标.
顺便说一句,在您的问题中,命令make CXXFLAGS= -std=c++11 -fopenmp
所产生的错误不只是
make: openmp: No such file or directory
make: *** No rule to make target 'openmp'. Stop.
因为CXXFLAGS=
和-std=c++11
之间有空格.我知道了
$ make CXXFLAGS= -std=c++11 -fopenmp
make: invalid option -- =
make: invalid option -- c
make: invalid option -- +
make: invalid option -- +
make: invalid option -- 1
make: invalid option -- 1
例如,如果要使用-std=c++14
而不是-std=c++11
进行编译,则需要使用
$ make CXXFLAGS=-std=c++14
注释:没有空格,或等效地
$ make CXXFLAGS="-std=c++14"
再次没有空格.
The following is defined in the makefile:
CXX = g++
CXXFLAGS = -std=c++11
I would like to compile my code with OpenMP directives without changing the original makefile (which runs perfectly). The manual suggests a way to do this, is by changing it on the command line. However, when I run,
make CXXFLAGS=-std=c++11 -fopenmp
the error mentioned before pops up. Can someone help me understand what I'm doing wrong?
The problem here is the space between -std=c++11
and -fopenmp
. It splits these two arguments up and the -fopenmp
is interpreted as the option -f
then openmp
is interpreted as a makefile
that make
attempts to build because it can't find it in the current directory.
You need to execute make
with quotes ("
) like
$ make CXXFLAGS="-std=c++11 -fopenmp"
this will pass CXXFLAGS= -std=c++11 -fopenmp
to make
. We can see this behaviour with the following simple makefile
.
CXX = g++
CXXFLAGS = -std=c++11
all:
@echo $(CXXFLAGS)
Running make
will produce the output
$ make
-std=c++11
Running make CXXFLAGS="-std=c++11 -fopenmp"
will produce
$ make
-std=c++11 -fopenmp
the correct output and what we were hoping to achieve.
As an aside the command, make CXXFLAGS= -std=c++11 -fopenmp
, in your question should produce more errors than just
make: openmp: No such file or directory
make: *** No rule to make target 'openmp'. Stop.
because of the space between CXXFLAGS=
and -std=c++11
. I get
$ make CXXFLAGS= -std=c++11 -fopenmp
make: invalid option -- =
make: invalid option -- c
make: invalid option -- +
make: invalid option -- +
make: invalid option -- 1
make: invalid option -- 1
If for instance you want to compile with -std=c++14
instead of -std=c++11
you would need to execute make
with
$ make CXXFLAGS=-std=c++14
note: no space, or equivalently with
$ make CXXFLAGS="-std=c++14"
again without a space.
这篇关于没有规则将目标设置为"openmp"吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!