Boost in Visual Studio 2010, IntelliSense error - c++

I would like to see if you could orient me.
It happens that I compiled and referenced the boost libraries in order to use them with Visual Studio 2010. When building my test project I get these two IntelliSense errors
1 IntelliSense: #error directive: "Macro BOOST_LIB_NAME not set (internal error)" c:\boost_1_43_0\boost\config\auto_link.hpp
2 IntelliSense: #error directive: "some required macros where not defined (internal logic error)." c:\boost_1_43_0\boost\config\auto_link.hpp
Checking the auto_link.hpp header file the first error is in this line
#ifndef BOOST_LIB_NAME
# error "Macro BOOST_LIB_NAME not set (internal error)"
#endif
Tracing the definition of BOOST_LIB_NAME, it seems that is defined in config.hpp by boost_regex, which code I am including below
#if !defined(BOOST_REGEX_NO_LIB) && !defined(BOOST_REGEX_SOURCE) && !defined(BOOST_ALL_NO_LIB) && defined(__cplusplus)
# define BOOST_LIB_NAME boost_regex
# if defined(BOOST_REGEX_DYN_LINK) || defined(BOOST_ALL_DYN_LINK)
# define BOOST_DYN_LINK
... more code
and strangely when I point to BOOST_LIB_NAME it defines BOOST_LIB_NAME and the IntelliSense errors disappear.
My program builds and executes fine using the Boost:Regex library -- with or without the Intellisense errors; however, I do not understand why these IntelliSense errors appear in the first place, and second why pointing the macro in the config.hpp defines BOOST_LIB_NAME.
Any guidance will be greatly appreciated.
Thanks,
Jaime

The Visual Studio IntelliSense error checking for C++ is not perfect and often reports errors that aren't really errors (those are links to three false positives that I've found and reported; they aren't related to your problem, though).

Related

Visual Studio 2019 C++ cross-platform directives #if #else ignored

I am using Visual Studio 2019 (updated to date, running on Windows) to rewrite old program code in cross-platform C++ language (Windows & Linux).
In the code, I am using the pre-compilation directives #if, #else, #endif to toggle platform-specific blocks of code.
Example:
76 #ifdef WINDOWS_OS
77 errno_t success = fopen_s(&arq, logConfigFileName.str().c_str(), "rt");
78 #else
79 arq = fopen(logConfigFileName.str().c_str(), "rt");
80 #endif
In the Visual Studio editor, everything looks correct (see screenshot).
Project selected: Windows, Debug, x86.
Lines 1 and 2 appear normally (active and without error indication) and lines 3 to 5 appear in gray indicating they are disabled, that is, it appears as it should be.
However, when compiling I get the error:
Error C4996 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
error on line 79, line that should be ignored by the compiler.
How can I fix this, so that my code can be compiled for both platforms without problems ?
You don't need to create / define macros to identify the OS.
Compiler do it already. See C++ compiling on Windows and Linux: ifdef switch for the list.
Problem solved.
The problem was in the definition of the WINDOWS_OS flag, I had defined it in the code with the #define WINDOWS_OS statement.
The IDE recognized the instruction, but the preprocessor didn't.
The solution was to include the WINDOWS_OS flag in the list of definitions in: Project Properties -> Settings Properties -> C++ > Preprocessor - Preprocessor Settings.
To me this does not make sense, my everyday IDE is Rad Studio and in it if you set a compiler directive in the code it is valid for everything.
Thank you all.

How to add predefine macro for nvcc?

I am currently compiling a Qt project which integrates OpenMesh and CUDA together. Since I have to use nvcc to compile the project, I found an error from the OpenMesh:
J:\OpenMesh2.4\include\OpenMesh/Core/System/compiler.hh(109) : fatal error C1189:
#error : "You have to define _USE_MATH_DEFINES in the compiler settings!"
Since the compiler is nvcc not vc compiler, even I add the macro in the "preprocessor definitions", the error still appears. I just wonder if there is a way to add this macro for the nvcc?
I also tried to manually add this macro in one of my header which include the open mesh headers. The above error is gone but the compile gives another strange error about the source code of openmesh.
Found the solution: add -D followed by the macro in the nvcc flag...

