Os paso la captura con el error que me sale:https://gyazo.com/dbe2919a54ef1ecaf995aa200af65bd6 (https://gyazo.com/dbe2919a54ef1ecaf995aa200af65bd6)
Quiero utilizar una funcion de la estructura Tiempo que he creado yo en una biblioteca aparte y me sale que no le hago referencia, no se que debería hacer. Saludos y gracias.
¿La estructura Tiempo está en el mismo archivo que esMenor?
¿Haces referencia a la otra librería a la hora de linkear?
Se necesitan más datos, que encima la imagen la pusiste cortada, y no se ve la linea del comando de linkeo completa.
Si. la funcion esMenor esta en la misma biblioteca que la estructura Tiempo y esta incluida en ella. En la main hago referencia #include <../ModTiempo/tiempo.h>
Ahora pego todas las bibliotecas
Este sería el módulo de biblioteca tiempo.
#include "tiempo.h"
#include <iostream>
using namespace std;
Tiempo definir(int seg){
int h=seg/3600;
int minutos=seg%3600;
int segundos=(seg%3600)%60;
Tiempo t={h,minutos,segundos};
return t;
}
/*
* Pre: seg >= 0, mil_seg >= 0 y mil_seg <= 999
* Post: Devuelve una medida de tiempo de seg segundos y mil_seg milesimas
* de segundo
*/
Tiempo definir(int seg, int mil_seg){
int h=seg/3600;
int min=seg%3600;
int segundos=(seg%3600)%60;
int milesimas= mil_seg;
Tiempo t={h,min,segundos,milesimas};
return t;
}
/****************************************************************************
* Funciones para conocer la descomposición de un dato de tipo Tiempo
* en horas, minutos, segundos y milésimas de segundo
****************************************************************************/
/*
* Pre: t define una medida de tiempo no negativa con precisión de una milésima
* de segundo.
* Podemos imaginar a t equivalente a <h:m:s:mil>, donde h son horas (igual
* o mayor que 0), m son minutos (entre 0 y 59), s son segundos (entre 0 y
* 59) y mil son milésimas de segundo (entre 0 y 999)
* Post: Devuelve el número de horas h de la medida de tiempo t
*/
int hora (Tiempo t){
return t.horas;
}
/*
* Pre: t define una medida de tiempo no negativa con precisión de una milésima
* de segundo.
* Podemos imaginar a t equivalente a <h:m:s:mil>, donde h son horas (igual
* o mayor que 0), m son minutos (entre 0 y 59), s son segundos (entre 0 y
* 59) y mil son milésimas de segundo (entre 0 y 999)
* Post: Devuelve el número de minutos m de la medida de tiempo t
*/
int minuto (Tiempo t){
return t.minutos;
}
/*
* Pre: t define una medida de tiempo no negativa con precisión de una milésima
* de segundo.
* Podemos imaginar a t equivalente a <h:m:s:mil>, donde h son horas (igual
* o mayor que 0), m son minutos (entre 0 y 59), s son segundos (entre 0 y
* 59) y mil son milésimas de segundo (entre 0 y 999)
* Post: Devuelve el número de segundos s de la medida de tiempo t
*/
int segundo (Tiempo t){
return t.seg;
}
/*
* Pre: t define una medida de tiempo no negativa con precisión de una milésima
* de segundo.
* Podemos imaginar a t equivalente a <h:m:s:mil>, donde h son horas (igual
* o mayor que 0), m son minutos (entre 0 y 59), s son segundos (entre 0 y
* 59) y mil son milésimas de segundo (entre 0 y 999)
* Post: Devuelve el número de milésimas de segundos mil de la medida de tiempo t
*/
int milesima (Tiempo t){
return t.mil_seg;
}
/****************************************************************************
* Funciones para comparar dos datos de tipo Tiempo
****************************************************************************/
/*
* Pre: t1 y t2 definen dos medidas de tiempo con precisión de una milésima
* de segundo, iguales o superiores a 0 milésimas de segundo
* Post: Devuelve true si y sólo si el tiempo t1 es más corto que el tiempo t2
*/
bool esMenor (Tiempo t1, Tiempo t2){
if(t1.horas<t2.horas){
return t1.horas<t2.horas;
}
else if(t1.horas==t2.horas && t1.minutos<t2.minutos){
return t1.minutos<t2.minutos;
}
else if(t1.minutos<t2.minutos && t1.seg<t2.seg){
return t1.seg<t2.seg;
}
else if(t1.segundos==t2.segundos && t1.mil_seg<t2.mil_seg){
return t1.mil_seg<t2.mil_seg;
}
else{
return false;
}
}
/*
* Pre: t1 y t2 definen dos medidas de tiempo con precisión de una milésima
* de segundo, iguales o superiores a 0 milésimas de segundo
* Post: Devuelve true si y sólo si el tiempo t1 es más largo que el tiempo t2
*/
bool esMayor (Tiempo t1, Tiempo t2){
if(t1.horas>t2.horas){
return t1.horas>t2.horas;
}
else if(t1.horas==t2.horas && t1.minutos>t2.minutos){
return t1.minutos>t2.minutos;
}
else if(t1.minutos>t2.minutos && t1.seg>t2.seg){
return t1.seg>t2.seg;
}
else if(t1.segundos==t2.segundos && t1.mil_seg>t2.mil_seg){
return t1.mil_seg>t2.mil_seg;
}
else{
return false;
}
}
/*
* Pre: t1 y t2 definen dos medidas de tiempo con precisión de una milésima
* de segundo, iguales o superiores a 0 milésimas de segundo
* Post: Devuelve true si y sólo el valor del tiempo t1 es igual al del
* tiempo t2
*/
bool sonIguales (Tiempo t1, Tiempo t2){
if(t1.horas==t2.horas && t1.minutos==t2.minutos && t1.seg==t2.seg && t1.mil_seg==t2.mil_seg){
return t1.horas==t2.horas;
}
else{
return false;
}
}
/****************************************************************************
* Funciones para operar aritméticamente con un par de datos de tipo Tiempo
****************************************************************************/
/*
* Pre: t1 y t2 definen dos medidas de tiempo con precisión de una milésima
* de segundo, iguales o superiores a 0 milésimas de segundo.
* Post: Devuelve un tiempo igual a la suma de los tiempos t1 y t2
*/
Tiempo sumar (Tiempo t1, Tiempo t2){
t1=t1.horas*3600+t1.minutos*60+t1.seg+(double)t1.mil_seg/1000;
t2=t2.horas*3600+t2.minutos*60+t2.seg+(double)t2.mil_seg/1000;
return t1+t2;
}
/*
* Pre: t1 y t2 definen dos medidas de tiempo con precisión de una milésima
* de segundo, iguales o superiores a 0 milésimas de segundo. El valor
* de t1 es igual o superior al de t2.
* Post: Devuelve un tiempo igual a la diferencia del tiempo t1 menos el
* tiempo t2
*/
Tiempo restar (Tiempo t1, Tiempo t2){
t1=t1.horas*3600+t1.minutos*60+t1.seg+(double)t1.mil_seg/1000;
t2=t2.horas*3600+t2.minutos*60+t2.seg+(double)t2.mil_seg/1000;
return t1-t2;
}
Implemento esta función en otra biblioteca y aquí me salta el error:
#include <iostream>
#include <iomanip>
#include "../ModTiempo/tiempo.h"
using namespace std;
/*
* Pre: n >= 0 y T[0,n-1] almacena los valores de n medidas de tiempo.
* Post: Los valores de T[0,n-1] han sido permutados de forma que ahora
* se encuentran ordenados según medidas de tiempo de duración
* igual o creciente. Es decir, el tiempo T[0] es igual o menor
* que el tiempo T[1], ..., y el tiempo T[n-2] es menor o igual
* que el tiempo T[n-1]
*/
void ordenar(Tiempo T[], const int n){
for(int i=0;i<n;i++){
int menor=i;
for(int j=i+1;j<n;j++){
if(esMenor(T[j],T[menor])){
menor=j;
}
}
Tiempo aux=T[i];
T[i]=T[menor];T[menor]=aux;
}
}
/*
* Pre: El tiempo t es inferior a 100 horas
* Post: Escribe por pantalla una secuencia de 12 caracteres (y sin
* acabar la línea) en la que presenta el tiempo definido por t
* con el siguiente formato:
* hh:mm:ss,mmm
* Un ejemplo:
* 07:30:00,055
*/
void mostrar (const Tiempo t){
if(hora(t)>=0 && hora(t)<=100){
cout<<setw(2)<<hora(t)<< ':'<<setw(2)<<setfill('0')<<minuto(t)<<':'<<setw(2)<<setfill('0')<<segundo(t)<<','<<setw(3)<<setfill('0')<<milesima(t);
}
}
/*
* Pre: Los tiempos almacenados en T[0,n-1] son inferiores a 100 horas
* Post: Escribe por pantalla n líneas en las que presenta los valores de
* los tiempos almacenados en T[0,n-1] con el siguiente formato
* (cadauno de los tiempos ocupa 12 caracteres):
* 01. 03:12:00,500
* 02. 12:45;30,000
* 03. 00:01:00,450
* ....
*/
void mostrar (const Tiempo T[], const int n){
{
if(hora(t)>=0 && hora(t)<=100){
for(int i=0;i<n;i++){
cout<<setw(2)<<hora(t)<< ':'<<setw(2)<<setfill('0')<<minuto(t)<<':'<<setw(2)<<setfill('0')<<segundo(t)<<','<<setw(3)<<setfill('0')<<milesima(t);
}
}
}
Y aquí todos los errores del codigo:
https://gyazo.com/aa039937548ff7355e5262ef0e087e11 (https://gyazo.com/aa039937548ff7355e5262ef0e087e11)
Creo que es porque no inicializo ningun valor.
No hagas multiples post, edita el último que has hecho.
¿Compilaste el .cpp de la librería? Las librerías se trabajan así:
Citarlibreria.cpp compilado -> libreria.o
main.cpp compilado -> main.o
main.o + libreria.o compilados -> main.exe
No has puesto más información, así que te dejo eso y ya dirás.
Perdona no me había enterado bien antes, no me aparece tiempo.o creo que no se ha llegado a compilar. Paso la compilacion hasta el error aqui: https://gyazo.com/223ee8af50bcadacdffce56e4e4dca83 (https://gyazo.com/223ee8af50bcadacdffce56e4e4dca83), ¿Qué es lo que puede ocurrir entonces? se compila antes la biblioteca que contiene a la otra??
Esta es toda la compilacion:
C:\Windows\system32\cmd.exe /C mingw32-make.exe -j 8 -e -f Makefile
"----------Building project:[ ModHerramientas - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'C:/Users/Guillermo/Desktop/trabajos/ModHerramientas'
mingw32-make.exe[1]: Leaving directory 'C:/Users/Guillermo/Desktop/trabajos/ModHerramientas'
mingw32-make.exe[1]: Entering directory 'C:/Users/Guillermo/Desktop/trabajos/ModHerramientas'
g++ -c "C:/Users/Guillermo/Desktop/trabajos/ModHerramientas/herramientas.cpp" -g -O0 -Wall -o ./Debug/herramientas.cpp.o -I. -I.
g++ -o ./Debug/ModHerramientas @"ModHerramientas.txt" -L.
./Debug/herramientas.cpp.o: In function `ordenar(Tiempo*, int)':
C:/Users/Guillermo/Desktop/trabajos/ModHerramientas/herramientas.cpp:21: undefined reference to `esMenor(Tiempo, Tiempo)'
./Debug/herramientas.cpp.o: In function `mostrar(Tiempo)':
C:/Users/Guillermo/Desktop/trabajos/ModHerramientas/herramientas.cpp:40: undefined reference to `hora(Tiempo)'
C:/Users/Guillermo/Desktop/trabajos/ModHerramientas/herramientas.cpp:40: undefined reference to `hora(Tiempo)'
C:/Users/Guillermo/Desktop/trabajos/ModHerramientas/herramientas.cpp:41: undefined reference to `milesima(Tiempo)'
C:/Users/Guillermo/Desktop/trabajos/ModHerramientas/herramientas.cpp:41: undefined reference to `segundo(Tiempo)'
C:/Users/Guillermo/Desktop/trabajos/ModHerramientas/herramientas.cpp:41: undefined reference to `minuto(Tiempo)'
C:/Users/Guillermo/Desktop/trabajos/ModHerramientas/herramientas.cpp:41: undefined reference to `hora(Tiempo)'
./Debug/herramientas.cpp.o: In function `mostrar(Tiempo const*, int)':
C:/Users/Guillermo/Desktop/trabajos/ModHerramientas/herramientas.cpp:57: undefined reference to `hora(Tiempo)'
C:/Users/Guillermo/Desktop/trabajos/ModHerramientas/herramientas.cpp:57: undefined reference to `hora(Tiempo)'
C:/Users/Guillermo/Desktop/trabajos/ModHerramientas/herramientas.cpp:58: undefined reference to `milesima(Tiempo)'
C:/Users/Guillermo/Desktop/trabajos/ModHerramientas/herramientas.cpp:58: undefined reference to `segundo(Tiempo)'
C:/Users/Guillermo/Desktop/trabajos/ModHerramientas/herramientas.cpp:58: undefined reference to `minuto(Tiempo)'
C:/Users/Guillermo/Desktop/trabajos/ModHerramientas/herramientas.cpp:58: undefined reference to `hora(Tiempo)'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[1]: *** [Debug/ModHerramientas] Error 1
mingw32-make.exe: *** [All] Error 2
ModHerramientas.mk:78: recipe for target 'Debug/ModHerramientas' failed
mingw32-make.exe[1]: Leaving directory 'C:/Users/Guillermo/Desktop/trabajos/ModHerramientas'
Makefile:4: recipe for target 'All' failed
====13 errors, 0 warnings====
¿Puedes pasar el makefile?
De todos modos, para que veas el procedimiento:
(https://i.gyazo.com/cdf983decbadd606d86f0be7bbf4d313.png)
(https://i.gyazo.com/b84791567e6f235284711ceab742059d.png)
Compilando desde consola me salta este error:
https://gyazo.com/6537c560794c390e48b400f9e4bc0842 (https://gyazo.com/6537c560794c390e48b400f9e4bc0842)
En el makefile del workspace me pone esto:
.PHONY: clean All
All:
@echo "----------Building project:[ ModHerramientas - Debug ]----------"
@cd "ModHerramientas" && "$(MAKE)" -f "ModHerramientas.mk"
clean:
@echo "----------Cleaning project:[ ModHerramientas - Debug ]----------"
@cd "ModHerramientas" && "$(MAKE)" -f "ModHerramientas.mk" clean
Y este es el mk de herramientas project:
##
## Auto Generated makefile by CodeLite IDE
## any manual changes will be erased
##
## Debug
ProjectName :=ModHerramientas
ConfigurationName :=Debug
WorkspacePath := "C:\Users\Guillermo\Desktop\trabajos"
ProjectPath := "C:\Users\Guillermo\Desktop\trabajos\ModHerramientas"
IntermediateDirectory :=./Debug
OutDir := $(IntermediateDirectory)
CurrentFileName :=
CurrentFilePath :=
CurrentFileFullPath :=
User :=Guillermo
Date :=29/11/2015
CodeLitePath :="C:\Program Files\CodeLite"
LinkerName :=g++
SharedObjectLinkerName :=g++ -shared -fPIC
ObjectSuffix :=.o
DependSuffix :=.o.d
PreprocessSuffix :=.o.i
DebugSwitch :=-gstab
IncludeSwitch :=-I
LibrarySwitch :=-l
OutputSwitch :=-o
LibraryPathSwitch :=-L
PreprocessorSwitch :=-D
SourceSwitch :=-c
OutputFile :=$(IntermediateDirectory)/$(ProjectName)
Preprocessors :=
ObjectSwitch :=-o
ArchiveOutputSwitch :=
PreprocessOnlySwitch :=-E
ObjectsFileList :="ModHerramientas.txt"
PCHCompileFlags :=
MakeDirCommand :=makedir
RcCmpOptions :=
RcCompilerName :=windres
LinkOptions :=
IncludePath := $(IncludeSwitch). $(IncludeSwitch).
IncludePCH :=
RcIncludePath :=
Libs :=
ArLibs :=
LibPath := $(LibraryPathSwitch).
##
## Common variables
## AR, CXX, CC, AS, CXXFLAGS and CFLAGS can be overriden using an environment variables
##
AR := ar rcus
CXX := g++
CC := gcc
CXXFLAGS := -g -O0 -Wall $(Preprocessors)
CFLAGS := -g -O0 -Wall $(Preprocessors)
ASFLAGS :=
AS := as
##
## User defined environment variables
##
CodeLiteDir:=C:\Program Files\CodeLite
Objects0=$(IntermediateDirectory)/herramientas.cpp$(ObjectSuffix) $(IntermediateDirectory)/main.cpp$(ObjectSuffix)
Objects=$(Objects0)
##
## Main Build Targets
##
.PHONY: all clean PreBuild PrePreBuild PostBuild MakeIntermediateDirs
all: $(OutputFile)
$(OutputFile): $(IntermediateDirectory)/.d $(Objects)
@$(MakeDirCommand) $(@D)
@echo "" > $(IntermediateDirectory)/.d
@echo $(Objects0) > $(ObjectsFileList)
$(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions)
MakeIntermediateDirs:
@$(MakeDirCommand) "./Debug"
$(IntermediateDirectory)/.d:
@$(MakeDirCommand) "./Debug"
PreBuild:
##
## Objects
##
$(IntermediateDirectory)/herramientas.cpp$(ObjectSuffix): herramientas.cpp $(IntermediateDirectory)/herramientas.cpp$(DependSuffix)
$(CXX) $(IncludePCH) $(SourceSwitch) "C:/Users/Guillermo/Desktop/trabajos/ModHerramientas/herramientas.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/herramientas.cpp$(ObjectSuffix) $(IncludePath)
$(IntermediateDirectory)/herramientas.cpp$(DependSuffix): herramientas.cpp
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/herramientas.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/herramientas.cpp$(DependSuffix) -MM "herramientas.cpp"
$(IntermediateDirectory)/herramientas.cpp$(PreprocessSuffix): herramientas.cpp
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/herramientas.cpp$(PreprocessSuffix) "herramientas.cpp"
$(IntermediateDirectory)/main.cpp$(ObjectSuffix): main.cpp $(IntermediateDirectory)/main.cpp$(DependSuffix)
$(CXX) $(IncludePCH) $(SourceSwitch) "C:/Users/Guillermo/Desktop/trabajos/ModHerramientas/main.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/main.cpp$(ObjectSuffix) $(IncludePath)
$(IntermediateDirectory)/main.cpp$(DependSuffix): main.cpp
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/main.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/main.cpp$(DependSuffix) -MM "main.cpp"
$(IntermediateDirectory)/main.cpp$(PreprocessSuffix): main.cpp
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/main.cpp$(PreprocessSuffix) "main.cpp"
-include $(IntermediateDirectory)/*$(DependSuffix)
##
## Clean
##
clean:
$(RM) -r ./Debug/
El de tiempo:
##
## Auto Generated makefile by CodeLite IDE
## any manual changes will be erased
##
## Debug
ProjectName :=ModTiempo
ConfigurationName :=Debug
WorkspacePath := "C:\Users\Guillermo\Desktop\trabajos"
ProjectPath := "C:\Users\Guillermo\Desktop\trabajos\ModTiempo"
IntermediateDirectory :=./Debug
OutDir := $(IntermediateDirectory)
CurrentFileName :=
CurrentFilePath :=
CurrentFileFullPath :=
User :=Guillermo
Date :=29/11/2015
CodeLitePath :="C:\Program Files\CodeLite"
LinkerName :=g++
SharedObjectLinkerName :=g++ -shared -fPIC
ObjectSuffix :=.o
DependSuffix :=.o.d
PreprocessSuffix :=.o.i
DebugSwitch :=-gstab
IncludeSwitch :=-I
LibrarySwitch :=-l
OutputSwitch :=-o
LibraryPathSwitch :=-L
PreprocessorSwitch :=-D
SourceSwitch :=-c
OutputFile :=$(IntermediateDirectory)/$(ProjectName)
Preprocessors :=
ObjectSwitch :=-o
ArchiveOutputSwitch :=
PreprocessOnlySwitch :=-E
ObjectsFileList :="ModTiempo.txt"
PCHCompileFlags :=
MakeDirCommand :=makedir
RcCmpOptions :=
RcCompilerName :=windres
LinkOptions :=
IncludePath := $(IncludeSwitch). $(IncludeSwitch).
IncludePCH :=
RcIncludePath :=
Libs :=
ArLibs :=
LibPath := $(LibraryPathSwitch).
##
## Common variables
## AR, CXX, CC, AS, CXXFLAGS and CFLAGS can be overriden using an environment variables
##
AR := ar rcus
CXX := g++
CC := gcc
CXXFLAGS := -g -O0 -Wall $(Preprocessors)
CFLAGS := -g -O0 -Wall $(Preprocessors)
ASFLAGS :=
AS := as
##
## User defined environment variables
##
CodeLiteDir:=C:\Program Files\CodeLite
Objects0=$(IntermediateDirectory)/tiempo.cpp$(ObjectSuffix)
Objects=$(Objects0)
##
## Main Build Targets
##
.PHONY: all clean PreBuild PrePreBuild PostBuild MakeIntermediateDirs
all: $(OutputFile)
$(OutputFile): $(IntermediateDirectory)/.d $(Objects)
@$(MakeDirCommand) $(@D)
@echo "" > $(IntermediateDirectory)/.d
@echo $(Objects0) > $(ObjectsFileList)
$(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions)
MakeIntermediateDirs:
@$(MakeDirCommand) "./Debug"
$(IntermediateDirectory)/.d:
@$(MakeDirCommand) "./Debug"
PreBuild:
##
## Objects
##
$(IntermediateDirectory)/tiempo.cpp$(ObjectSuffix): tiempo.cpp $(IntermediateDirectory)/tiempo.cpp$(DependSuffix)
$(CXX) $(IncludePCH) $(SourceSwitch) "C:/Users/Guillermo/Desktop/trabajos/ModTiempo/tiempo.cpp" $(CXXFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/tiempo.cpp$(ObjectSuffix) $(IncludePath)
$(IntermediateDirectory)/tiempo.cpp$(DependSuffix): tiempo.cpp
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/tiempo.cpp$(ObjectSuffix) -MF$(IntermediateDirectory)/tiempo.cpp$(DependSuffix) -MM "tiempo.cpp"
$(IntermediateDirectory)/tiempo.cpp$(PreprocessSuffix): tiempo.cpp
@$(CXX) $(CXXFLAGS) $(IncludePCH) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/tiempo.cpp$(PreprocessSuffix) "tiempo.cpp"
-include $(IntermediateDirectory)/*$(DependSuffix)
##
## Clean
##
clean:
$(RM) -r ./Debug/
¿Tienes la librería agregada al proyecto?
He pasado lo que acabo de compilar en consola arriba, tengo dos proyectos distintos pero la libreria de una la uso en otro, hay algun problema en eso??
El proyecto modtiempo y modherramientas estan en la misma carpeta, con utilizar esto en el modulo de herrmientas debería de bastar no??
#include "../ModTiempo/tiempo.h"