makefile error

Hello!

How is it possible to solve errors in makefile?
what are they mean?

more specifically i have project on sdk xilinx .
application project
library project
library project

library projects compiled.
but application project gets error on makefile inside debug folder:

make: *** [makefile:50: test.elf] Error 1

 
 arm-linux-gnueabihf-g++  -o "test.elf" $(OBJS) $(USER_OBJS) $(LIBS)


Please help😁
Totally depends on what the Makefile is doing, and what exact error you get!

I suggest: Start by trying to understand what the specific rule (command) that fails is actually trying to do...

Makefiles consist of rules which describe how to carry out commands. For example, a rule might explain how to compile a single source file, or how to link all the object files into the executable, or perhaps how to clean up all the object files. A rule has the following form

1
2
3
4
target: dependencies
        command
        command
        ...



See also:
https://www.c-howto.de/tutorial/makefiles/
Last edited on
Maybe you could show more of the error(s), and the line it's trying to run, we might be able to provide more substantial help.

Right now, there isn't much to go on.
The file is in aplication project --> debug folder
'test' is my app. project .

after compile success i should get test.elf file.

the makefile:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
################################################################################
# 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 $(CC_DEPS)),)
-include $(CC_DEPS)
endif
ifneq ($(strip $(C_UPPER_DEPS)),)
-include $(C_UPPER_DEPS)
endif
ifneq ($(strip $(CXX_DEPS)),)
-include $(CXX_DEPS)
endif
ifneq ($(strip $(S_UPPER_DEPS)),)
-include $(S_UPPER_DEPS)
endif
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
ifneq ($(strip $(CPP_DEPS)),)
-include $(CPP_DEPS)
endif
endif

-include ../makefile.defs

# Add inputs and outputs from these tool invocations to the build variables 
ELFSIZE += \
test.elf.size \


# All Target
all: test.elf secondary-outputs

# Tool invocations
test.elf: $(OBJS)  $(USER_OBJS)
	@echo 'Building target: $@'
	@echo 'Invoking: ARM v7 Linux g++ linker'
	arm-linux-gnueabihf-g++  -o "test.elf" $(OBJS) $(USER_OBJS) $(LIBS)
	@echo 'Finished building target: $@'
	@echo ' '

test.elf.size: test.elf
	@echo 'Invoking: ARM v7 Linux Print Size'
	arm-linux-gnueabihf-size test.elf  |tee "test.elf.size"
	@echo 'Finished building: $@'
	@echo ' '

# Other Targets
clean:
	-$(RM) $(CC_DEPS)$(EXECUTABLES)$(OBJS)$(C_UPPER_DEPS)$(CXX_DEPS)$(S_UPPER_DEPS)$(C_DEPS)$(CPP_DEPS)$(ELFSIZE) test.elf
	-@echo ' '

secondary-outputs: $(ELFSIZE)

.PHONY: all clean dependents
.SECONDARY:

-include ../makefile.targets




