Reputation: 31
I get this error:
make all
Building file: ../src/lol.c
Invoking: GCC C Compiler
gcc -lm lol.c -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/lol.d" -MT"src/lol.d" -o "src/lol.o" "../src/lol.c"
gcc: error: lol.c: No such file or directory
make: *** [src/lol.o] Error 1
MAKEFILE
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
-include ../makefile.init
RM := rm -rf
# All of the sources participating in the build are defined here
-include sources.mk
-include src/subdir.mk
-include subdir.mk
-include objects.mk
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif
-include ../makefile.defs
# Add inputs and outputs from these tool invocations to the build variables
# All Target
all: lol
# Tool invocations
lol: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC C Linker'
gcc -o "lol" $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
# Other Targets
clean:
-$(RM) $(OBJS)$(C_DEPS)$(EXECUTABLES) lol
-@echo ' '
.PHONY: all clean dependents
.SECONDARY:
-include ../makefile.targets
SUBDIR.mk
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
# Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \
../src/lol.c
OBJS += \
./src/lol.o
C_DEPS += \
./src/lol.d
# Each subdirectory must supply rules for building sources it contributes
src/%.o: ../src/%.c
@echo 'Building file: $<'
@echo 'Invoking: GCC C Compiler'
gcc -lm lol.c -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
@echo 'Finished building: $<'
@echo ' '
when I try to compile the code below. I use eclipse on ubuntu 14.04lts. I know you'll probably need more details bout the error but I don't know what and how, please just ask if you need further information.
#include <stdio.h>
#include <math.h>
/* to be compiled with "gcc -lm 05_09.c" */
double calculateCharges(float hours);
int main(void)
{
float car_a_hours, car_b_hours, car_c_hours, tothours;
float car_a_charge, car_b_charge, car_c_charge, totcharge;
printf("\n\n");
printf("enter car #1 parking hours: ");
scanf("%f", &car_a_hours);
printf("enter car #2 parking hours: ");
scanf("%f", &car_b_hours);
printf("enter car #3 parking hours: ");
scanf("%f", &car_c_hours);
tothours = car_a_hours + car_b_hours + car_c_hours;
car_a_charge = calculateCharges(car_a_hours);
car_b_charge = calculateCharges(car_b_hours);
car_c_charge = calculateCharges(car_c_hours);
totcharge = car_a_charge + car_b_charge + car_c_charge;
printf("\n\n");
printf("Car\tHours\tCharge\n");
printf("%d\t%5.1f\t%6.2f\n", 1, car_a_hours, car_a_charge);
printf("%d\t%5.1f\t%6.2f\n", 2, car_b_hours, car_b_charge);
printf("%d\t%5.1f\t%6.2f\n", 3, car_c_hours, car_c_charge);
printf("TOTAL\t%5.1f\t%6.2f\n", tothours, totcharge);
printf("\n\n");
return 0;
}
double calculateCharges(float hours)
{
if ((hours - 3.0) <= 0)
return 2.0;
else if ((hours == 24.0))
return 10;
else
return (ceil(hours) - 3) * 0.5 + 2;
}
Upvotes: 1
Views: 18207
Reputation: 31
It was a Gcc Math.h Linking Problem in Eclipse If you use Eclipse/gcc and have functions that need the math.h library, you may find out that the linker can't find functions like sqrt or pow and signal it like this:
undefined reference to `pow' Matrix.c /TzUtils/Sources line 152 C/C++ Problem
undefined reference to `pow' Matrix.c /TzUtils/Sources line 204 C/C++ Problem
and it was my original error, before tried to add wrongly the flag -lm.
This thing happens because the library which contains math.h is not linked by default. To link it you will need to add the extra flag -Im.
In Eclipse this can be done by: Right click on your project in Project Explorer and select Properties. Go to C\C++ Build -> Settings -> Tool Settings -> Gcc Linker -> Libraries and click on green plus button to add a new library. When the dialog pops up, write m, and Eclipse will automatically add the -Im flag. After this I don't get any error. Thanks everyone for the help. Credits answer: dystopiancode.blogspot.it
Upvotes: 1