This question already has answers here:
Possible problems with NOMINMAX on Visual C++
(4 answers)
Closed 7 years ago.
I want to use #define NOMINMAX in my Visual Studio C++ project using MFC, so that I can use std::min and std::max. However, when I put this line in my stdafx.h, I get following compile error:
c:\program files (x86)\windows kits\8.0\include\um\GdiplusTypes.h(475): error C3861: 'min': identifier not found
I am not using GDI+ intentionally, this is something MFC must be doing. Can the issue be fixed somehow, either by removing the GDI+, or by adjusting it to compile?
I don't work on Windows so I'm not used to dealing with this, and I'm not testing this, but I believe that answer is suggesting you do this:
#define NOMINMAX
#include <algorithm>
namespace Gdiplus
{
using std::min;
using std::max;
};
//... your other includes.
This will get the "proper" versions of min and max, and make them available without the std:: prefix (which seems to be how it is used in the GdiplusTypes.h header).
The winapi min and max are macros, so you can just #undef them after including the MFC or winapi headers:
#undef min
#undef max
Related
This question already has answers here:
M_PI works with math.h but not with cmath in Visual Studio
(7 answers)
Closed 4 years ago.
I'm trying to compile a library in C++ as dll windows with visual studio 2017.
I have all C++/H compiled with clang 3.8 for android and it works.
I created a new project as dynamic library with LLVM as platform toolset. Now I'm trying to build but there is an error :
Error C2065 'M_PI': undeclared identifier
This error is present in many .cpp files. All linked .h contains :
#include <cmath>
I replaced by :
#define _USE_MATH_DEFINES // for C++
#include <cmath>
But it change nothing. What can I do ?
This is a known issue, try defining _USE_MATH_DEFINES as a definition in your project properties instead of the file itself.
This can be found in project properties -> C/C++ -> Preprocessor -> Preprocessor definitions.
I use the armadillo library in visual C++ to take care of some matrix and vector operations. Here's what one of my cpp files looks like:
#include "stdafx.h"
#include <cmath>
#include <armadillo>
#include "buildRotMatrix.h"
using namespace std;
using namespace arma;
//code
When I compile I get the following warning:
1>CL : warning : detected 'min' and/or 'max' macros and undefined them;
1>CL : warning : you may wish to define NOMINMAX before including any windows header
I don't actually use min and max functions in the code but i'd like to get rid of the warnings. adding #define NOMINMAX hasn't worked and I haven't found other solutions. It's not clear to me where the conflict comes from since my understanding from google searches is people get it from including windows.h.
i need some linear algebra in my project and want use OpenBLAS for this. I downloaded the precompiled version (64bit version) and unpacked it to my projectfolder. In Visual Studio, i added include-, bin-, and lib-folder to my Project and ran the this example without problems.
Next, i wanted to look at LAPACK, so i added lapacke.h to the includes, which is in the same directory as cblas.h and is included in the official download. But now i get hundreds of errors, for every function, as if a lib file was missing or something. E.g. for this line
85 lapack_complex_float lapack_make_complex_float( float re, float im );
i get
PATH\include\lapacke.h(85): error C2146: syntax error: missing ';' before identifier 'lapack_make_complex_float'
I can't find any further information on how to set up OpenBLAS/LAPACK, they usually just say 'include the files', which i have. Otherwise the cblas example wouldn't run either. And the (relevant) examples i can find only use cblas.h, not lapacke.h
Can some tell me what i'm doing wrong?
The problem is that OpenBlas uses C99 _Complex by default. This is not supported by Visual C++. You can solve this by using standard library definitions before including lapacke.h:
#include <complex>
#define lapack_complex_float std::complex<float>
#define lapack_complex_double std::complex<double>
#include <lapacke.h>
Using std::complex is problematic unless OpenBLAS was built with LAPACK_COMPLEX_CPP otherwise the library uses a different complex type internally, usually C99 _Complex.
Modern versions of the Microsoft compiler (e.g. the one in VSTUDIO 2022) support a similar "_Complex" mechanism. Therefore I include the following header file prior to "lapacke.h"
#ifdef _MSC_VER
#include <complex.h>
#define LAPACK_COMPLEX_CUSTOM
typedef _Dcomplex lapack_complex_float;
typedef _Fcomplex lapack_complex_double;
#define lapack_complex_float_real(z) (real(z))
#define lapack_complex_float_imag(z) (imag(z))
#endif // _MSC_VER
See the lapack.h header file that ships with OpenBLAS how #define LAPACK_COMPLEX_CUSTOM overrides complex variable type definitions
(Visual Studio 2010 / Visual C++ / Windows 7)
example.cpp:
#include <Shlobj.h>
#pragma comment (lib, "Shell32.lib")
...
void example()
{
SHGetKnownFolderPath(...) // undefined
}
I'm doing everything according to documentation and what I see in other threads, but it still doesn't work.
I had exactly the same problem. Another project with the same code and ancillary files (but different includes) was working.
Putting #include <Shlobj.h> at the top of the file solved the problem.
It might not be replicable though, as it should have worked without doing that. Probably another Visual Studio bug.
Try putting following statement before all includes:
#define WINVER 0x0600
#define _WIN32_WINNT 0x0600
Since the documentation says it needs Vista/2008 minimum.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
error: ‘NULL’ was not declared in this scope
i'm having this code, which has been written in visual studio but i`m working in eclipse and i'm trying to make it compilable for eclipse and i throws me this error
..\heap.cpp:104:10: error: 'NULL' was not declared in this scope
code:
#include"heap.h"
using namespace std;
template<class T>
Heap<T>::Heap() // constructor
{
root = NULL;
size = 0;
}
Eclipse isn't a compiler, just an IDE. I'm guessing you're using it with another compiler than Visual Studio and the system headers are somewhat different, leading to your VC++ working includes to not include the declaration of NULL on <the other compiler>. As Martinho Fernandes said, you need to include <stdlib.h> or <cstdlib>, or some header that includes those ones. As the other question says, the C++ 11 way would be <stddef.h> or <cstddef>.