Skip to content

Commit 3ed723e

Browse files
author
Alex Mous
committed
Patch to issue with linking error to i2c library as well as cleanup Makefile
1 parent b80e611 commit 3ed723e

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

MPU6050.cpp

-11
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,6 @@
22
//Copyright (c) 2019, Alex Mous
33
//Licensed under the CC BY-NC SA 4.0
44

5-
//Includes
6-
#include <iostream>
7-
#include <unistd.h>
8-
#include <fcntl.h>
9-
#include <sys/ioctl.h>
10-
#include <sys/types.h>
11-
#include <time.h>
12-
#include <linux/i2c-dev.h>
13-
#include <cmath>
14-
#include <thread>
15-
165
//Include the header file for this class
176
#include "MPU6050.h"
187

MPU6050.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@
4141
#include <sys/ioctl.h>
4242
#include <sys/types.h>
4343
#include <time.h>
44-
#include <linux/i2c-dev.h>
45-
#include <i2c/smbus.h>
44+
extern "C" {
45+
#include <linux/i2c-dev.h>
46+
#include <i2c/smbus.h>
47+
}
4648
#include <cmath>
4749
#include <thread>
4850

Makefile

+30-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
1-
all: MPU6050.cpp
2-
g++ -fPIC -c MPU6050.cpp -o MPU6050.o
3-
g++ -shared -o libMPU6050.so MPU6050.o
4-
install -m 755 -p libMPU6050.so /usr/lib/
5-
install -m 644 -p MPU6050.h /usr/include/
6-
rm -f MPU6050.o
7-
rm -f libMPU6050.so
1+
CC=g++
82

9-
clean:
3+
DEPS=MPU6050.h
4+
CFLAGS=-fPIC -Wall
5+
6+
LIBS=-li2c
7+
LFLAGS=-shared
8+
9+
OBJ=MPU6050.o
10+
OLIB=libMPU6050.so
11+
12+
13+
14+
%.o: %.cpp $(DEPS)
15+
$(CC) -c $< -o $@ $(CFLAGS)
16+
17+
all: $(OBJ)
18+
$(CC) -o $(OLIB) $< $(LIBS) $(LFLAGS)
19+
20+
install: all $(OLIB) $(DEPS)
21+
install -m 755 -p $(OLIB) /usr/lib/
22+
install -m 644 -p $(DEPS) /usr/include/
23+
24+
uninstall:
1025
rm -f /usr/include/MPU6050.h
1126
rm -f /usr/lib/libMPU6050.so
27+
28+
clean:
1229
rm -f Example
30+
rm -f Example.o
31+
rm -f MPU6050.o
32+
rm -f libMPU6050.so
1333

14-
example:
15-
g++ Example.cpp -o Example -lMPU6050 -pthread
16-
./Example
34+
example: Example.o
35+
$(CC) $< -o Example -lMPU6050 -pthread

0 commit comments

Comments
 (0)