Frage

I' m trying to setup a simple tool to measure different aspects of a system. I build a project which can log an accelerometer, gyroscope and a magnetometer. I want full control of the the program so I decided not to use any usr/local kind of libraries and keep all files in the project folder. All files all working. I want to make the structure of my program as follows: https://www.dropbox.com/s/59s3si8spvkdq98/filestructure.png (not enough REP). I don't have much experience in making Makefiles, except changing a few variables. I work in the Embedded environment and mostly with IDE's.

I tried building my project with the following Makefile:

# Project name
NAME        = TEST

# Tools
CC          = gcc
CFLAGS      = -o     

# Paths
DRV_PATH    = drivers
SRC_PATH    = src
LIB_PATH    = libs

# includes
INCLUDES    = -I $(DRV_PATH) -I $(LIB_PATH) -I $(SRC_PATH)

# what files do we need to compile?
# libraries
MY_LIB      = $(LIB_PATH)/bcm2835.c 

# main files
MAIN        = main.c

# src files
#MY_SRC      = $(SRC_PATH)/vector.c
MY_SRC      += $(SRC_PATH)/dcm.c

# select drivers to compile
DRV_SRC      = $(DRV_PATH)/adxl345.c
DRV_SRC     += $(DRV_PATH)/itg3200.c
DRV_SRC     += $(DRV_PATH)/hmc5883l.c
DRV_SRC     += $(DRV_PATH)/gy-85.c
DRV_SRC     += $(DRV_PATH)/nrf24l01.c


# bundle files
ALL_SRC     = $(MY_LIB) $(DRV_SRC) $(MY_SRC) $(MAIN)

OBJ         = $(ALL:.c=.o)
BIN         = $(ALL:.c=)

# make commands
all:
        $(CC) $(CFLAGS) $(NAME) $(ALL_SRC) 

debug:  
        $(CC) $(CFLAGS) $(NAME) $(ALL_SRC) -DDEBUG=1 

imudebug:  
        $(CC) $(CFLAGS) $(NAME) $(ALL_SRC) -DIMUDEBUG=1 

nrfdebug:  
        $(CC) $(CFLAGS) $(NAME) $(ALL_SRC) -DNRFDEBUG=1 

I use the different make commands to generate some debug output. The config file currently includes all files and is as follows:

#ifndef CONFIG_H
#define CONFIG_H

/* includes */
#include <stdio.h>
#include <math.h>

/* libs */
#include <bcm2835.h>

/* drivers */
#include "gy-85.h"
#include "adxl345.h"
#include "itg3200.h"
#include "hmcl5883l.h"
#include "nrf24l01.h" 

/* src */
#include "dcm.h"

#endif // __CONFIG_H__

And the dcm.h file looks as follows. I tried t keep all .h files like this:

#ifndef DCM_H
#define DCM_H

#include <bcm2835.h>
#include <stdio.h>
#include <math.h>
#include "gy-85.h"

double pitch, roll, yaw;
double DCM_Matrix[3][3];
uint64_t stamp;

void resetFusion(void);

#endif

This is my make result:

