undefined reference to `log' [message #1849606] |
Wed, 26 January 2022 16:50 |
Jim De Broux Messages: 3 Registered: January 2022 |
Junior Member |
|
|
compiles without issue
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define TEST 2.0
int main(int argc, char *argv[]) {
double test = 0.0;
double result = 0.0;
test = 2.0;
result = log(2);
printf("\nresult is %f", result);
return 0;
}
As does this
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define TEST 2.0
int main(int argc, char *argv[]) {
double test = 0.0;
double result = 0.0;
test = 2.0;
result = log(TEST);
printf("\nresult is %f", result);
return 0;
}
BUT this gives an error on compilation
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define TEST 2.0
int main(int argc, char *argv[]) {
double test = 0.0;
double result = 0.0;
test = 2.0;
result = log(test);
printf("\nresult is %f", result);
return 0;
}
The error is shown as :
13:35:39 **** Incremental Build of configuration Debug for project test_fp ****
make all
Building file: ../src/test_fp.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/test_fp.d" -MT"src/test_fp.o" -o "src/test_fp.o" "../src/test_fp.c"
Finished building: ../src/test_fp.c
Building target: test_fp
Invoking: GCC C Linker
gcc -o "test_fp" ./src/test_fp.o
./src/test_fp.o: In function `main':
/home/jim/projects/test_fp/Debug/../src/test_fp.c:12: undefined reference to `log'
makefile:43: recipe for target 'test_fp' failed
collect2: error: ld returned 1 exit status
make: *** [test_fp] Error 1
"make all" terminated with exit code 2. Build might be incomplete.
13:35:39 Build Failed. 3 errors, 0 warnings. (took 321ms)
The differences in the code are log with constants and log with variable
Interesting that when I use a constant as an argument the reference to "log" is not a problem but when I try using a variable as an argument it can longer find "log".
So far, Googling around, the info has been scanty, but the best I can determine is that the libraries are being linked in the wrong order. This would seem to me to be an error in the makefile generation and that the gcc compiler has gotten more particular with newer releases. I have tried re-compiling older programs that compiled successfully before and that used <math.h>, but now they no longer compile where once they did.
Here is the make file:
################################################################################
# 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 objects.mk
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif
-include ../makefile.defs
OPTIONAL_TOOL_DEPS := \
$(wildcard ../makefile.defs) \
$(wildcard ../makefile.init) \
$(wildcard ../makefile.targets) \
BUILD_ARTIFACT_NAME := test_fp
BUILD_ARTIFACT_EXTENSION :=
BUILD_ARTIFACT_PREFIX :=
BUILD_ARTIFACT := $(BUILD_ARTIFACT_PREFIX)$(BUILD_ARTIFACT_NAME)$(if $(BUILD_ARTIFACT_EXTENSION),.$(BUILD_ARTIFACT_EXTENSION),)
# Add inputs and outputs from these tool invocations to the build variables
# All Target
all: main-build
# Main-build Target
main-build: test_fp
# Tool invocations
test_fp: $(OBJS) $(USER_OBJS) makefile objects.mk $(OPTIONAL_TOOL_DEPS)
@echo 'Building target: $@'
@echo 'Invoking: GCC C Linker'
gcc -o "test_fp" $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
# Other Targets
clean:
-$(RM) test_fp
-@echo ' '
.PHONY: all clean dependents main-build
-include ../makefile.targets
Since the makefile should NOT be edited I am wondering if I am missing something in the initial set-up of my project or is there something else amiss.
My system info:
:~$ cc --version
cc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I am using Eclipse 2021-12, downloaded directly from eclipse.org
Any information, even just pointing me in the right direction, would be appreciated and likely helpful.
Thanks
[Updated on: Wed, 26 January 2022 18:30] Report message to a moderator
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.29780 seconds