![使用 i2c-dev lib 构建 C++ 程序](https://linux22.com/image/951416/%E4%BD%BF%E7%94%A8%20i2c-dev%20lib%20%E6%9E%84%E5%BB%BA%20C%2B%2B%20%E7%A8%8B%E5%BA%8F.png)
我一直在尝试使用 Ubuntu Core 22.04.02 LTS 上的库构建 C++ 程序i2c-dev.h
,以便可以读取和写入 I2C 数据包。但我无法正确构建我的程序。我尝试在程序中包含路径,makefile
但编译器返回错误,似乎是因为编译了一些 Linux 头文件本身。
这是我现在的 makefile:
CC = g++
CFLAGS = -Wall
ALL_LIBS = -lrt -lstdc++ -std=c++11 -pthread -L/opt/picoscope/lib -lps4000a -libi2c
INCLUDES = -I/opt/picoscope/include/libps4000a -I/usr/src/linux-headers-5.15.0-67-generic/include -I/usr/src/linux-headers-5.15.0-67-generic/arch/x86/include/generated
ALL_TARGET = verde
all: $(ALL_TARGET)
$(ALL_TARGET): verde.cpp verde.h
$(CC) -o $(ALL_TARGET) verde.cpp $(CFLAGS) $(ALL_LIBS) $(INCLUDES)
clean:
rm -f *.o
rm -f $(ALL_TARGET)
rm -f *.bin
rm -f *.csv
rm -f *.txt
sudo rm -rf CPU*
sudo rm -rf RF*
这是运行 make 时的最新错误消息:
In file included from /usr/include/linux/posix_types.h:5,
from /usr/src/linux-headers-5.15.0-1032-realtime/include/uapi/linux/types.h:14,
from /usr/src/linux-headers-5.15.0-1032-realtime/include/linux/types.h:6,
from /usr/src/linux-headers-5.15.0-1032-realtime/include/uapi/linux/i2c-dev.h:12,
from /usr/src/linux-headers-5.15.0-1032-realtime/include/linux/i2c-dev.h:12,
from verde.h:54,
from verde.cpp:28:
verde.cpp: In function ‘void loggingSwitchDetect()’:
verde.cpp:929:36: error: invalid conversion from ‘void*’ to ‘char**’ [-fpermissive]
929 | dioValInt = strtol(dioVal, NULL, 16);
| ^~~~
| |
| void*
In file included from /usr/include/c++/11/cstdlib:75,
from verde.h:33,
from verde.cpp:28:
/usr/include/stdlib.h:178:43: note: initializing argument 2 of ‘long int strtol(const char*, char**, int)’
178 | char **__restrict __endptr, int __base)
| ~~~~~~~~~~~~~~~~~~^~~~~~~~