I'm trying to compile a little project that includes windows.h using the clang compiler. Unfortunately, clang produces some errors I'm not able to resolve. What's causing these errors? Does clang not support all required features, am I missing something?
In file included from C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/wind
ows.h:155:
In file included from C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/wind
ef.h:177:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winnt.h(12857) : warning:
expression result unused [-Wunused-value]
UNREFERENCED_PARAMETER(CallbackEnviron);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winnt.h:12857:28: note: in
stantiated from:
UNREFERENCED_PARAMETER(CallbackEnviron);
^~~~~~~~~~~~~~~
In file included from C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/wind
ows.h:156:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2326) : error:
invalid operands to binary expression ('LONGLONG' (aka 'double') and
'LONGLONG')
Old & Value,
~~~ ^ ~~~~~
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2327) : error:
expected ')'
Old) != Old);
^
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2325) : note:
to match this '('
} while (InterlockedCompareExchange64(Destination,
^
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2344) : error:
invalid operands to binary expression ('LONGLONG' (aka 'double') and
'LONGLONG')
Old | Value,
~~~ ^ ~~~~~
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2345) : error:
expected ')'
Old) != Old);
^
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2343) : note:
to match this '('
} while (InterlockedCompareExchange64(Destination,
^
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2362) : error:
invalid operands to binary expression ('LONGLONG' (aka 'double') and
'LONGLONG')
Old ^ Value,
~~~ ^ ~~~~~
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2363) : error:
expected ')'
Old) != Old);
^
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include/winbase.h(2361) : note:
to match this '('
} while (InterlockedCompareExchange64(Destination,
^
...and a lot more...
You probably need to define a clang-compatible version of the UNREFERENCED_PARAMETER macro. Something like this should help you on the way: https://web.archive.org/web/20130425151054/http://sourcefrog.net/weblog/software/languages/C/unused.html
Also, it seems the type LONGLONG is defined as double for clang, and you can't do binary arithmetic (and, or, not etc) on floats. You need to make sure this is typedefed as a proper integer type.
Depending a bit on how windows.h, winbase.h and winnt.h is structured you may be able to make your own wrapper that gets the right defines in place to make this pass. Otherwise, try to find a gcc-compatible version of windows.h, and use that. Clang should be compatible with it.
Good luck!
Related
I have problems with my code, after including dirent.h in my project, I got the error
Severity Code Description Project File Line Suppression State
Error C2011 '_iobuf': 'struct' type redefinition KittenProject C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt_wstdio.h 26
in the corecrt_wstdio.h file, line 26
how can I fix this? thanks in advence
Trying to build apr 1.7 on Windows with Visual Studio, tried 2017 and 2013.
When building the project (Debug|x86) or compiling e.g. dso.c if get the following error message:
1>dso.c
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2143: syntax error: missing ')' before '*'
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2143: syntax error: missing '{' before '*'
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2059: syntax error: ')'
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2061: syntax error: identifier 'apr_winapi_pfn_if_indextoname'
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2059: syntax error: ';'
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2513: ' ': no variable declared before '='
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2065: 'apr_winapi_pfn_if_indextoname': undeclared identifier
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): warning C4047: '=': 'int' differs in levels of indirection from 'int *(__cdecl *)(NET_IFINDEX,PCHAR)'
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2146: syntax error: missing ';' before identifier 'apr_load_dll_func'
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2100: illegal indirection
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): error C2064: term does not evaluate to a function taking 1207 arguments
1>c:\dev\log4cxx\apr\include\arch\win32\apr_arch_misc.h(503): warning C4033: 'apr_winapi_if_indextoname' must return a value
I have succesfully build version 1.65 (after apply the hint from http://letcoderock.blogspot.com/2017/09/build-log4cxx-trunk-on-windows-by.html or Apache Cross Compilation Error ./gen_test_char: cannot execute binary file)
Comparing apr_arch_misc.h of the two version, i have noticed DLL_IPHLPAPI was new to the enum apr_dlltoken_e and Intelisense was complaining about
APR_DECLARE_LATE_DLL_FUNC(DLL_IPHLPAPI, PCHAR, NETIOAPI_API_, if_indextoname, 0, (
NET_IFINDEX InterfaceIndex,
PCHAR InterfaceName),
(InterfaceIndex, InterfaceName));
with "expecting a ')'".
If have changed NETIOAPI_API_ to WINAPI. Do not know if this is correct but the file could now be compiled (after running the above trick with gen_test_char.exe).
But after that I ran into the next Problem:
1>sockaddr.c
1>network_io\unix\sockaddr.c(144): error C2065: 'IF_NAMESIZE': undeclared identifier
1>network_io\unix\sockaddr.c(144): error C2057: expected constant expression
1>network_io\unix\sockaddr.c(144): error C2466: cannot allocate an array of constant size 0
1>network_io\unix\sockaddr.c(144): error C2133: 'scbuf': unknown size
1>network_io\unix\sockaddr.c(1274): error C2065: 'IF_NAMESIZE': undeclared identifier
I have succesfully build apr with gcc in linux/cygwin. I have looked into the the preprocessor substitutions for IF_NAMESIZE and here it is replaced by 44. But I can not find the definiton or where this is set.
Does anyone have an idea how to fix this? And is the above change to WINAPI correct?
Just use cmake to build the Visual Studio Solution:
With
cmake -G "Visual Studio 15 2017" -A x64
the .sln ist properly set up and building the solution works with no errors. Even gen_test_char.exe is build.
Maybe the apr project should make the cmake building instructions a little bit more prominent on their site.
As written in README file:
Note you must manually modify the include\apr.hw file before you
build to change default options
So i just removed line #define _WIN32_WINNT 0x0501 from apr-1.7.0\include\apr.hw
and run nmake -f Makefile.win. Worked fine for me. VS2017 tools, Windows 10.
In case someone else also runs into this problem: I was using cmake + nmake to build APR, but it still didn't work for me.
The reason was that I had old compilation flags to support Windows XP:
cmake -DMIN_WINDOWS_VER=0x0501 ...
Investigating Iphlpapi.h, it seems that netioapi.h and other networking headers used by the current version of APR are supported only starting from Vista onward:
#if (NTDDI_VERSION >= NTDDI_VISTA)
#include <netioapi.h>
#endif // (NTDDI_VERSION >= NTDDI_VISTA)
So in order for the compilation to work, just remove that cmake option or specify a value higher than 0x0600 (the equivalent for Vista).
I am new to programming and picked up the C language as my first computer language. I was doing a sample conversion program and when i compiled the code, i get the following error.
What does it mean and how do i fix it?
Thanks!
1>------ Build started: Project: ConversionProgram, Configuration: Debug Win32 ------
1>Build started 24-07-2012 20:58:37.
1>InitializeBuildStatus:
1> Touching "Debug\ExcerciseProgram1.unsuccessfulbuild".
1>ClCompile:
1> conversion.cpp
1>c:\my documents\visual studio 2010\projects\excerciseprogram1\excerciseprogram1\question2.cpp(12): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 10.0\vc\include\stdio.h(304) : see declaration of 'scanf'
1>c:\my documents\visual studio 2010\projects\excerciseprogram1\excerciseprogram1\question2.cpp(18): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>c:\my documents\visual studio 2010\projects\excerciseprogram1\excerciseprogram1\question2.cpp(32): error C2857: '#include' statement specified with the /YcStdAfx.h command-line option was not found in the source file
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.1
I am using VB 2010 as my IDE
The reason why you are experiencing a compile error is mentioned here:
error C2857: '#include' statement specified with the /YcStdAfx.h command-line option was not found in the source
This means that the compiler is making the inclusion of StdAfx.h compulsory. You can remedy this by adding #include <StdAfx.h> to your source code.
It seems that your source file is not including the precompiled header file. All source files must, as first non-comment, include "stdafx.h" if you are using precompiled headers.
I've been trying to learn C, and I'm stuck on including libraries. I need to use strcpy(), but that method is included in the iostream library, but whenever I try to include the library, the program gives me errors. I've tried using "iostream", "iostream.h", , , but it either gives me a "can't find iostream.h" error, or the program exceeds 100 errors and just crashes. Even if my code is empty, I still get the same thing. Here's the code:
#include "iostream"
int main(void)
{
}
Yup, just that much makes it crash already. And here's a part of the errors I'm getting (could never paste them all here):
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(37): error C2061: syntax error : identifier 'abs'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(37): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(39): error C2061: syntax error : identifier 'acos'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(39): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(39): error C2061: syntax error : identifier 'asin'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(39): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2061: syntax error : identifier 'atan'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2061: syntax error : identifier 'atan2'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2061: syntax error : identifier 'ceil'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(41): error C2061: syntax error : identifier 'cos'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(41): fatal error C1003: error count exceeds 100; stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
So yeah it even exceeds the 100 errors and the program just stops counting. I don't understand why, I'm just including a regular library. Is there an equivalent of strcpy()? I mainly wanted to use it like this (for practice):
#include "stdafx.h"
#include "stdlib.h"
#include "stdio.h"
#include "conio.h"
#include "iostream"
int main(void)
{
struct person
{
int id;
char name[50];
int age;
};
struct person p1;
p1.id = 5595;
strcpy(p1.name, "Myname");
p1.age = 18;
printf("%d%s%d", p1.id, p1.name, p1.age);
}
<iostream> is a C++ header (it deals with input/ouput streams, as the name implies). If you want strcpy, you need <string.h>.
If your source file is ".c", all you have to do is to rename it ".cpp".
Then it'll compile as C++, you'll have the C++ headers, and you'll be able to use C++ streams.
I don't see any need for iostreams, however.
Strcpy and friends are in "<string.h>". Just include it, and "stdio.h" (like you're doing); delete the "iostreams" #include ... and life should be good.
iostreams are a C++-only feature. The iostreams header file is written in C++, not C. (Yes, they are different languages!) Presumably, you're invoking the compiler in C mode, so when the compiler looks at the header file it of course throws lots of errors since many of the constructs used in iostream makes sense only in C++ mode.
If you want to use iostreams, you have to compile in C++ mode (and code in proper, modern C++ accordingly), use a different library that's C-only or work around it by implementing your own code as necessary.
In this case, all you apparently want to do is to use strcpy(). That is declared in the string.h, not iostream. (string.h is a C header file.) Just #include <string.h> and it should compile.
im tyring to get this to work:
#define UNICODE
#define _UNICODE
#include <wchar.h>
int main()
{
wprintf(L"Hello World!\n");
wprintf(L"£안, 蠀, ☃!\n");
return 0;
}
using visual studio 2008 express (on windows xp, if it matters).
when i run this from the command prompt (started as cmd /u which is supposed to enable unicode ?) i get this:
C:\dev\unicodevs\unicodevs\Debug>unicodevs.exe
Hello World!
┬ú∞
C:\dev\unicodevs\unicodevs\Debug>
which i suppose was to be expected given that the terminal does not have the font to render those.
but what gets me is that even if i try this:
C:\dev\unicodevs\unicodevs\Debug>cmd /u /c "unicodevs.exe > output.txt"
the file produced (even though its UTF-8 encoded) looks like:
Hello World!
壓
the source file itself is defined as unicode (encoded in UTF-8 without BOM).
the compiler output when building:
1>------ Rebuild All started: Project: unicodevs, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'unicodevs', configuration 'Debug|Win32'
1>Compiling...
1>main.c
1>.\main.c(1) : warning C4005: 'UNICODE' : macro redefinition
1> command-line arguments : see previous definition of 'UNICODE'
1>.\main.c(2) : warning C4005: '_UNICODE' : macro redefinition
1> command-line arguments : see previous definition of '_UNICODE'
1>Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\wchar.h
1>Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
1>Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\sal.h
1>C:\Program Files\Microsoft Visual Studio 9.0\VC\include\sal.h(108) : warning C4001: nonstandard extension 'single line comment' was used
1>Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\crtassem.h
1>Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\vadefs.h
1>Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\swprintf.inl
1>Note: including file: C:\Program Files\Microsoft Visual Studio 9.0\VC\include\wtime.inl
1>Linking...
1>Embedding manifest...
1>Creating browse information file...
1>Microsoft Browse Information Maintenance Utility Version 9.00.30729
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>Build log was saved at "file://c:\dev\unicodevs\unicodevs\unicodevs\Debug\BuildLog.htm"
1>unicodevs - 0 error(s), 3 warning(s)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
any ideas on what am i doing wrong ?
similar questions on ST (like this one: unicode hello world for C?) seem to refer to *nix builds - as far as i understand setlocale() is not available for windows.
i also tried building this using code::blocks/mingw gcc, but got the same results.
It's not the writing (wprintf) that's the problem, it's the cmd redirection of output that's causing the problem. You can try testing by writing directly to file instead. In that case, you might then run into notepad (or rather Windows API function) not guessing correctly and interpreting your text as ASCII incorrectly if you're just writing a couple of words. In which case, you'll need to write the BOM characters into the file first as well.
#include <stdio.h>
#include <wchar.h>
int main()
{
FILE *out;
char bom[] = "\xFF\xFE";
wchar_t s[] = L"中文!";
size_t c;
out = fopen ("out.txt", "w");
if(out == NULL)
{
perror("out.txt");
return 1;
}
c = fwrite(bom, 1, 2, out);
if(c != 2)
{
perror ("Fatal write error.");
fclose(out);
return 2;
}
c = fwrite(s, sizeof(wchar_t), wcslen(s), out);
if(c != wcslen(s))
{
perror ("Fatal write error.");
fclose(out);
return 2;
}
fclose(out);
return 0;
}