简体   繁体   English

使用OpenMP的Makefile:无法将-o与-c,-S或-E指定给多个文件

[英]Makefile with OpenMP: cannot specify -o with -c, -S or -E with multiple files

I have a problem including parallel calculation with OpenMP in my makefile. 我的问题包括在makefile中使用OpenMP进行并行计算。 The error I got is 我得到的错误是

cannot specify -o with -c, -S or -E with multiple files 不能将-o与-c,-S或-E指定给多个文件

Here is my makefile: 这是我的makefile:

GSLFLAGS := pkg-config --cflags gsl
LIBGSL := pkg-config --libs gsl

CFLAGS = -c -C -O3 -openmp=parallel

lateral.o:lateral.cxx

    g++ -c lateral.cxx 

main.o:main.cxx 

    g++ -c main.cxx  $< ${GSLFLAGS} ${CFLAGS}

alg:main.o lateral.o

    g++ -o  $@ $^ ${LIBGSL}

The line 线

g++ -c main.cxx $< ${GSLFLAGS} ${CFLAGS}

Should read 应该读

g++ -c main.cxx ${GSLFLAGS} ${CFLAGS}

because, $< expands to the first prerequisite, main.cxx , giving g++ -c main.cxx main.cxx . 因为$<扩展到第一个前提条件main.cxx ,从而给出g++ -c main.cxx main.cxx To avoid that, you can even write generic rules like: 为了避免这种情况,您甚至可以编写通用规则,例如:

%.o: %.cxx
    g++ -c -o $@ ${GSLFLAGS} ${CFLAGS} $^

And you don't need special rules for main.o and lateral.o , the complete makefile would be: 而且,对于main.olateral.o不需要特殊的规则,完整的makefile将是:

GSLFLAGS := pkg-config --cflags gsl
LIBGSL := pkg-config --libs gsl

all: alg

%.o: %.cxx
    g++ -c -o $@ ${GSLFLAGS} ${CFLAGS} $^

alg: main.o lateral.o
    g++ -o  $@ $^ ${LIBGSL}

You can find a detailed explanation of the syntax above here or a much more detailed documentation here . 你可以找到上面的语法的详细说明这里还是一个更详细的文档在这里

Edit : 编辑

Sorry I missed the C flags, there is also an error there: 抱歉我错过了C标志,那里也有一个错误:

CFLAGS = -c -C -O3 -openmp=parallel

Your should remove the -c since you are already using it in the rule, which is what gcc is complaining about. 您应该删除-c因为您已经在规则中使用了-c ,这就是gcc抱怨的内容。

IMO (but can't test right now) there's something wrong with this line: IMO(但目前无法测试)此行有问题:

CFLAGS = -c -C -O3 -openmp=parallel

I think -openmp=parallel should just be -fopenmp . 我认为-openmp=parallel应该只是-fopenmp First because that's the correct compile flag for OpenMP, second because what's after -o will be interpreted as the name of the output file. 首先是因为这是OpenMP的正确编译标志,其次是-o之后的内容将被解释为输出文件的名称。 And as your error message says, you can't use -c and -o together. 并且如错误消息所述,您不能同时使用-c-o

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

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