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

查看:718
本文介绍了如何将.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文件。即对于控制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我发现了可怕的文档和一个奇怪的超级光滑的超级飞行whiz爆炸界面,不能单独留下足够的混淆和混淆简单的功能。我该怎么做才能添加这些库?

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天全站免登陆