【问题标题】:make: *** [.o] Error 1制作:*** [.o] 错误 1
【发布时间】:2015-07-25 04:47:33
【问题描述】:

我得到这个错误:

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 

制作文件

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

【问题讨论】:

  • 我们需要错误输出中的 above 行。特别是关于代码中的错误等。
  • @dnt994 添加更多日志
  • 显示生成文件。该编译命令显然很混乱(lol.c 有两次不同的路径)。
  • @EtanReisner 我在哪里以及如何做到这一点?对不起,我是个菜鸟:D
  • 有问题的目标不在那个makefile中。它必须在其中列出的 included 生成文件之一中。

标签: c eclipse makefile ubuntu-14.04


【解决方案1】:

这是 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 -> Settings -> Tool Settings -> Gcc Linker -> Libraries 并单击绿色加号按钮添加一个新库。弹出对话框时,写m,Eclipse会自动添加-Im标志。 在此之后我没有收到任何错误。感谢大家的帮助。 学分答案:dytopiancode.blogspot.it

【讨论】:

    猜你喜欢
    • 2021-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-08
    • 1970-01-01
    • 2019-07-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多