mindbeast / rpi-mpu6050

Simple C code for raspberry pi to read gyro, accelerometer, and temperature data from a mpu-6050 sensor.
9 stars 12 forks source link

How do I compile #2

Open cherbin opened 4 years ago

cherbin commented 4 years ago

I'm getting the folllowing errors

make gcc -g rpi-mpu6050.c -o rpi-mpu6050 rpi-mpu6050.c: In function ‘main’: rpi-mpu6050.c:46:20: warning: implicit declaration of function ‘i2c_smbus_read_byte_data’ [-Wimplicit-function-declaration] int8_t power = i2c_smbus_read_byte_data(fd, MPU_POWER1); ^~~~~~~~ rpi-mpu6050.c:47:5: warning: implicit declaration of function ‘i2c_smbus_write_byte_data’ [-Wimplicit-function-declaration] i2c_smbus_write_byte_data(fd, MPU_POWER1, ~(1 << 6) & power); ^~~~~~~~~ rpi-mpu6050.c:70:9: warning: implicit declaration of function ‘sleep’ [-Wimplicit-function-declaration] sleep(1); ^~~~~ /usr/bin/ld: /tmp/ccKkAgbz.o: in function main': /opt/CANBUS/GYRO/C/rpi-mpu6050-master/rpi-mpu6050.c:46: undefined reference toi2c_smbus_read_byte_data' /usr/bin/ld: /opt/CANBUS/GYRO/C/rpi-mpu6050-master/rpi-mpu6050.c:47: undefined reference to i2c_smbus_write_byte_data' /usr/bin/ld: /opt/CANBUS/GYRO/C/rpi-mpu6050-master/rpi-mpu6050.c:50: undefined reference toi2c_smbus_read_byte_data' /usr/bin/ld: /opt/CANBUS/GYRO/C/rpi-mpu6050-master/rpi-mpu6050.c:51: undefined reference to i2c_smbus_read_byte_data' /usr/bin/ld: /opt/CANBUS/GYRO/C/rpi-mpu6050-master/rpi-mpu6050.c:53: undefined reference toi2c_smbus_read_byte_data' /usr/bin/ld: /opt/CANBUS/GYRO/C/rpi-mpu6050-master/rpi-mpu6050.c:54: undefined reference to i2c_smbus_read_byte_data' /usr/bin/ld: /opt/CANBUS/GYRO/C/rpi-mpu6050-master/rpi-mpu6050.c:55: undefined reference toi2c_smbus_read_byte_data' /usr/bin/ld: /tmp/ccKkAgbz.o:/opt/CANBUS/GYRO/C/rpi-mpu6050-master/rpi-mpu6050.c:56: more undefined references to `i2c_smbus_read_byte_data' follow collect2: error: ld returned 1 exit status make: *** [Makefile:3: rpi-mpu6050] Error 1

WA6YDQ commented 2 years ago

I know this is an old issue, but for future reference:

cc -o mpu rpi-mpu6050.c -li2c

The compile stage needs the i2c library.