C语言 C Makefile 问题:“gcc:-lm:链接器输入文件未使用,因为链接未完成 mpicc -lm 3D-ELM.o -o 3D-ELM.exe”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15133343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 05:30:11  来源:igfitidea点击:

C Makefile trouble: "gcc: -lm: linker input file unused because linking not done mpicc -lm 3D-ELM.o -o 3D-ELM.exe"

cmakefile

提问by Eamorr

I'm having some trouble with a C Makefile.

我在使用 C Makefile 时遇到了一些麻烦。

Here are the contents of the Makefile:

下面是 Makefile 的内容:

PROJECT = 3D-ELM
MPICC = mpicc
CLAGS = -g -O3
LIBS = -lm
SRC = src_el
OBJECTS = $(PROJECT).o

$(PROJECT).exe : $(OBJECTS)
        $(MPICC) $(CFLAGS) $(LIBS) $(OBJECTS) -o $(PROJECT).exe

$(PROJECT).o : $(SRC)/$(PROJECT).c
        $(MPICC) $(CFLAGS) $(LIBS) -c $(SRC)/$(PROJECT).c

clean:
        rm -rf *o $(PROJECT)

When I make, here is the error:

当我制作时,这是错误:

gcc: -lm: linker input file unused because linking not done

gcc:-lm:链接器输入文件未使用,因为链接未完成

Does anyone know what's wrong?

有谁知道出了什么问题?

Many thanks in advance,

提前谢谢了,



EDIT: Got it. I don't need to pass libs when making the object file... Doh! bangs head off desk

编辑:明白了。制作目标文件时我不需要传递库...哦!刘海头离开办公桌

Thanks for all your help guys,

谢谢大家的帮助

回答by Blagovest Buyukliev

The problem comes from this part of the makefile:

问题来自makefile的这一部分:

$(PROJECT).o : $(SRC)/$(PROJECT).c
        $(MPICC) $(CFLAGS) $(LIBS) -c $(SRC)/$(PROJECT).c

At this step you are only invoking the compiler. The -cswitch tells the compiler only to compile to an object file, and the linker is not involved at all. Since there is nothing to link, the $(LIBS)part is unnecessary.

在这一步,您只调用编译器。该-c开关告诉编译器只编译成目标文件,并链接器完全不参与。由于没有任何链接,因此该$(LIBS)部分是不必要的。

The actual linking is done at the following stage:

实际链接在以下阶段完成:

$(PROJECT).exe : $(OBJECTS)
        $(MPICC) $(CFLAGS) $(LIBS) $(OBJECTS) -o $(PROJECT).exe

This is where the individual object files are merged together with the libraries to produce an executable. The compiler itself is not invoked at this point because the source files have already been transformed into object files.

这是将单个目标文件与库合并以生成可执行文件的地方。此时不会调用编译器本身,因为源文件已经转换为目标文件。