当前位置: 首页 > news >正文

在MCUXpresso IDE中建立使用静态库的工程

文章目录

    • 在MCUXpresso IDE中建立使用静态库的工程
    • 概述
    • 笔记
    • 将工作区清空
    • 建立库工程
    • 建立主工程
    • 验证
    • END

在MCUXpresso IDE中建立使用静态库的工程

概述

在做Smoothieware工程移植到MCUXpresso IDE的任务。
查看编译日志,发现Smoothieware分为2个工程,一个主工程lpc1768, 一个静态库工程mbed-lpc1768.
我前面实验,是将所有代码都在一个工程中编译,编译出来的elf在MCU中装不下。当然原因很多。
但是我想严格按照Smoothieware的做法来,也将工程分为2个工程,一个主工程a,一个库工程b.
先编译b, 再编译a(a中链接b, 并使用b的接口)。

做了一个实验,验证了建立这种2个工程的例子,确实可以。

笔记

将工作区清空

在这里插入图片描述
在这里插入图片描述
头2个文件夹是工作区用的,不能删
后面3个logs文件夹是硬件调试器的单步调试连接日志,是自动产生的,不用删(删了也会再产生)。

建立库工程

新建c++工程
在这里插入图片描述
MCU选1769
在这里插入图片描述
选c++静态库工程
在这里插入图片描述
给定静态库工程名称
在这里插入图片描述
不要选LpcOpen库和CMSIS库
在这里插入图片描述

在这里插入图片描述
语言标准选2011,除了src目录,不需要建立inc目录
在这里插入图片描述
新建inc目录
在这里插入图片描述
在这里插入图片描述
在inc目录中新建c++的.h文件
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
同理,在src目录中建立实现文件my_lib.cpp
将工程根目录加入工程的包含路径。
在这里插入图片描述
填写my_lib.h内容如下

// @file my_lib.h
// @brief only test static library's interface#ifndef __MY_LIB_H__
#define __MY_LIB_H__int add(int x, int y);#endif // #ifndef __MY_LIB_H__

填写my_lib.cpp内容如下

// @file my_lib.cpp#include "inc/my_lib.h"int add(int x, int y)
{return  (x + y);
}

编译通过。

17:53:44 **** Incremental Build of configuration Debug for project my_lib ****
make -r -j16 all 
make[1]: Nothing to be done for 'main-build'.
Performing post-build steps
arm-none-eabi-size "libmy_lib.a" ; # arm-none-eabi-objdump -h -S "libmy_lib.a" >"libmy_lib.lss"text	   data	    bss	    dec	    hex	filename26	      0	      0	     26	     1a	my_lib.o (ex libmy_lib.a)17:53:45 Build Finished. 0 errors, 0 warnings. (took 475ms)

建立主工程

在同一个工作区中,再建立主工程。
以下是不同的地方,相同的地方请参考静态库工程的建立。
选c++工程
在这里插入图片描述
在这里插入图片描述
不选crp
在这里插入图片描述
在主工程的my_main.cpp中加入库函数调用。

/** Copyright 2022 NXP* NXP confidential.* This software is owned or controlled by NXP and may only be used strictly* in accordance with the applicable license terms.  By expressly accepting* such terms or by downloading, installing, activating and/or otherwise using* the software, you are agreeing that you have read, and that you agree to* comply with and are bound by, such license terms.  If you do not agree to* be bound by the applicable license terms, then you may not retain, install,* activate or otherwise use the software.*/#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif#include <cr_section_macros.h>// TODO: insert other include files here
#include "my_lib.h"// TODO: insert other definitions and declarations hereint main(void) {// TODO: insert code hereint z = add(3, 5);// Force the counter to be placed into memoryvolatile static int i = z ;// Enter an infinite loop, just incrementing a counterwhile(1) {i++ ;// "Dummy" NOP to allow source level single// stepping of tight while() loop__asm volatile ("nop");}return 0 ;
}

设置头文件路径
在这里插入图片描述
增加要链接的库名称和库搜索路径
在这里插入图片描述
编译通过

Finished building: ../src/cr_cpp_config.cppFinished building: ../src/cr_startup_lpc175x_6x.cppFinished building: ../src/crp.cFinished building: ../src/my_main.cppBuilding target: my_main.axf
Invoking: MCU C++ Linker
arm-none-eabi-c++ -nostdlib -L"D:\my_tmp\nxp_dev\ws\my_lib\Debug" -Xlinker -Map="my_main.map" -Xlinker --cref -Xlinker --gc-sections -Xlinker -print-memory-usage -mcpu=cortex-m3 -mthumb -T "my_main_Debug.ld" -o "my_main.axf" ./src/cr_cpp_config.o ./src/cr_startup_lpc175x_6x.o ./src/crp.o ./src/my_main.o    -lmy_lib
Memory region         Used Size  Region Size  %age UsedMFlash512:       16048 B       512 KB      3.06%RamLoc32:        1828 B        32 KB      5.58%RamAHB32:           0 B        32 KB      0.00%
Finished building target: my_main.axfPerforming post-build steps
arm-none-eabi-size "my_main.axf"; # arm-none-eabi-objcopy -v -O binary "my_main.axf" "my_main.bin" ; # checksum -p LPC1769 -d "my_main.bin";text	   data	    bss	    dec	    hex	filename14668	   1380	    444	  16492	   406c	my_main.axf18:08:44 Build Finished. 0 errors, 0 warnings. (took 2s.351ms)

验证

接上1769板子, 选SWD调试,可以单步调试,接口调用正确,且可以单步调试进入接口。

END

http://www.dtcms.com/a/414280.html

相关文章:

  • 【人工智能通识专栏】第二十八讲:IDE集成Deepseek
  • 电子商务网站建设参考书软文时光发稿平台
  • Flask与Django:Python Web框架的哲学对决
  • Android 消息循环机制
  • 若依前后端分离版集成到企业微信自建应用
  • 电商网站建设心得ps做网站首页怎么运用起来
  • 免费建一级域名网站精品网站设计
  • windows电脑如何执行openssl rand命令
  • 【MySQL✨】MySQL 入门之旅 · 第十一篇:常见错误排查与解决方案
  • Word表格数据提取工具
  • 【Rust GUI开发入门】编写一个本地音乐播放器(1. 主要技术选型架构设计)
  • Rust 中的 static 和 const
  • Linux操作系统-进程(一)
  • 零基础学AI大模型之LangChain六大核心模块与大模型IO交互链路
  • 20250927让荣品RD-RK3588-MID开发板的Android13系统在uboot下关闭背光充电
  • 人工智能专业知识图谱
  • 深入理解Windows服务:架构、管理与编程实践
  • 作风建设简报--门户网站如何提高网站百度权重
  • CentOS7搭建ELK日志分析系统
  • 基于大数据hive的银行信用卡用户的数仓系统的设计与实现_django
  • Docker从网络管理到容器优化
  • count down 83 days
  • 华为云速建站如何用网页设计制作个人网站
  • 做网站用什么压缩代码和图片如何做淘宝商城网站
  • 基于STM32与influxDB的电力监控系统-3
  • STM32 程序下载失败的问题原因和解决方法集合!
  • 【读论文】AI笔记(一)9月26日组会前
  • 逻辑的回归——一阶谓词逻辑及其变体在自然语言处理深层语义分析中的作用与前瞻
  • Java EE初阶启程记03---Thread类及常见方法
  • 医疗行业 AI 投毒攻击原理及防护研究