没有规则将目标设置为"openmp"吗? [英] No rule to make target 'openmp'?

查看:137
本文介绍了没有规则将目标设置为"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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