je commence à écrire un programme en C, mais je l'erreur suivante et je ne peux pas comprendre pourquoi:Undefined Symbole pour l'architecture x86_64 - C
Undefined symbols for architecture x86_64:
"_receiveByte", referenced from:
_main in main_prog.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [q1] Error 1
Pour autant que je comprends, j'ai inclus tout correctement dans les fichiers appropriés et dans mon makefile, mais j'ai toujours cette erreur. C'est ce que mon code ressemble à:
main_prog.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "physical.h"
#include "main_prog.h"
int main(int argc, char *argv[])
{
PhysicalState * initPhysical();
const Direction blah = L2R;
unsigned char new_char;
new_char = receiveByte(blah);
printf("Done.\n");
}
main_prog.h
#ifndef _MAIN_PROG_H
#define _MAIN_PROG_H
// nothing yet
#endif
physical.h
#ifndef _PHYSICAL_H
#define _PHYSICAL_H
#include <pthread.h>
#define MAX_FRAME_SIZE 1024
typedef enum
{
false,
true
} boolean;
typedef enum
{
L2R,
R2L
} Direction;
struct PHYSICAL_STATE
{
pthread_cond_t L2RTxSignal;
pthread_cond_t L2RRxSignal;
boolean L2RReady;
pthread_mutex_t L2RLock;
pthread_cond_t R2LTxSignal;
pthread_cond_t R2LRxSignal;
boolean R2LReady;
pthread_mutex_t R2LLock;
};
typedef struct PHYSICAL_STATE PhysicalState;
PhysicalState * initPhysical();
unsigned char receiveByte(const Direction dir);
#endif
et enfin mon
makefile
PROG = main_prog
HDRS = physical.h main_prog.h
SRCS = main_prog.c
OBJDIR = object
OBJS = $(patsubst %.c, $(OBJDIR)/%.o, $(SRCS))
CC = gcc
CFLAGS = -Wall --std=c99 -L.
LIBS = -lm
all : $(OBJDIR) $(PROG)
$(PROG) : $(OBJS)
$(CC) $(CFLAGS) $^ -o $(PROG) $(LIBS)
object/%.o : %.c $(HDRS)
$(CC) -c $(CFLAGS) $< -o [email protected] $(LIBS)
$(OBJDIR) :
mkdir -p [email protected]/
clean:
rm -rf object/
rm -f $(PROG)
Il y a également un fichier physical.o
situé dans le même répertoire que tous ces fichiers, alors que le fichier se trouve dans main_prog.o object/
comme spécifié par le makefile . J'ai essayé de déplacer le fichier physical.o
autour ainsi que le fichier main_prog.o
autour (et en changeant le makefile pour correspondre) mais j'ai toujours cette erreur. Toute solution à cette erreur serait grandement appréciée merci.
double possible de [symbole non défini pour l'architecture x86 \ _64 dans la compilation de programme C] (https://stackoverflow.com/questions/29073978/undefined-symbol-for-architecture-x86 -64-dans-compilation-c-programme) –
Le problème était que la référence d'objet manquait dans mon makefile. Même erreur que^cette question, cependant problème et solution différents. –
OK. Essayez l'un des autres [373 résultats] (https://stackoverflow.com/search?q=%5Bc%5D+undefined+symbol+for+architecture+x86_64) –