I'm new to C++, I have a Visual C++ project in Visual Studio 2008 (stuck with it I'm afraid) and I'm trying to get unit tests to work. I've got my code and I've got my new test project set up but any time I include the header file of the code I want to test, I get 138 compilation errors.
#include "stdafx.h"
//#include "../ProjName/ProjName.h"
using namespace System;
using namespace System::Text;
using namespace System::Collections::Generic;
using namespace Microsoft::VisualStudio::TestTools::UnitTesting;
namespace TestProjName
{
...various code created by the wizard...
[TestMethod]
void Test1()
{
Assert::AreEqual(0,1);
};
};
My code compiles (and runs) fine until the #include to my ProjName is uncommented. When it is uncommented, I get a lot of errors from the VS libraries along the lines of:
1>c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\vadefs.h(89) : error C4956: 'va_list *' : this type is not verifiable
,
1>c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h(2027) : error C4956: 'threadlocaleinfostruct *' : this type is not verifiable
and
1>c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\wchar.h(235) : error C2337: 'SA_Post' : attribute not found
Has anyone come across this before? Might anyone suggest a (probably simple) thing I'm overlooking?
Found my own solution after a good while googling. My test project used /clr:safe common language runtime support. Switching it to /clr fixed the issue for me.
Related
In my simple OpenGL program I get the following error about exit redefinition:
1>c:\program files\microsoft visual studio 8\vc\include\stdlib.h(406) : error C2381: 'exit' : redefinition; __declspec(noreturn) differs
1> c:\program files\microsoft visual studio 8\vc\platformsdk\include\gl\glut.h(146) : see declaration of 'exit'
I'm using Nate Robins' GLUT for Win32 and get this error with Visual Studio 2005 or Visual C++ 2005 (Express Edition). What is the cause of this error and how do I fix it?
Cause:
The stdlib.h which ships with the recent versions of Visual Studio has a different (and conflicting) definition of the exit() function. It clashes with the definition in glut.h.
Solution:
Override the definition in glut.h with that in stdlib.h. Place the stdlib.h line above the glut.h line in your code.
#include <stdlib.h>
#include <GL/glut.h>
or this...
To fix the error, right click on the project name in the Solution Explorer tab and select Properties -> C/C++ -> Preprocessor -> Preprocessor definitions and append GLUT_BUILDING_LIB to the existing definitions, seperated by semicolons.
#include <iostream>
using namespace std;
void fun(int i)
{
cout<<"Called with int "<<i;
}
void main()
{
using df = decltype(&fun);
}
I am getting following syntax errors in Visual Studio,
Error 1 error C2143: syntax error : missing ';' before '=' c:\users\kpranit\documents\visual studio 2012\projects\sample\sample\sample.cpp 12
Error 2 error C2873: 'df' : symbol cannot be used in a using-declaration c:\users\kpranit\documents\visual studio 2012\projects\sample\sample\sample.cpp 12
Visual Studio 2012 which, based on your project directory, is the one you're using, does not support type aliasing.
It's a C++11 feature and does not make an appearance in the MSDN documentation, even for VS2013, though I think that may just be a doc error on their part - the Microsoft site for C++11 compatibility (look for "alias templates") lists it as being available under VS2013.
So, if you want to use that feature, you'll probably have to upgrade to the later compiler.
Although only having done a very little in C++ before I'm trying to compile the following chrome plugin so that I can see how it works and use that as a starting point to develop something similar: http://code.google.com/p/minimizetotray/source/browse/trunk/?r=17#trunk%2FDLL
So far I have taken the following steps: downloaded the source, opened it in MS Visual Studio Pro 2008, and obtained a few of SDKs and headerfiles it was asking for including the latest version of the NPAPI headers: http://npapi-sdk.googlecode.com/svn/trunk/headers/
Now I get the following errors when I try to compile and have no idea how to sort this.
Compiling...
JSMethods.cpp
c:\documents and settings\dell customer\desktop\dll\jsmethods.cpp(92) : error C2039: 'UTF8length' : is not a member of '_NPString'
c:\program files\microsoft visual studio 9.0\vc\include\plugin\npruntime.h(85) : see declaration of '_NPString'
c:\documents and settings\dell customer\desktop\dll\jsmethods.cpp(101) : error C2039: 'UTF8characters' : is not a member of '_NPString'
c:\program files\microsoft visual studio 9.0\vc\include\plugin\npruntime.h(85) : see declaration of '_NPString'
Etc...
Apart from those two errors it all seems dandy, its not asking for missing includes or anything. Any help appreciated!
Unless I'm mistaken on the latest SDK the _NPString struct is defined as...
typedef char NPUTF8;
typedef struct _NPString {
const NPUTF8 *UTF8Characters;
uint32_t UTF8Length;
} NPString;
And in your code you are calling UTF8length instead of UTF8Length (uppercase L).
Strangely I had this working before but I reinstalled my system, upgraded to w7 and now I can't seem to get this code to compile.
The problem is that I'm using winhttp.h in most of my application, but I have a simple FTP client object that I wrote using wininet.h functionality. I can't seem to get the application to compile now, no matter how/where I include which headers.
Currently I have in my stdafx.h:
#include <winhttp.h>
And in my ftp client .c
#include <wininet.h>
This compiles all objects successfully except for the FTP client object which fails with:
c:\Program Files\Microsoft Platform SDK\Include\WinInet.h(52) : warning C4005: 'BOOLAPI' : macro redefinition
c:\Program Files\Microsoft Platform SDK\Include\winhttp.h(45) : see previous definition of 'BOOLAPI'
c:\Program Files\Microsoft Platform SDK\Include\WinInet.h(270) : error C2143: syntax error : missing '}' before '('
c:\Program Files\Microsoft Platform SDK\Include\WinInet.h(270) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Any advice?
Ah got it, finally by moving the winhttp include into the cpp files and putting wininet into the ftp client header.
Most likely a clash between winhttp.h and wininet.h.
In my simple OpenGL program I get the following error about exit redefinition:
1>c:\program files\microsoft visual studio 8\vc\include\stdlib.h(406) : error C2381: 'exit' : redefinition; __declspec(noreturn) differs
1> c:\program files\microsoft visual studio 8\vc\platformsdk\include\gl\glut.h(146) : see declaration of 'exit'
I'm using Nate Robins' GLUT for Win32 and get this error with Visual Studio 2005 or Visual C++ 2005 (Express Edition). What is the cause of this error and how do I fix it?
Cause:
The stdlib.h which ships with the recent versions of Visual Studio has a different (and conflicting) definition of the exit() function. It clashes with the definition in glut.h.
Solution:
Override the definition in glut.h with that in stdlib.h. Place the stdlib.h line above the glut.h line in your code.
#include <stdlib.h>
#include <GL/glut.h>
or this...
To fix the error, right click on the project name in the Solution Explorer tab and select Properties -> C/C++ -> Preprocessor -> Preprocessor definitions and append GLUT_BUILDING_LIB to the existing definitions, seperated by semicolons.