linux下使用动态库
程序员文章站
2022-06-04 13:06:45
...
Makefile
ARGET = usbcan_tool
CC ?= gcc
CFLAGS ?= -Wall -g
CXX ?= g++
CXXFLAGS ?= -Wall -g
COBJS = \
./main.o \
./usbcan.o
CPPOBJS =
OBJS = $(COBJS) $(CPPOBJS)
LIBS = -lpthread -L./lib -lcontrolcan
INCLUDES = -L./include
$(TARGET): $(OBJS)
$(CXX) $(CXXFLAGS) $(LDFLAGS) $^ $(LIBS) -o $(TARGET)
$(COBJS): %.o: %.c
$(CC) $(CFLAGS) -c $(INCLUDES) $< -o [email protected]
$(CPPOBJS): %.o: %.cpp
$(CXX) $(CXXFLAGS) -c $(INCLUDES) $< -o [email protected]
clean:
rm -rf $(OBJS) *.o $(TARGET) *log
.PHONY: clean
看目录结果
drwx------ 2 flinn flinn 4096 4月 2 13:25 include
drwx------ 2 flinn flinn 4096 4月 2 13:25 lib
-rw------- 1 flinn flinn 432 4月 2 13:25 main.c
-rw------- 1 flinn flinn 514 4月 2 13:25 Makefile
drwx------ 2 flinn flinn 4096 4月 2 13:25 si
-rw------- 1 flinn flinn 2513 4月 2 13:25 usbcan.c
在lib目录下有动态链接库libcontrolcan.so
最后需要制定动态链接库的地址,否则提示错误
LD_LIBRARY_PATH=/home/flinn/usbcan_tool/lib
export LD_LIBRARY_PATH
USBCAN需要root权限才能访问底层usb驱动, 需要新建一个规则:
sudo vim /etc/udev/rules.d/99-myusb.rules
##
ACTION=="add",SUBSYSTEMS=="usb", ATTRS{idVendor}=="04d8", ATTRS{idProduct}=="0053",
GROUP="users", MODE="0777"
上一篇: 关于数据库的外键和主键
推荐阅读