Keil5.15 using the GCC compiler link. A library file

Source: Internet
Author: User

我们知道,当使用第三方的代码时,人家有可能会扔个Lib文件给你.这时候,别人只要提供header文件给你,则你就可以通过Lib文件及header的函数声明,对Lib中的函数进行调用.在Keil中如果使用ARMCC调用Lib文件,相信大家都能从网上找到方法.那如果在Keil中使用GCC来链接第三方GCC编译好的Lib文件——".a"应该如何呢?在告诉大家方法之前,我们写个简单的函数,然后用GCC编译器编译产生.a文件,便于我们进行测试.首先,在Keil中配置gcc编译环境,这个可以参考我的文章.

KEIL5.15 uses the GCC compiler to compile the STM32 project, in which there is a way to make a configuration.
Next, you configure the project to generate a library. This is like the way Keil ARMCC.

Finally, write your own test code.
NIIPLIB.C file code for the library file:

int NiipLib_GetValue(unsignedchar* pBuffer,int nSize){    int0;    for0;nIndex <nSize;nIndex++)    {            pBuffer[nIndex] = nIndex;    }    return nIndex;}

NiipLib.h file code for the library file:

#ifdef __cplusplus"C" {#endifintchar* pBuffer,int#ifdef __cplusplus}#endif
点击编译,我们可以在编译输出目录下得到"libNiipLib.a"文件.接着,我们就要在另外个工程引用这个库文件了.将"libNiipLib.a"文件与"NiipLib.h"拷贝到自己新建的或者已存在的项目下面.下面图片的重点来了,请大家留意一下,开始"找不同"或者"大家来找茬".

细心的人,会发现为什么我"Include Libraries"这个地方,为什么填写的是"NiipLib"为什么不是"libNiipLib.a"?其实,我开始也填写"libNiipLib.a",但编译器老提示无法找到"libNiipLib.a"这个文件.我真的想说FUCK.在网上搜索了一下,发现GCC有个变态的情况,叫做"隐式约定命名规则".什么叫做"隐式约定命名规则"?用别人的解释

-ltest means to link the dynamic library libtest.a file, which is the GCC implicit convention naming rules, that is, the library name with the LIB header, such as LIBTEST.A, and on the link parameters do not take, such as-ltest means to link libtest.a

而我的理解就是,你要调用什么.a文件,你只需去掉文件名前缀的"lib"及后缀的".a",就可以了。测试结果:

From: http://blog.csdn.net/lan120576664

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Keil5.15 using the GCC compiler link. A library file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.