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
I am new to C and I am trying to compile a code that uses am external library. Therefore, I am following these steps for linking a library. But at the very first one
gcc -c -Wall -Werror -fpic PICASO_SERIAL_4DLIBRARY.C
I get this
PICASO_SERIAL_4DLIBRARY.C:1:0: error: -fpic ignored for target (all code is position independent) [-Werror]
#include <windows.h>
cc1plus.exe: all warning being treated as errors
additionally undder # there is a arrow above. I tried googling it but I could only find out that this is a Linux problem and not a Windows one (I am developing on Windows now) and the I followed these steps to install gcc. an compiling other small projects work, too.
Anyone any idea, why this doesn’t work?
DavidPostill
7,6649 gold badges41 silver badges60 bronze badges
asked Oct 18, 2015 at 7:15
6
The mention of #include <windows.h>
is incidental. That just happens to be the first line of code.
The compiler tries to associate a line of code with the error to help you find the problem. But in this case the code is irrelevant. The error is in the command line and you will get a failure no matter what the code is. But because the compiler is coded to always associate a line of code with an error, it decides, arbitrarily, to point the finger at the first line of code.
Because you use -Werror
, warnings are treated as errors. The compiler therefore converts a warning about an ignored option to emit position independent code into an error. The error message states this very clearly:
PICASO_SERIAL_4DLIBRARY.C:1:0: error: -fpic ignored for target (all code is position independent) [-Werror]
I suspect you glazed over when reading the error message, and turned your attention to the line of code that was highlighted. Always read error messages carefully!
To resolve the error, remove the -fpic
option from your command line.
answered Oct 18, 2015 at 7:30
David HeffernanDavid Heffernan
599k42 gold badges1064 silver badges1481 bronze badges
3
Try to compile without -fpic
. This flag is inappropriate for the mingw-w64 target.
answered Oct 18, 2015 at 7:22
0
I’ve just installed VS2015 Community.
I didn’t uninstall VS2010.
It converted a large application I’m currently working on.
I’m getting this error — fatal error C1083: Cannot open include file: ‘windows.h’: No such file or directory
Here is some new code I just created using the empty template, multi char instead of UTF 16:
#include <windows.h> INT_PTR CALLBACK simple_2015_dialog_box(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { DialogBox(hinstance, "SIMPLE_2015_DIALOG", NULL, (DLGPROC)simple_2015_dialog_box); } INT_PTR CALLBACK simple_2015_dialog_box(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { }
There might be a lot of problems in this little piece of code, I just tossed it together. I didn’t even bother building the dialog template.
However, the only error it reports is — fatal error C1083: Cannot open include file: ‘windows.h’: No such file or directory
I searched the C drive for windows.h and found nothing.
I’ve found Microsoft’s search tool useless since Win 7. Here is what it came up with when looking for windows.h.
Why do I need to scroll through 209 files with names like
amd64_microsoft.windows.c..-controls.resources_6595b64144ccf1df_5.82.10586.0_hu-hu_396d25395bc70435_comctl32.dll.mui_0da4e682
when I’m searching for a file with the name of «windows.h»? I’ve looked for a forum on MS’s search feature, with no luck.
Anyway, the search finds no file named windows.h.
Why can’t I find VS2010’s windows.h file?
What am I doing wrong?
Thanks
Larry
-
Edited by
Thursday, March 24, 2016 6:08 PM
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
#include "stdafx.h" #include <windows.h> #include <iostream> #include <string> #include <sstream> #include <vector> #include <stdexcept> #include <cstdlib> class Fraction { long _numerator; //числитель long _denominator; // знаменатель // функция для проверки знаменателя на равенство нулю void check_zero() { if ( ! _denominator ) throw std::runtime_error("Zero denominator!"); } public: // конструктор, принимающий значения числителя и знаменателя Fraction(long n, long d) : _numerator(n), _denominator(d) { check_zero(); } // конструктор по умолчанию Fraction() : _numerator(1), _denominator(1) { } // конструктор копирования Fraction(const Fraction & f) { *this = f; } // деструктор ~Fraction() { } // перегруженный оператор = const Fraction & operator = (const Fraction & f) { if ( this != & f ) { _numerator = f.numerator(); _denominator = f.denominator(); } return *this; } // функции для доступа к числителю и знаменателю (константные - чтение, неконстантные - запись) long numerator() const { return _numerator; } void numerator (long n) { _numerator = n; } long denominator() const { return _denominator; } void denominator(long d) { _denominator = d; check_zero(); } // функция, возвращающая дробь в виде строки std::string str() const { if ( ! _numerator ) return "0"; std::ostringstream ost; ost << _numerator << '/' << _denominator; return ost.str(); } // функция, возвращающая строку, содержащую "правильную дробь" // к примеру 5/2 будет выведено, как 2 1/2 std::string correct_str() const { if ( _numerator >= _denominator ) { std::ostringstream ost; long whole = _numerator / _denominator; ost << whole; if ( _numerator % _denominator ) ost << ' ' << ( _numerator - whole * _denominator ) << '/' << _denominator; return ost.str(); } else return str(); } // функция для сокращения дроби. 4/8 будет преобразованно в 1/2 const Fraction & abbreviation() { for ( long i = _numerator; i > 1; --i ) { if ( _numerator % i == 0 && _denominator % i == 0 ){ _numerator /= i; _denominator /= i; break; } } return *this; } // перегруженные функции для выполнения математических действий с дробями // см. учебник по математике примерно для пятого класса const Fraction operator * (const Fraction & f) const { Fraction n( _numerator * f._numerator, _denominator * f._denominator ); n.abbreviation(); return n; } const Fraction operator / (const Fraction & f) const { Fraction n( _numerator * f._denominator, _denominator * f._numerator ); n.abbreviation(); return n; } const Fraction operator + (const Fraction & f) const { Fraction n; if ( _denominator == f._denominator ){ n.numerator(_numerator + f._numerator); n.denominator(_denominator); } else { n.numerator(_numerator * f._denominator + f._numerator * _denominator); n.denominator(_denominator * f._denominator); } n.abbreviation(); return n; } const Fraction operator - (const Fraction & f) const { Fraction n; if ( _denominator == f._denominator ){ n.numerator(_numerator - f._numerator); n.denominator(_denominator); } else { n.numerator(_numerator * f._denominator - f._numerator * _denominator); n.denominator(_denominator * f._denominator); } n.abbreviation(); return n; } }; // перегруженный оператор вывода в поток std::ostream & operator << (std::ostream & ost, const Fraction & f) { ost << f.correct_str(); return ost; } // функция для вывода русского текста std::string tr(const char * text) { static char buf [ 2048 ]; CharToOemA(text, buf); std::string s(buf); return s; } // вывод подсказки void help() { std::cout << tr("Калькулятор дробей.") << "n" << tr("Введите запрос в виде 1/2 + 1/3 или 4 5/8 * 3 1/6") << "n" << tr("и нажмите enter.") << "n" << tr("Обратите внимание! Все данные вводятся через пробел,") << "n" << tr("между числителем, символом '/' и знаменателем") << "n" << tr("пробелы не допускаются!") << std::endl; } // вывод меню int print_menu() { int m; std::cout << tr("n1 - вычислитьn2 - помощьn0 - выходn> "); std::cin >> m; std::cout << std::endl; std::cin.get(); return m; } // разбор строки, вычисление, на выходе - строка с результатом std::string calc(const std::string & arguments) { static const std::string operators("+-*/"); long whole, numerator, denominator; char op; size_t pos; int op_pos; Fraction a, b; std::vector<std::string> avec; std::istringstream ist(arguments); std::string arg; while ( ist >> arg ) avec.push_back(arg); if ( avec.size() < 3 || avec.size() > 5 ) return tr("Ошибка ввода!"); if ( operators.find(avec[1][0]) != std::string::npos ) { op_pos = 2; op = avec[1][0]; whole = 0; if ( ( pos = avec[0].find('/') ) == std::string::npos ) { numerator = atol(avec[0].c_str()); denominator = 1; } else if ( pos == 0 || pos == avec[0].size() - 1 ) return tr("Ошибка ввода!"); else { numerator = atol(avec[0].substr(0, pos).c_str()); denominator = atol(avec[0].substr(pos + 1).c_str()); } } else if ( operators.find(avec[2][0]) != std::string::npos ) { op_pos = 3; op = avec[2][0]; whole = atol(avec[0].c_str()); if ( ( pos = avec[1].find('/') ) == std::string::npos || pos == 0 || pos == avec[1].size() - 1 ) return tr("Ошибка ввода!"); numerator = atol(avec[1].substr(0, pos).c_str()); denominator = atol(avec[1].substr(pos + 1).c_str()); } else return tr("Ошибка ввода!"); a.numerator(whole * denominator + numerator); a.denominator(denominator); if ( avec.size() - op_pos == 1) { whole = 0; if ( ( pos = avec[op_pos].find('/') ) == std::string::npos ) { numerator = atol(avec[op_pos].c_str()); denominator = 1; } else if ( pos == 0 || pos == avec[op_pos].size() - 1 ) return tr("Ошибка ввода!"); else { numerator = atol(avec[op_pos].substr(0, pos).c_str()); denominator = atol(avec[op_pos].substr(pos + 1).c_str()); } } else { whole = atol(avec[op_pos].c_str()); if ( ( pos = avec[op_pos + 1].find('/') ) == std::string::npos || pos == 0 || pos == avec[op_pos + 1].size() - 1 ) return tr("Ошибка ввода!"); numerator = atol(avec[op_pos + 1].substr(0, pos).c_str()); denominator = atol(avec[op_pos + 1].substr(pos + 1).c_str()); } b.numerator(whole * denominator + numerator); b.denominator(denominator); switch ( op ) { case '+' : return (a + b).correct_str(); case '-' : return (a - b).correct_str(); case '*' : return (a * b).correct_str(); case '/' : return (a / b).correct_str(); default : return tr("Ошибка ввода!"); } } int main() { std::string buf; int mnu; while ( mnu = print_menu() ){ switch ( mnu ) { case 1 : std::cout << tr("Запрос: "); std::getline(std::cin, buf); if ( buf.empty() ) std::cerr << tr("Ошибка ввода!") << std::endl; else std::cout << tr("Результат: ") << calc(buf) << std::endl; break; case 2 : help(); break; default: std::cerr << tr("Неверный выбор") << std::endl; break; } } return 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