make:*** [。o]错误1

时间:2015-05-13 18:27:32

标签: c eclipse makefile ubuntu-14.04

我收到此错误:

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 ' '

当我尝试编译下面的代码时。我在ubuntu 14.04lts上使用eclipse。我知道你可能需要更多关于错误的细节,但我不知道是什么以及如何,请问你是否需要进一步的信息。

#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;
}

1 个答案:

答案 0 :(得分:0)

这是Eclipse中的Gcc Math.h链接问题 如果您使用Eclipse / gcc并且具有需要math.h库的函数,您可能会发现链接器找不到像sqrt或pow这样的函数并发出如下信号:

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

这是我原来的错误,之后尝试错误添加标志-lm。

发生这种情况是因为默认情况下不包含包含math.h的库。要链接它,您需要添加额外的标志-Im。

在Eclipse中,这可以通过以下方式完成: 在Project Explorer中右键单击您的项目,然后选择Properties。 转到C \ C ++ Build - &gt;设置 - &gt;工具设置 - &gt; Gcc Linker - &gt;库并单击绿色加按钮添加新库。弹出对话框时,编写m,Eclipse将自动添加-Im标志。 在此之后我没有得到任何错误。谢谢大家的帮助。 致谢答案:dystopiancode.blogspot.it