gpt4 book ai didi

c - make : *** [. o]错误1

转载 作者:行者123 更新时间:2023-11-30 19:43:00 27 4
gpt4 key购买 nike

我收到此错误:

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

最佳答案

这是 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 标志。此后我没有收到任何错误。感谢大家的帮助。学分答案:dystopiancode.blogspot.it

关于c - make : *** [. o]错误1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30222597/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com