交叉编译 进入到源码目录,执行 ./configure ac_cv_func_malloc_0_nonnull=yes --host=aarch64-none-linux-gnu --enable-static --prefix=/home/feng/文档/development/Linux/application/OK527N/libmodbus-3.1.10/install/其中--host为交叉编译器的前缀;--prefix为编译结果的目录,需要为绝对路径。之后执行 makemake install编译成功后,就会在install目录下生成三个目录:include、lib、share。我们需要将lib目录移动到开发版的lib目录下 scp -r ./install/lib/ root@192.168.33.4:/移植测试程序我们这里以random-test-server和random-test-client为例进行测试,其中开发板为server,电脑为client。 开发板首先进入tests目录下,将random-test-server.c测试程序里面的ctx=modbus_new_tcp("127.0.0.1", 1502);
改为 ctx = modbus_new_tcp(NULL, 1502);,即 server 监控所有的 ip 地址,端口是 1502。之后重新执行交叉编译 aarch64-none-linux-gnu-gcc -o random-test-server random-test-server.c -L/home/feng/文档/development/Linux/application/OK527N/libmodbus-3.1.10/install/lib -lmodbus -I/home/feng/文档/development/Linux/application/OK527N/libmodbus-3.1.10/install/include/modbus将得到的random-test-server文件复制到开发板上 scp -r ./tests/random-test-server root@192.168.33.4:/home在开发板上执行程序 chmod 777 random-test-server./random-test-server电脑端编译./configuremakesudo make install修改测试文件首先进入tests目录下,将random-test-client.c测试程序里面的ctx = modbus_new_tcp("127.0.0.1", 1502); 改为 ctx = modbus_new_tcp("192.168.33.4", 1502);,即将服务端的ip地址改为开发板的ip地址,端口是 1502。重新执行make编译 测试首先在开发板上执行./random-test-server启动服务端程序,之后在电脑客户端执行./random-test-client,运行结果如下:
![](https://bbs.aw-ol.com/assets/uploads/files/1720877644823-65ccbe72-63ad-45d4-9eb8-e1b2248e19f2.png)
|