C++ 无法打开包含文件:'atlbase.h':没有这样的文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16404092/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot open include file: 'atlbase.h': No such file or directory
提问by Lemon Juice
Please have a look at the following code
请看下面的代码
#define _ATL_APARTMENT_THREADED
#include <atlbase.h>
//You may derive a class from CComModule and use it if you want to override something,
//but do not change the name of _Module
extern CComModule _Module;
#include <atlcom.h>
#include <sapi.h>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
cout << "Hello" << endl;
ISpVoice * pVoice = NULL;
if (FAILED(::CoInitialize(NULL)))
return FALSE;
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
if( SUCCEEDED( hr ) )
{
cout << "Succeeded" << endl;
hr = pVoice->Speak(L"Hello world", 0, NULL);
pVoice->Release();
pVoice = NULL;
}
else
{
cout << "Not succeeded" << endl;
}
::CoUninitialize();
return TRUE;
}
I am using QT. When I run this code, I get the error
我正在使用 QT。当我运行此代码时,出现错误
Cannot open include file: 'atlbase.h': No such file or directory
无法打开包含文件:'atlbase.h':没有这样的文件或目录
I noticed that I do not have the files atlbase.h
or atlcom.h
in my machine. However, this code runs without error in my laptop, and I got those 2 files there.
我注意到我没有文件atlbase.h
或atlcom.h
在我的机器中。但是,这段代码在我的笔记本电脑上运行没有错误,我在那里得到了这两个文件。
I am thinking about getting a copy of those 2 files into my desktop computer and will it work? If yes, to which folder do I have to copy them? I am new to Windows programming, QT and speech.
我正在考虑将这 2 个文件的副本复制到我的台式计算机中,它会起作用吗?如果是,我必须将它们复制到哪个文件夹?我是 Windows 编程、QT 和语音的新手。
回答by Vladyslav Litunovsky
For me these files are located here:
对我来说,这些文件位于:
VS2010 - C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\atlbase.h
VS2008 - C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlbase.h
Please note ATL is part of Microsoft Visual Studio (but not the Express Edition). If you need get ATL for Express please take a look at this topic How to add WTL and ATL to visual studio c++ express 2008
请注意 ATL 是 Microsoft Visual Studio(但不是 Express Edition)的一部分。如果您需要为 Express 获取 ATL,请查看此主题How to add WTL and ATL to Visual Studio c++ express 2008
I don't think copying atlbase.h
and atlcom.h
will help you.
You might try to get all atl*.h files and install required Microsoft Visual C++ Redistributable package.
我不认为抄袭atlbase.h
并atlcom.h
会帮助你。您可以尝试获取所有 atl*.h 文件并安装所需的 Microsoft Visual C++ Redistributable 包。
回答by john
You don't need those headers for that code. Remove extern CComModule _Module;
and the atl headers. Add #include <windows.h>
.
您不需要该代码的那些标头。删除extern CComModule _Module;
和 atl 标头。添加#include <windows.h>
.
回答by renaissanceMan
I installed VS 2015 Express which said it was VS 2017 Community when it ran and was having this altbase.h problem with very simple c++ programs. You can fixate on getting the exact include files or you can take a step back to solve this problem. Microsoft is a big, thorough company, when they give you the c++ compiler they give you the libraries you need. When I fixed this problem I
我安装了 VS 2015 Express,它说它在运行时是 VS 2017 Community,并且在使用非常简单的 C++ 程序时遇到了这个 altbase.h 问题。您可以专注于获取确切的包含文件,或者您可以退后一步来解决这个问题。Microsoft 是一家大而全面的公司,当他们为您提供 C++ 编译器时,他们会为您提供所需的库。当我解决这个问题时
- started Visual Studio as administrator.
- Created a Win32 c++ Console app
- Did NOT check "Empty Project" on c++ project create wizard.
- Did NOT check the Common Header Files for ATL and MFC.
- 以管理员身份启动 Visual Studio。
- 创建了一个 Win32 c++ 控制台应用程序
- 没有在 C++ 项目创建向导上检查“空项目”。
- 没有检查 ATL 和 MFC 的通用头文件。
Then when I added my code the generated stdafx.h default included header did not cause this altbase.h problem like it was doing before. I was able to add other includes and did a "using namespace std;" and I was able to do cout and cin's. My base operating system was Windows 7 Home Premium. Obviously when you installed VS 2015/2017 Express you had to select the c++ check box for the install.
然后当我添加我的代码时,生成的 stdafx.h 默认包含的标头并没有像以前那样导致这个 altbase.h 问题。我能够添加其他包含并做了一个“使用命名空间标准;” 我能够做 cout 和 cin's。我的基本操作系统是 Windows 7 Home Premium。显然,当您安装 VS 2015/2017 Express 时,您必须选择 c++ 复选框进行安装。
回答by Marc Claesen
Having the headers is certainly a step in the right direction, but you will also need the libraries in order to compile (unless everything is implemented in headers). You can place the headers where you like, just make sure the linker finds them (either in the default location* or by including the path as a flag).
拥有头文件肯定是朝着正确方向迈出的一步,但您还需要这些库才能进行编译(除非所有内容都在头文件中实现)。您可以将标题放置在您喜欢的位置,只需确保链接器找到它们(在默认位置* 或通过将路径作为标志包含在内)。
*I don't know the default location for Windows.
*我不知道 Windows 的默认位置。
回答by SChepurin
ATL and MFC come with retail versions of VC++. It does not matter where you will place includes and libraries (atl*.lib) needed. Just provide the correct paths to them in IDE.
ATL 和 MFC 随附有零售版本的 VC++。您将包含和所需的库 (atl*.lib) 放在哪里并不重要。只需在 IDE 中为它们提供正确的路径。