1
所以我有三個文件:重複的符號錯誤 - 全局變量
jarvismarch.c
jarvismarchtools.c
jarvismarchtools.h
運行make
後,我收到以下錯誤:
Andrew-Carpenters-Laptop:Independent Study ahcarpenter$ make
cc -c -o jarvismarch.o jarvismarch.c
cc -c -o jarvismarchtools.o jarvismarchtools.c
cc -o jarvismarch jarvismarch.o jarvismarchtools.o
ld: duplicate symbol _string1 in jarvismarchtools.o and jarvismarch.o for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1
string 1
是內jarvismarchtools.c
聲明。 jarvismarchtools.h
包含在jarvismarchtools.c
以及jarvismarch.c
之內。
任何想法,我怎麼能解決這個問題?
在jarvismarchtools.h
:
/*
FILENAME: jarvismarchtools.h
AUTHOR: Andrew H. Carpenter
DATE: 2 Feb 2013
DESCRIPTION: This is a header file containing tools for running Jarvis' March.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
extern int string1 = 1;
typedef struct Point {
double x, y;
char *label;
} point;
/*
DESCRIPTION: A function that determines the angle (in degrees) between two points.
INPUT: Requires two points as input.
在jarvismarchtools.c
:
/*
FILENAME: jarvismarchtools.c
AUTHOR: Andrew H. Carpenter
DATE: 2 Feb 2013
DESCRIPTION: This is an implemenetation file containing tools for running Jarvis' March.
*/
#include "jarvismarchtools.h"
int string1 = 1;
float getAngle(point p1, point p2){
所以我做了上述變化,但我仍然收到上述錯誤。有任何想法嗎? – Drew
@Drew請發佈修改後的代碼和確切的錯誤消息。 –
您可能還想補充一點,變量只能在一個地方初始化。 –