Cannot open include file: 'atlbase.h': No such file or directory [duplicate]
Asked Answered
L

5

21

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

Cannot open include file: 'atlbase.h': No such file or directory

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.

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.

Luik answered 6/5, 2013 at 17:37 Comment(4)
The same directory you found them in on your laptop is a good choice :)Stationmaster
Thats the problem. Directory is VS 2010 professional. I have 1 license I guess.Luik
See: #3898787Decanal
VS has a very liberal license, you can deploy it on any machine you own as long as they are not used concurrently. Clearly you'll want to take advantage of that, messing with the Express edition is a waste of your time.Stationmaster
H
19

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

I don't think copying atlbase.h and atlcom.hwill help you. You might try to get all atl*.h files and install required Microsoft Visual C++ Redistributable package.

Hoot answered 6/5, 2013 at 18:5 Comment(1)
This helped for me: https://mcmap.net/q/271274/-c-include-lt-atlbase-h-gt-is-not-foundRibeiro
S
7

You don't need those headers for that code. Remove extern CComModule _Module; and the atl headers. Add #include <windows.h>.

Skyscape answered 6/5, 2013 at 18:45 Comment(6)
unfortunatly, it came out with lot of unresolved symbol errors and main.obj not forund errorsLuik
I promise you, you do not need ATL for this application, its a straight COM app. Your project settings or environment must be wrong somehow.Skyscape
Thanks for the reply. Are you using MinGW qt or VS2010 Compiler QT? I am using the one which use VS 2010 compiler. Please help! This is my final year project!!!!!!!!Luik
I'm using VS2010 express.Skyscape
Thank you so much for the answer. I started a project with VS2013 which installation includes atlstr.h, but I have long moved to newer versions of VS. I was installing VS2013 just for the sake of this file until I saw your answer.Balcke
@Skyscape thank for your answer! But I get error: C:\Program Files (x86)\Microsoft Speech SDK 5.1\Include\sphelper.h:53: error: atlbase.h: No such file or directory #include <atlbase.h> ^ Audwin
O
1

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.

Offenbach answered 6/5, 2013 at 17:41 Comment(0)
T
1

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.

Tigre answered 6/5, 2013 at 18:8 Comment(0)
F
1

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

  1. started Visual Studio as administrator.
  2. Created a Win32 c++ Console app
  3. Did NOT check "Empty Project" on c++ project create wizard.
  4. Did NOT check the Common Header Files for ATL and 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.

Forefend answered 13/5, 2017 at 5:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.