HYPRE blas build error with VS 2015 - c++

I installed VS 2015 Professional. I installed the latest HYPRE, from the Lawrence Livermore website. I then configured it using CMake and proceeded to build, and I started getting BLAS (dnrm2.c) build errors:
2> dnrm2.c
2> 1>
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\math.h(454): error C2059: syntax error: '('
The line of code triggering the error in dnrm2.c is:
#include "math.h"
which points to the file:
c:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\math.h
I looked up this error and found some suggestions such as this to change the include to:
#include <cmath>
and to edit the HYPRE project settings in: Configuration > C/C++ > Advanced > Compile As to Compile As C++ (/TP)
which I did, but I still see same error, since apparently the same header path to math.h is included from cmath as well:
#else /* _STD_USING */
#include <math.h>
#endif /* _STD_USING */
I've even tried re-installing VS 2015 without any luck (same errors). Appreciate any ideas on what's going on here, and how to resolve this. I guess I could try a minimalist example in VS 2015 that includes the math.h and report back, if that helps.
EDIT
My minimalist example:
#include "math.h"
int main() {
double d1 = sqrt(4.0);
float d2 = abs(4.0);
return 0;
}
appears to be building OK. I tried to set the project the same way to Compile as C (or C++, didn't matter). This doesn't really help me though.

OK, the problem here is with HYPRE source it looks like. They have this in a file f2c.h included before including the math.h:
//#undef abs
//#define abs(x) ((x) >= 0 ? (x) : -(x))
//#endif
When I commented it out (since this is already defined in the standard), then it gets past that build error. Of course I run into other build errors. I'm trying to tackle those separately.
EDIT: It's not as simple as that because they (HYPRE) actually rely on their own definition of abs. So I had undo the above and change the order of some includes so that the undef actually made sense. Either way, this is a HYPRE source code problem.

If you succeed in compiling the HYPRE on VS2015, Could you send your VS2015 program to me!
My major is Geophysics modeling and inversion.
MY email is schoolhui#hotmail.com
Thank you very much!

I've just commented
_Check_return_ int __cdecl abs(_In_ int _X);
in
c:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\math.h
and then HYPRE was successfully compiled!
Then, I've uncommented "abs".

Related

VS 2019 C++ Missing symbols in pch.h

I've seen the related question regarding "_T()" not found. I have a console app. The "Debug" version of the console app compiles and runs fine. When I try to compile it as a "Release" version I first get hundreds of _T() Not Found. I tried adding #include <tchar.h> to pch.h which was completely ineffective. Based on what I found in the question about undefined _T() I read, I added the text
#ifdef _UNICODE
#define _T(x) L ## x
#else /* _UNICODE */
#define _T(x) x
#endif /* _UNICODE */
#include <tchar.h>
#include "framework.h"
to pch.h before #include "framework.h". The compiler noticed but now complained as follows:
Error C2039 '_tcscpy_s': is not a member of '`global namespace'' Anon C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333\atlmfc\include\atlchecked.h 111
plus a few hundred other similar messages.
This is not the first time this has happened. Every project I've tried to build with VS2019 eventually has this happen to it. And, this happens compiling a completely pristine "pch.h" that I had not (initially) modified at all before this error occurred.
I've already tried deleting VS and reinstalling it. My OS is Windows 10 (64-bit)
The list of Include directories is the same for both the Debug and Release configurations.
I feel that this must be related to something in the way Visual Studio is configured, but mostly I need help fixing it. The compiler seems to be getting tangled up in its own header files. What can I do to analyze/fix this?
ADDENDUM:
Just since I started writing this question I have gone back to my project and tried the Debug version again. Now it is getting the same errors. And I made no changes since the previous time I built it earlier today.

identifier "DDRB" is undefined - VS code / Visual studio

I am getting the following error when using the identifier DDRB:
identifier "DDRB" is undefined
But, when I click “go to definition”, the IDE does shows that it can find them. The code also compiles without any problem. I was using VScode first and setting intellisense to "tag parser" did work, but it also got rid of the error checking. So, I switched over to Visual Studio, but the issue remains. In both cases I included the AVR library.
I have googled quite a bit and found some solutions, but most were outdated or did not work. What can I do to resolve this issue?
"minimal reproducible example:"
#include <avr\io.h>
int main() {
DDRB |= (1 << DD3);
}
I can reproduce same issue in VS2017, and this one can be resolved by adding the #define __AVR_ATmega32U4__ above the #include <avr\io.h> like this:
#define __AVR_ATmega32U4__
#include <iostream>
#include <avr/io.h>
int main()
{
DDRB |= (1 << DD3);
}
After adding the macro definition, VS Intellisense option can recognize them well and the issue goes away. More details refer to Kissiel's reply. Thanks to him!
If you don't want to paste this definition into almost every file:
press f1
find C/C++; Edit configurations (UI)
paste your mcu name in Defines section e.g __AVR_ATmega32U4__
It worked for me in vs code.

Using OpenBLAS LAPACKE in Visual Studio

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

OpenCL 2.x(C++ bindings): undefined identifier

Edit: adding OpenCL.lib in library files section of visual studio solved the problem.
With cl2.hpp from this github repository pointed by khronos site, I get 60-70 similar errors when I try to compile a C++ dll project with OpenCL-C++-implementation functions to export.
'CL_DEVICE_QUEUE_ON_HOST_PROPERTIES': undeclared identifier
// I'm not using this, I'm newly converting a v1.2 C++ binding-based
// project to a v2.0 one
starting of the file is:
using namespace std;
#define __CL_ENABLE_EXCEPTIONS
#include <CL\cl2.hpp>
and the remaining lines are not underlined with red(visual studio). There are some compile time constants I need to add maybe, but I don't know which constants.
What is missing?
this code(there isn't any other code in project) also gives same error:
#include <CL\cl2.hpp>
I had the same errors and something that worked for me was to add the following prior to #include <cl2.hpp>
#define CL_HPP_TARGET_OPENCL_VERSION 120
#define CL_HPP_MINIMUM_OPENCL_VERSION 120
#include <cl2.hpp>

Boost build error with websocketpp and MySQL on Windows

I am trying to build a C++ app that uses both websocketpp and MySQL. I have encountered 2 build problems using VS 2010 C++ Express.
1) A problem with the boost libraries. It produces many errors like this:
1>c:\program files (x86)\boost\boost_1_50\boost\thread\win32\thread_data.hpp(210): error C2146: syntax error : missing ')' before identifier 'rel_time'
Here's the relevant snippet from thread_data.hpp starting with line 210:
inline BOOST_SYMBOL_VISIBLE void sleep(TimeDuration const& rel_time)
{
interruptible_wait(detail::pin_to_zero(rel_time.total_milliseconds()));
}
2) A conflict with the word VERSION which is documented here and I believe is independent.
To make a clear and simple example of the boost build problems, I'm using the websocketpp example: echo_server.cpp to which I added these includes:
#include "stdafx.h"
Boost lib includes recommended by "Building a program with websocketpp" on the websocketpp site.
#include <boost/regex.hpp>
#include <boost/random.hpp>
#include <boost/system/api_config.hpp>
#include <boost/system/config.hpp>
#include <boost/system/error_code.hpp>
#include <boost/system/system_error.hpp>
#include <boost/system/windows_error.hpp>
and the MySQL header includes. Adding these 2 boostincludes triggers the build errors. If I comment out these 2 includes, it builds without errors:
#include <my_global.h>
#include <mysql.h>
Any suggestions on how to deal with the boost problems?
I don't think this is the same build problem as this one, "Trying to build websocket++ with MinGW: last few linker errors — what could it be?"
Concerning the first error, check if there are any macros interfering with the code. Right-click and go to definition or #define the macro yourself at the beginning of the file and see where it gets redefined. In really hard cases, look at the preprocessor output via a compiler flag.
Concerning the rest, you don't provide any versions for Boost and MySQL. Then, there is my_global.h (or is that part of MySQL?) and stdafx.h, which are both under your control but you don't show them here. Also, try to reduce the issue to the smallest possible piece of code. In short, provide a reproducible example.