gcc -o      TEST libs/bcm2835.c  drivers/adxl345.c drivers/itg3200.c drivers/hmc5883l.c drivers/gy-85.c drivers/nrf24l01.c src/dcm.c main.c
In file included from drivers/adxl345.c:1:0:
drivers/adxl345.h:4:21: fatal error: bcm2835.h: No such file or directory
compilation terminated.
In file included from drivers/itg3200.c:1:0:
drivers/itg3200.h:4:21: fatal error: bcm2835.h: No such file or directory
compilation terminated.
drivers/hmc5883l.c: In function ‘magInit’:
drivers/hmc5883l.c:7:30: error: ‘MAG_ADDR’ undeclared (first use in this function)
drivers/hmc5883l.c:7:30: note: each undeclared identifier is reported only once for each function it appears in
drivers/hmc5883l.c:14:17: error: ‘MODE’ undeclared (first use in this function)
drivers/hmc5883l.c:14:23: error: ‘CONTINUOUS’ undeclared (first use in this function)
drivers/hmc5883l.c:22:17: error: ‘CONA’ undeclared (first use in this function)
drivers/hmc5883l.c:22:23: error: ‘RATE_50HZ’ undeclared (first use in this function)
drivers/hmc5883l.c: In function ‘magRead’:
drivers/hmc5883l.c:37:30: error: ‘MAG_ADDR’ undeclared (first use in this function)
drivers/hmc5883l.c:38:18: error: ‘DATA’ undeclared (first use in this function)
drivers/hmc5883l.c: In function ‘magGetRegister’:
drivers/hmc5883l.c:60:13: error: ‘BCM2835_I2C_REASON_OK’ undeclared (first use in this function)
drivers/hmc5883l.c:61:3: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
drivers/hmc5883l.c: At top level:
drivers/hmc5883l.c:71:6: warning: conflicting types for ‘magGetRegisters’ [enabled by default]
drivers/hmc5883l.c:38:2: note: previous implicit declaration of ‘magGetRegisters’ was here
drivers/hmc5883l.c: In function ‘magGetRegisters’:
drivers/hmc5883l.c:79:13: error: ‘BCM2835_I2C_REASON_OK’ undeclared (first use in this function)
drivers/hmc5883l.c:80:3: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
drivers/hmc5883l.c: At top level:
drivers/hmc5883l.c:97:6: warning: conflicting types for ‘magSetRegister’ [enabled by default]
drivers/hmc5883l.c:14:2: note: previous implicit declaration of ‘magSetRegister’ was here
drivers/hmc5883l.c: In function ‘magSetRegister’:
drivers/hmc5883l.c:107:13: error: ‘BCM2835_I2C_REASON_OK’ undeclared (first use in this function)
drivers/hmc5883l.c:108:3: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
drivers/gy-85.c: In function ‘gyInit’:
drivers/gy-85.c:15:30: error: ‘BCM2835_I2C_CLOCK_DIVIDER_2500’ undeclared (first use in this function)
drivers/gy-85.c:15:30: note: each undeclared identifier is reported only once for each function it appears in
drivers/gy-85.c: In function ‘gyUpdate’:
drivers/gy-85.c:29:2: error: unknown type name ‘int16_t’
drivers/gy-85.c:30:2: error: unknown type name ‘uint8_t’
drivers/gy-85.c:32:9: error: ‘int16_t’ undeclared (first use in this function)
drivers/gy-85.c:32:18: error: expected expression before ‘)’ token
drivers/gy-85.c:40:18: error: expected expression before ‘)’ token
drivers/gy-85.c:47:18: error: expected expression before ‘)’ token
drivers/gy-85.c:61:2: warning: return from incompatible pointer type [enabled by default]
In file included from drivers/nrf24l01.c:1:0:
drivers/nrf24l01.h:5:21: fatal error: bcm2835.h: No such file or directory
compilation terminated.
In file included from src/dcm.c:1:0:
src/dcm.h:4:21: fatal error: bcm2835.h: No such file or directory
compilation terminated.
In file included from main.c:1:0:
config.h:9:21: fatal error: bcm2835.h: No such file or directory
compilation terminated.
make: *** [all] Error 1

If you can point out the main problem with my file structure I would be so glad!

Current error list:

gcc -o  TEST -I libs -I drivers -I src libs/bcm2835.c  drivers/adxl345.c drivers/itg3200.c drivers/hmc5883l.c drivers/gy-85.c drivers/nrf24l01.c src/dcm.c main.c
drivers/gy-85.c: In function ‘gyUpdate’:
drivers/gy-85.c:63:2: warning: return from incompatible pointer type [enabled by default]
main.c: In function ‘main’:
main.c:51:4: warning: passing argument 1 of ‘nrf24Transmit’ from incompatible pointer type [enabled by default]
drivers/nrf24l01.h:145:9: note: expected ‘uint8_t *’ but argument is of type ‘uint64_t *’
/tmp/ccOWR401.o:(.bss+0x0): multiple definition of `accelRaw'
/tmp/cc1gy1Bh.o:(.bss+0x0): first defined here
/tmp/ccOWR401.o:(.bss+0x8): multiple definition of `accelBias'
/tmp/cc1gy1Bh.o:(.bss+0x8): first defined here
/tmp/ccyZlhJe.o:(.bss+0x0): multiple definition of `accelRaw'
/tmp/cc1gy1Bh.o:(.bss+0x0): first defined here
/tmp/ccyZlhJe.o:(.bss+0x8): multiple definition of `accelBias'
/tmp/cc1gy1Bh.o:(.bss+0x8): first defined here
/tmp/ccUbOIyA.o:(.bss+0x0): multiple definition of `accelRaw'
/tmp/cc1gy1Bh.o:(.bss+0x0): first defined here
/tmp/ccUbOIyA.o:(.bss+0x8): multiple definition of `accelBias'
/tmp/cc1gy1Bh.o:(.bss+0x8): first defined here
/tmp/ccyZlhJe.o: In function `resetFusion':
dcm.c:(.text+0x38): undefined reference to `atan2'
collect2: ld returned 1 exit status
make: *** [all] Error 1
War es hilfreich?

Lösung

You don't have your includes in your rule

INCLUDES    = -I $(DRV_PATH) -I $(LIB_PATH) -I $(SRC_PATH)

This just seems to dangle. Simplest solution to my eyes is to move down your CFLAGS definition and add in the includes:

INCLUDES    = -I $(DRV_PATH) -I $(LIB_PATH) -I $(SRC_PATH)
CFLAGS      = -o  $(INCLUDES) 

This way you don't have to change anything else. Of course, there are alternatives, this one just looks easiest.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top