交叉编译libmodbus


获取 libmodbus

从官网下载libmodbus

解压缩:

tar -zxvf libmodbus-3.1.6.tar.gz 

configure 选项

安装目录

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc.  You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.

System types:

--build=BUILD     configure for building on BUILD [guessed]
--host=HOST       cross-compile to build programs to run on HOST [BUILD]

编译

新建存放目录

mkdir libmodbus_arm

配置编译选项

./configure --host=arm-linux-gnueabihf --prefix=/home/book/libmodbus_cp/libmodbus_arm

编译

make & make install

在开发板安装

挂载 nfs

mount -o vers=4 192.168.10.173:/home/book /home/workdir

拷贝动态链接库到usr/lib

cp libmodbus.so* /usr/lib

查看/usr/lib

ls | grep "libmodbus"

测试

tests复制一个测试代码,修改IP地址

在主机上使用 gcc 编译并运行server

使用arm-linux-gnueabihf-gcc编译client

arm-linux-gnueabihf-gcc unit-test-client.c -o test -I /home/book/libmodbus_cp/libmodbus_arm/include/modbus  -L /home/book/libmodbus_cp/libmodbus_arm/lib -lmodbus

同时运行:

  • 分享:
评论
还没有评论
    发表评论 说点什么