A single-line test.c:
#include <dwrite.h>
From the visual studio command prompt,
compiled as C++ works: cl /c /Tp test.c
compiled as C does not: cl /c test.c
First, I get a bunch of errors as this one:
C:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um\dwrite.h(671): error C2059: syntax error: ':'
The line 671 is as follows:
interface DWRITE_DECLARE_INTERFACE("739d886a-cef5-47dc-8769-1a8b41bebbb0") IDWriteFontFile : public IUnknown
preprocessed to C++
struct __declspec(uuid("739d886a-cef5-47dc-8769-1a8b41bebbb0")) __declspec(novtable) IDWriteFontFile : public IUnknown
preprocessed to C
struct IDWriteFontFile : public IUnknown
and the part " : public IUnknown" gets in the way.
How am I supposed to fix this?
Then I get an error on line 1037: error C2061: syntax error: identifier 'IDWriteGeometrySink'
interface ID2D1SimplifiedGeometrySink;
typedef ID2D1SimplifiedGeometrySink IDWriteGeometrySink;
preprocessed to C
struct ID2D1SimplifiedGeometrySink;
typedef ID2D1SimplifiedGeometrySink IDWriteGeometrySink;
Finally, a bunch of errors involving static_cast which C does not have.
All in all, is dwrite.h not suitable for C? Using Visual Studio Community 2022. Does it work in any previous versions?
What I'm trying to do is compile https://github.com/makuke1234/PongD2D
C doesn't have inheritance, so this header is most likely C++ only.
The project you linked uses D2D from .cpp files and wraps C++ interface into C.
Related
I'm trying to compile the psutil module for Python, using VS 2015 and the Windows 10 SDK. Compilation fails with the following error:
c:\users\builder\documents\code\psutil\psutil\arch\windows\ntextapi.h(212): error C2365: 'ProcessBreakOnTermination': redefinition; previous definition was 'enumerator'
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\um\winternl.h(308): note: see declaration of 'ProcessBreakOnTermination'
c:\users\builder\documents\code\psutil\psutil\arch\windows\ntextapi.h(212): error C2086: '_PROCESSINFOCLASS2 ProcessBreakOnTermination': redefinition
c:\users\builder\documents\code\psutil\psutil\arch\windows\ntextapi.h(212): note: see declaration of 'ProcessBreakOnTermination'
Further investigation shows ProcessBreakOnTermination is part of an enum (PROCESSINFOCLASS) in winternl.h.
I believe this has to do with C++11's enforcement of scoped enums: https://msdn.microsoft.com/en-us/library/vstudio/2dzy4k6e(v=vs.110).aspx
However, I am lost on how to address this issue. If I try to add the class or struct bits as detailed on that MS website, I get compiler errors, since this is being compiled as C code. Why should the C++11 rules apply to C code here?
The solution I came up with was to wrap the offending dual-defined symbols in a #if.
(start of enum)
(last good entry)
#if _MSC_VER < 1900
(offending enum entry)
#endif
(next entry) = (last_good_entry)+2
Any nicer solutions are welcome!
Hi I am trying to utilize this library http://nemosim.sourceforge.net to play around with Spiking Neural Networks.
I am new to C and C++.
What I've done is, downloaded the installer from here: http://sourceforge.net/projects/nemosim/
Installed.
I then wrote this program in main.c file:
#include<nemo.h>
#include<stdio.h>
#include<stdlib.h>
main()
{
printf("Hello World!");
getchar();
}
and compiled it using MinGW on Windows:
gcc -I"C:\Program Files (x86)\NeMo\include" main.c -o main.exe
I get the following error:
In file included from main.c:1:0:
C:\Program Files (x86)\NeMo\include/nemo.h:48:1: error: unknown type name 'nemo_
network_class'
typedef nemo_network_class* nemo_network_t;
^
C:\Program Files (x86)\NeMo\include/nemo.h:49:1: error: unknown type name 'nemo_
simulation_class'
typedef nemo_simulation_class* nemo_simulation_t;
^
C:\Program Files (x86)\NeMo\include/nemo.h:50:1: error: unknown type name 'nemo_
configuration_class'
typedef nemo_configuration_class* nemo_configuration_t;
^
Please help me.
It looks like nemo.h has problems, but I suspect I am missing something because I am a newbie...
It looks like this code has a common error that occurs when C++ programmers migrate to writing C code. In C++, you can declare a struct nemo_network_class object by writing, for example:
nemo_network_class foo;
However, in C, the struct is part of the type identifier. You must write:
struct nemo_network_class foo;
Change this: typedef nemo_network_class* nemo_network_t;
... to this: typedef struct nemo_network_class* nemo_network_t;
Change this: typedef nemo_simulation_class* nemo_simulation_t;
... to this: typedef struct nemo_simulation_class* nemo_simulation_t;
Change this: typedef nemo_configuration_class* nemo_configuration_t;
... to this: typedef struct nemo_configuration_class* nemo_configuration_t;
After you've made these changes and confirmed that they work, please submit a bug report so that this solution gets pushed into production.
I have some working Matlab code, which I try to transform into C code using the Matlab coder. I am getting this error:
18 c:\users\bla\project\strcmpi.h(79) : warning C4028: formal parameter 2 different from declaration
19 c:\users\bla\project\strcmpi.h(79) : error C2371: 'strcmpi' : redefinition; different basic types
20 c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\string.h(245) : see declaration of 'strcmpi'
21 NMAKE : fatal error U1077: '"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.EXE"' : return code '0x2'
22 Stop.
23 The make command returned an error of 2
24 'An_error_occurred_during_the_call_to_make' is not recognized as an internal or external command,
25 operable program or batch file.
It looks very C specific to me (I am not a proficient C programmer). Can anyone please point me in the right direction to overcome this error? Thanks.
PS:
Here is some adapted Matlab code:
if(strcmpi(parameters.x,'bladibla') == 1)
% some code
else
% some more code
end
where 'parameters' is a struct. I would like to stick to my struct but if there are better ways to achieve the above, especially in the context of the Matlab coder and C, please let me know.
The thing about strcmpi() (case-insensitive string comparison) is that it's not a standard C function. Thus, code that relies on it but tries to be portable across platforms sometimes has to provide its own implementation while deferring to the system's implementation if available. In my experience, the project's own strcmpi() implementation will be protected by a configuration option. If you open up c:\users\bla\project\strcmpi.h, you might see code similar to this:
#ifndef CONFIG_STRCMPI_PRESENT
int strcmpi(const char *string1, const char *string2);
#endif // CONFIG_STRCMPI_PRESENT
If you see this, the trick to getting around the problem will probably be to find the associated config.h file and uncomment the following line:
// #define CONFIG_STRCMPI_PRESENT
This is all just a guess based on my experience with similar issues.
Basically, I have the compiler compiling my .cu files and I have (I think) full operation within those .cu files, but when I try to call them (kernel<<<1,1>>>(void)), the compiler registers syntax errors due to the CUDA syntax. Also, calls like cudaMalloc fail within c files.
Here are three really short files, so I can tell you where it is erroring.
//kernel.cu
#include "kernel.h"
#include <cuda.h>
#include <cuda_runtime_api.h>
__global__ int kernel(void){
return 5;
}
and
//kernel.h
#ifndef _KERNEL_h_
#define _KERNEL_h_
extern "C" int kernel(void);
#endif
and
//main.c
#include "kernel.h"
#include <cuda.h>
#include <cuda_runtime_api.h>
int main() {
int* device_a;
cudaMalloc( (void**)&device_a, sizeof(int) );
kernel<<<1,1>>>();
}
I got the header file from some of the SDK examples. Also, I have my build configuration set with CUDA 4.2, hence why the .cu file compiles. If I made any incidental syntax errors, it is because I simplified it for posting, not that it is actually in the source, although please mention it just in case.
kernel.cu compiles fine.
kernel.h has an error: "error C2059: syntax error : 'string'" on the "extern..." line. (Could this be because I took that from a c++ example?)
main.c has an error: "error C2065: 'kernel' : undeclared identifier"
and: "error C2059: syntax error : '<'"
but when I comment out the kernel call, so it is just cudaMalloc, I get: "error LNK2019: unresolved external symbol _cudaMalloc#8 referenced in function _main"
and: "fatal error LNK1120: 1 unresolved externals"
Is it something with Visual Studio 2010, or is it something I am not including? From the SDK examples, I can't tell what I'm doing wrong, other then they found a way, I think, to not use the triple bracket (CTRL+F doesn't find any). Any help is appreciated. Thank you in advance!
EDIT: after looking at some more examples, they do use the triple bracket syntax just fine.
EDIT: For those using this as reference, __global__ functions can only return void. If you try to return anything else, as I did, you will receive compiler errors.
Put the functions that invoke CUDA kernel in .cu files.
Set up VS2010 to compile CU files with the CUDA compiler, not the built in one (use the CUDA rules files (Cuda.props, Cuda.xml, Cuda.targets) located within the CUDA SDK).
I recommend placing kernels in files with a different extension (e.g. .curnel files), so that they will not be compiled directly (only if called).
I recommend putting the declaration of the functions that invoke CUDA kernels in .cuh files.
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.