Where is _CPPLIB_VER defined and is it modifiable in visual studio

I got an error "cannot open include file 'initializer_list', but I have not included initializer_list anywhere in the code.
#if !defined(BOOST_NO_0X_HDR_INITIALIZER_LIST)
#include <initializer_list> // error C1083: Cannot open include file: 'initializer_list': No such file or directory d:\boost\unordered\unordered_set.hpp
#endif
Then I use 'show includes' options and find BOOST_NO_0X_HDR_INITIALIZER_LIST is in dinkumware.hpp:
// C++0x headers implemented in 520 (as shipped by Microsoft)
//
#if !defined(_CPPLIB_VER) || _CPPLIB_VER < 520
# define BOOST_NO_0X_HDR_INITIALIZER_LIST
#endif
Now I know _CPPLIB_VER must be defined somewhere and the value is greater than 520. Where is it and can I change the value?
It is just the version check that is wrong. The current VS2012 C++ library version is 540, initializer lists will be supported in the next release. Coming very soon.
The Boost team just didn't have a time machine to guess the correct version. They picked the version number available at the time, the one for VS2010. Albeit that they got the test wrong, 520 didn't have it either so it should have been <=. Short from updating Boost, editing the file would have been a quick fix.

c++ pragma #error giving an error

I recently came across a piece of code which uses
the pragma directive
#error Error ! Define [_HOS_ | _HOS_OV_ | _HOV_].
This code is from the ADOC-C jacobian computation routine.
The problem is that in C++ visual studio 2010 there is a curly red line below the #error indicating there is some problem within that line.
The code also fails to compile giving error message at that line
Is there a syntax issue or are those [_HOS_ | _HOS_OV_ | _HOV_] not defined at that point, and intelliSense knows that resulting in curly red line indicating some problem?
The author of that code intended to have an error when not at least one of the tags named in the error message is defined. You should have a look at the documentation of the ADOC-C stuff if s.th. is mentioned there about these tags.
The intent of the #error directive is to create compile errors. It's usually a way for the programmer who wrote the code to tell the programmer that's trying to compile and use it "You did something wrong, this won't work!". The string following the directive is the message that should be shown to the programmer trying to compile the code.
You should check what directives are around this one, for example are there any #ifdefs that cause it to be executed. Then you should lookup the conditions in which they executed (e.g. not defining the things the error lists) and look for a way to make them go away.
The problem is that in C++ visual studio 2010 there is a curly red line below the #error indicating there is some problem within that line.
Visual Studio 2010 does not recognize #error preprocesor syntax anymore. It only recognize #pragma warning

iphlpapi / ifdef.h

I'm trying to use iphlpapi (GetAdapterInfo) and am having trouble compiling the code. I have iphlpapi.h from SDK 7 and have added the appropriate path to the include files in visual studio.
I get the following error...
c:\program files\microsoft sdks\windows\v7.0\include\ifdef.h(154) : error C2146: syntax error : missing ';' before identifier 'NET_IFTYPE'
The lines in ifdef where this occurs are shown below.
typedef NET_LUID IF_LUID, *PIF_LUID;
typedef ULONG NET_IFINDEX, *PNET_IFINDEX; // Interface Index (ifIndex)
typedef UINT16 NET_IFTYPE, *PNET_IFTYPE; // Interface Type (IANA ifType)
I finally figured out how to get this to work so I'm putting this here for others who might stumble upon it.
First, I'm using visual c++ version 6.0 with the 2003 sdk. I added the sdk as the first choice using TOOLS->OPTIONS->DIRECTORIES. Adding the include winsock2.h caused about 60 redefinition errors. I found several sources telling me that the winsock2 include had to precede the windows.h include. My windows.h include was generated for me by VC++ in the precompiled header stdafx.h so I moved the winsock2.h include there. I now can compile and run my program!
According to this page, it looks as though you might need to make sure winsock2.h is included first. I'm guessing that it defines some of those types.
Also, the MSDN page for NET_LUID says it requires Vista at a minimum. Make sure that's true.