如何将 .c 和 .h 文件添加到 Atmel Studio 6? [英] How to add .c and .h files to Atmel Studio 6?

查看:27
本文介绍了如何将 .c 和 .h 文件添加到 Atmel Studio 6?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多关于这个主题的问题,并且我已经查看了相当多的问题.但是我仍然遇到问题.

I know there are a lot of questions on this topic, and I've looked through a fair number of them. However I am still having problems.

我开始为原型 PCB 编写一个测试程序,现在它已经增长到近 1000 行,我正试图将其分解为可用于特定功能的库.

I started writing a test program for a prototype PCB, and now that it's grown to nearly 1000 lines I'm trying to break it up into libraries that I can use for particular functions.

我认为这将非常简单.为我需要的每个库制作 .c 和 .h 文件.IE.对于控制 OLED 显示器的功能,我会使用 OLED.h 和 OLED.c.将适当的函数/定义复制到每个文件中.然后将这些文件复制到 Atmel Studio 中的解决方案中.我将它们放入项目名称下的 src 文件夹中.

I thought this would be very simple. Make .c and .h files for each library that I need. I.e. I would have OLED.h and OLED.c for functions that control an OLED display. Copy the appropriate functions/definitions into each file. Then copy these files into the solution in Atmel Studio. I put them into the src folder under the project name.

但是,这不起作用!我得到一个非常长的错误列表.就编译器而言,.h 文件中定义的所有内容显然都是未定义的.我还收到许多类型为未知类型名称 int16_t/uint16_t/uint8_t/etc..."的错误消息,这让我很困惑.为什么函数在外部库中很重要,现在编译器不理解这些数据类型的含义?

However, this doesn't work! I get an exceedingly long list of errors. All of the things that are defined in the .h file are apparently undefined as far as the compiler is concerned. I also get many error messages of the type "unknown type name int16_t/uint16_t/uint8_t/etc..." That part is really baffling to me. Why should it matter that functions are in an external library, now the compiler doesn't understand what those data types mean?

所以,这可能是一个愚蠢的问题.我不希望 Atmel Studio 通过将它们包装在一些库项目"或其他东西中来控制我的库,我想将它们放在我选择的文件夹中,并在需要时添加它们.我已经搜索了这个问题的答案,并且找到了有关更改项目的编译器设置、链接器设置等的长教程……我尝试了本教程,但仍然没有骰子:http://www.engblaze.com/tutorial-using-avr-studio-5-with-arduino-projects/#setup

So, this is probably a stupid problem to have. I don't want Atmel Studio to control my libraries by wrapping them up in some "library project" or somethig, I want to put them in a folder of my choosing and add them when I need them. I've searched for answers to this problem and I find long tutorials about changing the compiler settings for the project, the linker settings, etc... I tried this tutorial and still no dice: http://www.engblaze.com/tutorial-using-avr-studio-5-with-arduino-projects/#setup

我也找不到通过右键单击项目并单击添加"来添加内容的方法.它要我找到 .a 文件.Atmel Studio 中的添加库"对话框看起来很糟糕.

I also can't find a way to add something by right clicking the project and clicking "Add." It wants me to find .a files. The "Add Library" dialog box in Atmel Studio is awful, it seems.

只是将库添加到现有项目并使其正常运行肯定不会那么复杂吗?!我过去使用过 PIC,来到 Atmel 时,我发现了可怕的文档和一个奇怪的超级光滑的超级飞天高手爆炸界面,它不能很好地单独留下,并且混淆了简单的功能.我可以做些什么来添加这些库?

Surely it can't be that convoluted to just add a library to an existing project and have it function normally?! I've used PICs in the past and coming to Atmel I've found horrible documentation and a weird super-slick super-fly whizz bang interface that can't leave well enough alone and obfuscates simple function. What can I do to add these libraries?

更新:似乎回答了我自己的问题.结果我需要将所有的库都包含在 .c 文件中以识别数据类型和诸如此类的东西.我不知何故认为这只需要在主文件中完成,但显然我错了.添加 asf.h 似乎效果很好,因为它包含所有 MCU 特定的端口定义/名称以及所有这些.目前一切顺利!

UPDATE: Seemed to answer my own question. Turns out I needed to include all of the libraries to recognize data types and whatnot into the .c file. I somehow assumed this only had to be done in the main file but obviously I was mistaken. Adding asf.h seems to work well as it includes all of the MCU specific port definitions/names and all of that. All good for now!

推荐答案

将库文件添加到解决方案应该很简单.转到解决方案资源管理器,右键单击您的解决方案,然后转到添加->现有项目".如果要添加预先存在的库并将其保存在与解决方案不同的文件夹中,请单击添加"旁边的箭头并选择添加为链接".由于解决方案文件夹中存在库的重复副本,并且文件无法保持最新​​,因此这可以省去很多麻烦.

Adding library files to a solution should be simple. Go to the Solution Explorer, right-click on your solution, and go to "Add->Existing Item". If you want to add a pre-existing library and keep it in a separate folder from your solution, click the arrow next to "Add" and choose "Add as link". That saves many headaches due to having a duplicate copy of your library in your solution folder, and files not staying up-to-date.

这篇关于如何将 .c 和 .h 文件添加到 Atmel Studio 6?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