- UID
- 1029342
- 性别
- 男
|
广州天嵌科技公司的TQ3358开发板支持CAN通信功能,而且最近很多朋友也有提到关于CAN测试程序 canutils 源码的编译的问题。现放出canutils 的源码和编译教程,以方便大家测试使用。
[hide] 1.首先编译libsocketcan
从终端进入libsocketcan源码目录,输入命令
CC=arm-linux-gcc ./configure --prefix=<安装路径>(需绝对路径) --host=arm-linux --build=i386
make
make install
编译成功,在 <安装路径>/lib/pkgconfig/下有个libsocketcan.pc文件,将其拷贝到PC的/usr/lib/pkgconfig/目录下。
2.编译canutils-4.0.6
先确认系统已安装automake
apt-get install automake
配置
./configure --host=arm-linux --prefix=<安装目录> --enable-debug
(如出现
config.status: executing libtool commands
sed: can't read config/autoconf/ltmain.sh: No such file or directory
sed: can't read libtoolT: No such file or directory
则apt-get install libtool 安装
然后执行
终端输入命令:autoreconf
再重新
./configure --host=arm-linux --prefix=<安装目录> --enable-debug
)
在canutils-4.0.6源码中的src/GNUmakefile.in 中的
CFLAGS = @CFLAGS@ (大概在96/97行)改为
CFLAGS = -Wall -g -O2
make
1)错误1:
cc1: warnings being treated as errors
candump.c: In function 'main':
candump.c:190: error: ignoring return value of 'daemon', declared with attribute warn_unused_result
make[1]: *** [candump.o] 错误 1
解决方法:
根据错误提示,是candump.c 忽略了返回值。所以在
打开源码src/candump.c文件,找到190行,将
daemon(1, 0);
改为:
{
int ret =0 ;
ret = daemon(1,0);
}
保存退出,重新make。
2)错误2:
/bin/bash ../libtool --tag=CC --mode=link arm-linux-gcc -Wall -g -O2 -o candump candump.o
libtool: Version mismatch error. This is libtool 2.4.2 Debian-2.4.2-1ubuntu1, but the
libtool: definition of this LT_INIT comes from libtool 2.4.
libtool: You should recreate aclocal.m4 with macros from libtool 2.4.2 Debian-2.4.2-1ubuntu1
libtool: and run autoconf again.
make[1]: *** [candump] 错误 63
解决方法:
终端中执行命令:rm aclocal.m4 & aclocal & autoconf
然后执行:rpmbuild -bb *.spec
重新 make
3)错误3:
canecho.c: In function 'main':
canecho.c:163: error: ignoring return value of 'write', declared with attribute warn_unused_result
make[1]: *** [canecho.o] 错误 1
解决方法:
将src/canecho.c的第163行:
write(s[out], &frame, sizeof(frame));
改为:
int ret;
ret = write(s[out], &frame, sizeof(frame));
重新make。 |
|