无法在代码/makefile中找到问题--> clang:错误:链接器命令失败,退出代码为1

问题描述 投票:0回答:1

获取 clang: 错误:运行 makefile 时链接器命令失败,退出代码为 1。特别是在尝试创建可执行文件时:

gcc powers.c -Wall -pedantic -ansi -c
gcc bounds.o powers.o -o pracTwo
duplicate symbol '_power' in:
    bounds.o
    powers.o

生成文件:

pracTwo: bounds.o powers.o
    gcc bounds.o powers.o -o pracTwo

bounds.o : bounds.c macros.h
    gcc bounds.c -Wall -pedantic -ansi -c

powers.o : powers.c
    gcc powers.c -Wall -pedantic -ansi -c

clean: 
    rm -f pracTwo bounds.o powers.o

预期结果,创建了 2 个 .o 文件(bounds.o 和 powers.o),然后将它们链接在一起以生成 pracTwo 可执行文件。尝试查看我的文件但无法找到问题?

以下是 .c 文件的标头: 边界.c

#include <stdio.h>
#include "macros.h"

void intCheck();
void doubleCheck();
void charCheck();

还有权力。c

#include <stdio.h>
#include <stdlib.h>

int power();

这是头文件:

#ifndef MACROS_H
#define MACROS_H

#include "powers.c"
#define FALSE 0
#define TRUE !FALSE

#define BETWEEN (n<lower) || (n>upper)

#endif

不确定问题是什么,找不到代码的任何错误。不确定以下重复符号“_power”的含义。

c makefile header c89
1个回答
0
投票

当您将

powers.c
包含到
bounds.c
中并同时链接
bounds.o
power.o
时,您最终会得到链接两次的相同符号。该代码仅包含声明,因此我无法重现该错误,并且 gcc 在我的系统上抱怨
power
而不是
_power

我建议您不要包含 .c 文件并仅依靠链接 (

power.o
)。您还可以将符号声明为静态以使其文件成为本地文件。

_
开头的不相关标识符是保留的 (7.1.3),因此建议您不要在代码中使用它。

© www.soinside.com 2019 - 2024. All rights reserved.