UC/OS在VC++6.0环境下的运行

      最近在学习嵌入式操作系统UC/OS II,参考的书是卢有亮编写的《嵌入式实时操作系统 UC/OS 原理与实践》,之前看邵贝贝的书上UC/OS的运行环境是Borland C++,由于对VC++6.0环境比较熟悉,所以这次打算在VC++6.0环境下进行UCOS的学习。我先在网上下载到了<书配套实验代码含UCOSV291>这个文件夹,里面有卢老师做的一个VC++工程,打开之后编译运行都一路OK。。于是我想自己建立一个工程,从头到尾熟悉一下这个过程,但是没想到本以为很简单的事情,结果却遇到了很大的麻烦,首先是编译出现了13个错误,错误都是说无法包含头文件,最终我花了很长时间找到了解决方法,那就是在TOOLS--Options--Directories,加入头文件所在的路径。如下图所示:winmm.lib 




这时候再次编译,会提示如下错误:

Linking...
main.obj : error LNK2001: unresolved external symbol __imp__timeSetEvent@20
Debug/UCOS.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
UCOS.exe - 2 error(s), 0 warning(s)

解决这个问题的方法有两种:

1.在includes.h文件的开头添加:#pragma comment(lib,"winmm.lib") 这句话的意思是:#pragma 是一条编译器指令,是给告诉编译器你要链接一些东西,然后在后面的comment里面指明是什么东西

2.Project -> Setting 选择 Link 标签

找到 Object/Library Modules 然后输入 winmm.lib就可以了。



总结一下:

以前经常遇到无法正确包含头文件的问题,另外一直没太弄明白 #include<file> and#include “file”的区别,现在终于弄清楚了,下面摘自于一个英文网站:

What is the difference between #include<file> and #include “file”?

When writing your C program, you can includefiles in two ways. The first way is to surround the file you want to includewith the angled brackets < and >. This method of inclusion tells thepreprocessor to look for the file in the predefined default location. Thispredefined default location is often an INCLUDE environment variable thatdenotes the path to your include files. For instance, given the INCLUDEvariable INCLUDE=C:COMPILERINCLUDE;S:SOURCEHEADERS; using the #include versionof file inclusion, the compiler first checks the C:COMPILERINCLUDE directoryfor the specified file. If the file is not found there, the compiler thenchecks the S:SOURCEHEADERS directory. If the file is still not found, the preprocessor checks the current directory(个人觉得这个说的不对,应该不会再回来搜索了).. The second way to include files isto surround the file you want to include with double quotation marks. This method of inclusion tells the preprocessor to look for the file in the currentdirectory first, then look for it in the predefined locations you have set up.Using the #include file version of file inclusion and applying it to thepreceding example, the preprocessor first checks the current directory for thespecified file. If the file is not found in the current directory, theC:COMPILERINCLUDE directory is searched. If the file is still not found, thepreprocessor checks the S:SOURCEHEADERS directory. The #include method of fileinclusion is often used to include standard headers such as stdio.h orstdlib.h. This is because these headers are rarely (if ever) modified, and theyshould always be read from your compilers standard include file directory. The#include file method of file inclusion is often used to include nonstandard headerfiles that you have created for use in your program. This is because theseheaders are often modified in the current directory, and you will want thepreprocessor to use your newly modified version of the header rather than theolder, unmodified version. 




总的来说:

当用#include“file.h”时,先搜索当前工作目录,如果没有,再去系统目录(预先定义好的路径)

当用#include<file.h>时   直接搜索系统目录(预先定义好的路径)


  刚开始一直报错说没找到头文件,就是因为程序中有许多#include<file.h> ,而在软件中没有设置

路径,导致找不到那些头文件。

   TOOLS--Options--Directories的原来的D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE就是本来的系统目录,比如通常用的#include<stdio.h>就是在这个目录中寻找的。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值