in the console i see:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
'Finished building: ../src/main.cpp'
' '
'Building target: test.elf'
'Invoking: ARM v7 Linux g++ linker'
arm-linux-gnueabihf-g++  -o "test.elf"  ./src/main.o  stld1553.a stld1553drvapi_win32.a 
stld1553drvapi_win32.a(SitalSDK.o): In function `GetMemSize(short)':
C:\SitalProjects\Linux_PCIe_Project\demo1\API\Debug/../src/SitalSDK.cpp:816: undefined reference to `Sital_GetDeviceMemSize(void*, unsigned int*)'
C:\SitalProjects\Linux_PCIe_Project\demo1\API\Debug/../src/SitalSDK.cpp:829: undefined reference to `Sital_GetDeviceMemSize(void*, unsigned int*)'
stld1553drvapi_win32.a(SitalSDK.o): In function `_startInterruptPoll()':
C:\SitalProjects\Linux_PCIe_Project\demo1\API\Debug/../src/SitalSDK.cpp:2425: undefined reference to `pthread_create'
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:50: test.elf] Error 1

19:11:24 Build Finished (took 673ms)
 
Linker: undefined reference

You don't provide the linker the object files (or libraries) that do implement the Sital_GetDeviceMemSize(void*, unsigned int*) and pthread_create
Remember i am new to c++

so i include actually the .a files of the libraries in debug folder in app. project.

it didn't help . any suggestions?

The .a files aren't used at runtime. They are needed by the linker. At some point, you need to pass in a parameter to the compiler to link the library.

For example, if you have libblah.a, you pass in -lblah in the compiler command line.
Compiler generates object file from each translation unit. For example, the 'main.o' from 'main.cpp'.
Linker combines object files into executable.

However, it is possible to pack (some) object files into "library file" and give that to linker (in addition to other object files).
There are two library file formats: archive and shared object. They are packed a bit differently.
The archive, .a, is simple concatenation. The shared object, .so, is used with dynamic linking.

Since libraries are not simply object files, the linker has to be told to read then as libraries. The -l option does that.
When you give that -lblah, the linker looks for libblah.so and libblah.a. With -L option you can add additional paths, locations that linker will check for libraries.

The -Lsomewhere -lblah would be in the LIBS variable.


Neither stld1553.a nor stld1553drvapi_win32.a seem to use the "libname.a" naming convention.
The stld1553drvapi_win32.a seems to contain at least the SitalSDK.o.
actually i linked the .a files in application project settings:
properties-->c/c++ build-->settings-->arm v8 Linux g++ linker-->miscellaneous-->
other objects--> here i put stld1553.a and stld1553drvapi_win32.a

so i think it is equivalent to -l option. or does it?
It's a link error.

None of the libs you've specified (stld1553.a, stld1553drvapi_win32.a) contain the function:
 
Sital_GetDeviceMemSize(void*, unsigned int*)


You could search for that function, and check that the file it's in is compiled and added to one of the libraries.

I realize you may be new to C/C++, but we've all had this baptism of fire. Just take it one step at a time.

[EDIT]
You check by:
1. search your source for that function implementation
2. touch the file and run make. Touch updates the timestamp of the file, and make will recompile it.
3. ensure the file is recompiled and added to a static lib, make note of the name.
4. we expect the library name will be one of the ones listed above.
5. ensure there is only one copy of this library on your system, or you'll never be quite sure which one it's using.
Last edited on
actually i linked the .a files in application project settings:
properties-->c/c++ build-->settings-->arm v8 Linux g++ linker-->miscellaneous-->
other objects--> here i put stld1553.a and stld1553drvapi_win32.a

In other words you do have IDE, where you make choices and the IDE generates Makefile for you.
That is good; the syntax of Makefile should be correct (unlike in manually written ones).
The problem is thus in the choices you have done -- in the content you told IDE to put into Makefile.


On x86_64 Linux:
man pthread_create wrote:
NAME
pthread_create - create a new thread

SYNOPSIS
#include <pthread.h>

int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg);

Compile and link with -pthread.

Whether the -pthread is correct option for your ARM compiler suite or how IDE is told to use it ... no idea.
Hi guys! thanks so far.

i have adopted some of the techniques you suggested.

now something strange happened.
when i build each library separately it worked and produce .a file.

i put .a files into debug folder in application project.

after i build app. project some errors appears on the libraries code.
this is what on the console:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
17:49:30 **** Incremental Build of configuration Debug for project CodeSample ****
make all 
'Building target: CodeSample.elf'
'Invoking: ARM v8 Linux g++ linker'
aarch64-linux-gnu-g++  -o "CodeSample.elf"  ./src/main.o  stld1553.a stld1553drvapi_win32.a 
stld1553.a(InterProcessSemaphore.o): In function `InterProcessSemaphore::Create()':
C:\SitalProjects\Linux_PCIe_Project\demo1\1553\Debug/../src/InterProcessSemaphore.cpp:91: undefined reference to `sem_open'
stld1553.a(InterProcessSemaphore.o): In function `InterProcessSemaphore::Open()':
C:\SitalProjects\Linux_PCIe_Project\demo1\1553\Debug/../src/InterProcessSemaphore.cpp:133: undefined reference to `sem_open'
stld1553.a(InterProcessSemaphore.o): In function `InterProcessSemaphore::Catch(unsigned int)':
C:\SitalProjects\Linux_PCIe_Project\demo1\1553\Debug/../src/InterProcessSemaphore.cpp:185: undefined reference to `sem_trywait'
C:\SitalProjects\Linux_PCIe_Project\demo1\1553\Debug/../src/InterProcessSemaphore.cpp:199: undefined reference to `sem_trywait'
stld1553.a(InterProcessSemaphore.o): In function `InterProcessSemaphore::Release()':
C:\SitalProjects\Linux_PCIe_Project\demo1\1553\Debug/../src/InterProcessSemaphore.cpp:229: undefined reference to `sem_post'
stld1553.a(InterProcessSemaphore.o): In function `InterProcessSemaphore::Close()':
C:\SitalProjects\Linux_PCIe_Project\demo1\1553\Debug/../src/InterProcessSemaphore.cpp:262: undefined reference to `sem_close'
C:\SitalProjects\Linux_PCIe_Project\demo1\1553\Debug/../src/InterProcessSemaphore.cpp:269: undefined reference to `sem_unlink'
stld1553drvapi_win32.a(SitalSDK.o): In function `_startInterruptPoll()':
C:\SitalProjects\Linux_PCIe_Project\demo1\API\Debug/../src/SitalSDK.cpp:2518: undefined reference to `pthread_create'
collect2.exe: error: ld returned 1 exit status
make: *** [makefile:50: CodeSample.elf] Error 1

17:49:30 Build Finished (took 508ms)


but 'undefined reference' is actually referenced when i clicked cntl+function !?
You have code of InterProcessSemaphore::Create()? It does contain sem_open, does it? What is sem_open?


Look at this small program:
1
2
3
4
5
6
7
8
#include <iostream>

int func( int x );

int main() {
  int answer = 42;
  std::cout << func( answer );
}

The linker will report undefined rereference to 'func(int)' on line 7, won't it?
Last edited on
"undefined reference to <some symbol>" most likely means that you are using that symbol (e.g. function, class or global variable) in your code, but you did not link the library where it is actually implemented!

Just because the declaration is available at compile-time, probably in a header file that you #include'd, does not mean that the implementation is available at link-time! You have to link the corresponding library file ;-)
Last edited on
Topic archived. No new replies allowed.