C: No such file eller Dir - A hva
Okay har skrevet et test program i C og bruger GCC til at compile med, men får den her fejl
test3.c:2:26: error: math_functions: No such file or directory
men øøh hvorfor gør den det, her er hvad jeg gør i terminal
new-host-2:test3 larsnielsen$ ls
math_functions.c math_functions.h test3.c
new-host-2:test3 larsnielsen$ gcc test3.c math_functions.c -o test3
test3.c:2:26: error: math_functions: No such file or directory
new-host-2:test3 larsnielsen$
- Log in to post comments
Kommentarer4
Jeg starter med at tænde
Jeg starter med at tænde for min synske evne til at læse kildekoden til det program du er ved at skrive, men ikke gør tilgængeligt.
$ export PSYCHIC=1;
I C skal du til forskel fra C++, huske at angive det fulde filnavn, du kan ikke undlade .h.
så hvis du ændrer
#include "math_functions"
til
#include "math_functions.h"
Så skulle det gerne virke
Undskyld jeg glemte koden,
Undskyld jeg glemte coden men den er her:
test3.c
#include
#include "math_functions.h"
main()
{
int theSum = sum(8, 12);
float theAverage = average(16.9, 7.86, 3.4);
printf("The sum is: %i ", theSum);
printf("and the average is: %f \n", theAverage);
printf("average casted to an int is: %i \n", (int)theAverage);
}
mathfunctions.h
int sum(int x, int y);
float average (float x, float y, float z);
math_functions.c
int sum (int x, int y)
{
return (x+y);
}
float average(float x, float y, float z)
{
return(x + y + z) / 3;
}
#2 Det er vigtigt at du inde
#2
Det er vigtigt at du inde i math_functions.c inkluderer math_functions.h
Du skal desuden derefter compile med:
gcc test3.c math_functions.c
Har lige selv prøvet at gøre det og det virker fint her nu. :)
Okay tak
Okay tak