Tengo problemas con la vinculación de mis archivos.Error de vinculador: "archivo de entrada del enlazador no se utilizó porque la vinculación no se realizó", referencia indefinida a una función en ese archivo
Básicamente, mi programa se compone de:
- El programa principal,
gen1
. gen1
- recibe la entrada envía astr2value
para procesamiento, resultados de salidasstr2value
, rompe de entrada en tokens usando "tokenizer" determina qué tipo de procesamiento que hacer para cada token , y los pasa fuera astr2num
, ostr2cmd
. A continuación, devuelve una matriz de los resultados.str2num
- hace algún procesamientostr2cmd
- ídemauthor.py
- un script en Python que generastr2cmd.c
ystr2cmd.h
de una cabeceracmdTable.h
.
Estoy bastante seguro de que tengo mi incluye bien, lo he comprobado un par de veces. También he comprobado que no hay condiciones #ifndef
mal en los encabezados.
Aquí es mi Makefile:
#CPP = g++ -lserial
CPP = g++ -DTESTMODE
C= gcc
DEFINES = LURC
CFLAGS = -Wall -fshort-enums -D$(DEFINES)
PROJECTFILES = gen1.cpp str2value.o
STR2VALUEFILES = str2value.cpp str2cmd.o str2num.o tokenizer.o str2value.h
gen1 : $(PROJECTFILES)
$(CPP) $(CFLAGS) -o gen1 $(PROJECTFILES)
str2value.o : $(STR2VALUEFILES)
# echo "str2value"
$(CPP) $(CFLAGS) -c $(STR2VALUEFILES)
str2num.o: str2num.cpp str2value.h str2num.hpp
$(C) $(CFLAGS) -c $^
tokenizer.o: tokenizer.cpp tokenizer.hpp
$(CPP) $(CFLAGS) -c $^
str2cmd.o : authorCMDs.py cmdTable.h
python authorCMDs.py cmdTable.h str2cmd #this uses the gcc -E cmdTable.h -DLURC
$(C) $(CFLAGS) -c str2cmd.c str2cmd.h
#TODO: add a thing that checks str2cmd.h/.c has not been modified by hand
.PHONEY: clean
clean:
rm *.o
.PHONEY: all
all:
clear
make clean
make
Aquí está la salida que recibo desde make todo:
make clean
make[1]: Entering directory `/home/frames/LURC/gen1/gen1Source'
rm *.o
make[1]: Leaving directory `/home/frames/LURC/gen1/gen1Source'
make
make[1]: Entering directory `/home/frames/LURC/gen1/gen1Source'
python authorCMDs.py cmdTable.h str2cmd #this uses the gcc -E cmdTable.h -DLURC
str2cmd.c and str2cmd.h, generated from cmdTable.h
gcc -Wall -fshort-enums -DLURC -c str2cmd.c str2cmd.h
gcc -Wall -fshort-enums -DLURC -c str2num.cpp str2value.h str2num.hpp
g++ -DTESTMODE -Wall -fshort-enums -DLURC -c tokenizer.cpp tokenizer.hpp
g++ -DTESTMODE -Wall -fshort-enums -DLURC -c str2value.cpp str2cmd.o str2num.o tokenizer.o str2value.h
g++: str2cmd.o: linker input file unused because linking not done
g++: str2num.o: linker input file unused because linking not done
g++: tokenizer.o: linker input file unused because linking not done
g++ -DTESTMODE -Wall -fshort-enums -DLURC -o gen1 gen1.cpp str2value.o
str2value.o: In function `getValue(char*)':
str2value.cpp:(.text+0xbd): undefined reference to `str2cmd(char*)'
str2value.cpp:(.text+0x102): undefined reference to `str2num(char*)'
str2value.o: In function `getAllValues(char*)':
str2value.cpp:(.text+0x164): undefined reference to `tokenizer::tokenizer(char*)'
str2value.cpp:(.text+0x177): undefined reference to `tokenizer::getNumTokens(char const*)'
str2value.cpp:(.text+0x1a9): undefined reference to `tokenizer::getNextToken(char const*)'
str2value.cpp:(.text+0x1e9): undefined reference to `tokenizer::getNumTokens(char const*)'
str2value.cpp:(.text+0x201): undefined reference to `tokenizer::~tokenizer()'
str2value.cpp:(.text+0x25b): undefined reference to `tokenizer::~tokenizer()'
collect2: ld returned 1 exit status
make[1]: *** [gen1] Error 1
make[1]: Leaving directory `/home/frames/LURC/gen1/gen1Source'
make: *** [all] Error 2
alguna sugerencia acerca de qué se trata? STR2VALUESFILES
tiene todos los archivos de objeto que necesito para definir las funciones que faltan.
¿cómo puedo crear un archivo objeto, fuera de otros archivos objeto, entonces? gen1 no tiene dependencias directas con str2num str2cmd o tokenizer –
Usted compila cada archivo '.cpp' individualmente y luego vincula todos los archivos' .o' resultantes. Agregué un simple ejemplo de 'hacer'. –
Se olvidó de mencionar: administrar dependencias a través de archivos de encabezado, no archivos de objeto. –