First of all: I’m using Microsoft Visual Studio 2012
I am a C#/Java developer and I am now trying to program for the kinect using Microsoft SDK and C++. So I started of with the Color Basics example, and I can not get it to compile.
At first, none of the classes were able to find Windows.h. So I installed (Or re-installed, I’m not sure) the Windows SDK, and added the include dir of the SDK to the include «path» of the project. Then all the problems were gone, except for one:
Error 5 error RC1015: cannot open include file 'windows.h'. C:tempColorBasics-D2DColorBasics.rc 17 1 ColorBasics-D2D
And thats the error. No reasons why, the system can find it because it is used in multiple other files, only this file is not able to work with it. As a reference, the entire file that is bugging (ColorBasics.rc):
//------------------------------------------------------------------------------
// <copyright file="ColorBasics-D3D.rc" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#define APSTUDIO_HIDDEN_SYMBOLS
#include "windows.h"
#undef APSTUDIO_HIDDEN_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_APP ICON "app.ico"
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_APP DIALOGEX 0, 0, 512, 424
STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_CONTROLPARENT | WS_EX_APPWINDOW
CAPTION "Color Basics"
CLASS "ColorBasicsAppDlgWndClass"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Screenshot",IDC_BUTTON_SCREENSHOT,238,391,50,14
CONTROL "",IDC_VIDEOVIEW,"Static",SS_BLACKFRAME,0,0,512,384
LTEXT "Press 'Screenshot' to save a screenshot to your 'My Pictures' directory.",IDC_STATUS,0,413,511,11,SS_SUNKEN,WS_EX_CLIENTEDGE
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_APP, DIALOG
BEGIN
END
END
#endif // APSTUDIO_INVOKED
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h"
END
2 TEXTINCLUDE
BEGIN
"#define APSTUDIO_HIDDEN_SYMBOLSrn"
"#include ""windows.h""rn"
"#undef APSTUDIO_HIDDEN_SYMBOLSrn"
""
END
3 TEXTINCLUDE
BEGIN
"rn"
""
END
#endif // APSTUDIO_INVOKED
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
0 / 0 / 0
Регистрация: 05.05.2013
Сообщений: 189
1
16.12.2013, 13:13. Показов 4806. Ответов 5
При компиляции кода выводит ошибки. Сказали, что это может быть из за не подключения windows.h. Подскажите как исправить
C++ | ||
|
Ошибки: первая: «error LNK2028: ссылка на неразрешенную лексему (0A00040C) «extern «C» int __stdcall CharToOemA(char const *,char *)» (?CharToOemA@@$$J18YGHPBDPAD@Z) в функции «class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl tr(char const *)» (?tr@@$$FYA?AV?$basic_string@DU?$char_traits@D@std @@V?$allocator@D@2@@std@@PBD@Z)»
вторая: «error LNK2019: ссылка на неразрешенный внешний символ «extern «C» int __stdcall CharToOemA(char const *,char *)» (?CharToOemA@@$$J18YGHPBDPAD@Z) в функции «class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl tr(char const *)» (?tr@@$$FYA?AV?$basic_string@DU?$char_traits@D@std @@V?$allocator@D@2@@std@@PBD@Z)»
__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь
0
Hi there. i have issue with using some C/C++ extension in vscode. it gives error as above.
My MacOS catalina version is 10.15.2 and VsCode version is Version: 1.38.1. i have similar error with other header extension such as conio.h and MMsystem.h etc. i have install mingw-w64 and also did the installation of vcpkg as suggested by vscode but still the error still there — . any suggestion would be great. thank you in advance «^^»
Hi @gyurmey . Do I understand correctly that you are running on MacOS, but have installed MinGW in order to target Windows? If so, I believe you would also need to install/extract a Windows 10 SDK to acquire the header files you are referring to.
Hi @gyurmey . Do I understand correctly that you are running on MacOS, but have installed MinGW in order to target Windows? If so, I believe you would also need to install/extract a Windows 10 SDK to acquire the header files you are referring to.
thank you @Colengms for the answer. i have been trying to extract window 10 SDK or find a way to use it in MacOS but haven’t found any solution or executable files for MacOS. is there any other way or vscode extension that enable the headers? thank you ^^
Hi @gyurmey . How did you install MinGW? It looks like MinGW packages should include Windows headers. On Ubuntu Linux, windows.h
is in the following packages:
mingw-w64-common
mingw-w64-i686-dev
mingw-w64-x86-64-dev
If you already have Windows headers installed, the issue you are seeing might be related to file system and case sensitivity. On Windows, the file system is (generally) not case sensitive, so a #include of «Windows.h» would find «windows.h». If the file system on your Mac is case sensitive, you may need to alter some casing used in source code to match the file system.
Hi @gyurmey . How did you install MinGW? It looks like MinGW packages should include Windows headers. On Ubuntu Linux,
windows.h
is in the following packages:mingw-w64-common mingw-w64-i686-dev mingw-w64-x86-64-dev
If you already have Windows headers installed, the issue you are seeing might be related to file system and case sensitivity. On Windows, the file system is (generally) not case sensitive, so a #include of «Windows.h» would find «windows.h». If the file system on your Mac is case sensitive, you may need to alter some casing used in source code to match the file system.
thank you again for the answer @Colengms .. i used the command brew install mingw-w64 . i tried to find the path for mingw but couldn’t find it. I tried to reinstall but it give warning that it is already installed.
Hi @gyurmey . I tried using brew install mingw-w64
. It prompted me to run xcode-select --install
and to also install gcc. That resulted in windows.h
being found here: /usr/local/Cellar/mingw-w64/9.0.0_2/toolchain-x86_64/x86_64-w64-mingw32/nclude/windows.h
I then configured the C/C++ Extension to use x86_64-w64-mingw32-gcc
by setting compilerPath
to its path, in c_cpp_properties.json
. Then I was able to #include windows.h
in a source file, without getting any squiggles.
I did the above using Big Sur, but I suspect the process is the same or similar for Catalina.
Is the above enough information to help you solve the issue?
Hi @gyurmey . I tried using
brew install mingw-w64
. It prompted me to runxcode-select --install
and to also install gcc. That resulted inwindows.h
being found here:/usr/local/Cellar/mingw-w64/9.0.0_2/toolchain-x86_64/x86_64-w64-mingw32/nclude/windows.h
I then configured the C/C++ Extension to use
x86_64-w64-mingw32-gcc
by settingcompilerPath
to its path, inc_cpp_properties.json
. Then I was able to #includewindows.h
in a source file, without getting any squiggles.I did the above using Big Sur, but I suspect the process is the same or similar for Catalina.
Is the above enough information to help you solve the issue?
Thank you so much @Colengms . Now the squiggles are gone and i can go to the definition of the header file as is was not the case earlier. i also found a new compiler path in C/C++ config. but when i run the C/C++ file on vscode, it still give same error on the terminal even the file doesn’t have any error warning. ^^ .. i will try to dig deeper into it.. «^_^»
but when i run the C/C++ file on vscode, it still give same error on the terminal
Could you clarify what you mean by «run the C/C++ file»? Are you referring to running a particular command line in the terminal, using Build and Debug Active File
, pressing F5 (Debug: Start Debugging
), clicking on Run and Debug
, or something else?
Config values in c_cpp_properties.json
are used to configure IntelliSense (squiggles, colorization, etc.), and not used directly to compile sources. The C/C++ extension is separate from (though somewhat connectable to) the various build systems projects might employ (such as Make or CMake) to compile sources.
If you had previously used one of the various features to Build/Run/Debug a single source file, tasks.json
and/or launch.json
files were likely created the first time and persistent, and may need corrections. However, since you are running on macOS, and MinGW generates executables for Windows, I assume you would be unable to run the program directly from VS Code.
but when i run the C/C++ file on vscode, it still give same error on the terminal
Could you clarify what you mean by «run the C/C++ file»? Are you referring to running a particular command line in the terminal, using
Build and Debug Active File
, pressing F5 (Debug: Start Debugging
), clicking onRun and Debug
, or something else?![]()
Config values in
c_cpp_properties.json
are used to configure IntelliSense (squiggles, colorization, etc.), and not used directly to compile sources. The C/C++ extension is separate from (though somewhat connectable to) the various build systems projects might employ (such as Make or CMake) to compile sources.If you had previously used one of the various features to Build/Run/Debug a single source file,
tasks.json
and/orlaunch.json
files were likely created the first time and persistent, and may need corrections. However, since you are running on macOS, and MinGW generates executables for Windows, I assume you would be unable to run the program directly from VS Code.
Thank you @Colengms for the answer. i have tried running both from Build and Debug Active File command and also vscode run tab. i do have task.json and launch.json. i think windows.h is not supported in MacOS using vscode. i tried in Linux Ubuntu as well and i did the same procedure but result in same error. May be it is only supported in window itself but unfortunately, could not test it ^^ .
Hi @gyurmey . MinGW stands for «Minimalist GNU for Windows». You should be able to (cross-)compile with MinGW, but you will not be able to run the program you generate on macOS or Linux. The program it generates would only run on a Windows PC. If you would like to build an application for macOS or Linux, I’d suggest using the inbuild versions of clang or gcc on those platforms.
Hi @gyurmey . MinGW stands for «Minimalist GNU for Windows». You should be able to (cross-)compile with MinGW, but you will not be able to run the program you generate on macOS or Linux. The program it generates would only run on a Windows PC. If you would like to build an application for macOS or Linux, I’d suggest using the inbuild versions of clang or gcc on those platforms.
thank you so much for thorough discussion and explanation.. @Colengms
See more:
Hi,
In my project after including some header files,it is showing the below error.When I removed those statements it is showing a bulk error of ‘178’ numbers.And I checked which are those including files.Can anyone help me how can I remove that error.
#ifdef _WINDOWS_ #error WINDOWS.H already included. MFC apps must not #include <windows.h> #endif
Thanks,
This may help someone. I got the same error from a UnitTest project.
I changed my stdafx.h to this:
#include "targetver.h" #include <afx.h> #include <afxwin.h> // MFC core and standard components // Headers for CppUnitTest #include "CppUnitTest.h" // TODO: reference additional headers your program requires here
… and the error went.
Here are some of the rules I use for #include files which might be helpful to you:
— Use precompiled headers («#include <stdafx.h>»). This must be the first include in your .cpp file. It should never be in a .h file. [I also routinely rename the file to something project specific (eg. util_stdafx.h) in a multi-project environment so that the wrong file is not included somewhere. You can choose whether or not to do this…]
— Immediately after the stdafx.h file include should be the #include corresponding to your .cpp file. This way, the .h file will #include anything it needs to work properly.
— After these 2 includes in your .cpp file, include anything else needed for the .cpp file to run correctly.
— Header files that come with the compiler are called «Stable headers». These should be the only ones that appear in stdafx.h, along with #defines used by these headers (eg. WIN32_LEAN_AND_MEAN, _WIN32_WINNT etc.). If you are on windows, then stdafx.h is the only place you should see «#include <windows.h>»
— The first non-blank non-comment lines in header files should be either «#pragma once» or guard block definition (or both).
Check probably `Windows.h` might be included in your `stdafx.h` file. If so, then comment `Windows.h` and then check, the error may go off. Because I had the same problem I resolve in same way.
thanks from all of you
your solutions were good and applicational.
i solved it through the following method:
just add below precompile definitions :
#ifdef __windows__ #undef __windows__ #endif
and thanks again
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900