Visual Studio nested macro/template classes debugging aid - c++

I was trying to build the Goptical package (https://savannah.gnu.org/projects/goptical ) in windows using Visual Studio 2019. It uses DPP library (https://code.ssji.net/hg/ ) which throws errors when building under Visual Studio. The Linux build with gcc goes smooth as expected, but I need this on windows with visual studio.
The errors come up from delegate classes which are nested template classes further wrapped inside using macros. Tried debugging but visual studio does not seem to pinpoint the exact location of the error, but instead point to last line which triggered the error.
Is there any mechanism by which we can see the macro definitions rolled back step by step? Or, an intermediate output that we could examine to debug this step by step? Posting the offending code and error details below:
1> delegate(578,1): error C2059: syntax error: ','
1> delegate(578): message : see reference to class template instantiation 'dpp::delegate_bind<base,R(void),3>' being compiled
Code:
#if DPP_DELEGATE_ARGC >= 2
_DPP_DELEGATE(2)
_DPP_DELEGATE_FUNC(2)
_DPP_DELEGATE_MEMBER(2)
_DPP_DELEGATE_MEMBER_THIS(2)
_DPP_DELEGATE_BIND(1, 1, 1, _DPP_DELEGATE_BTDEFS(1, 0), _a0, a0);
_DPP_DELEGATE_BIND(2, 1, 1, _DPP_DELEGATE_BTDEFS(1, 1), a0, _a0);
_DPP_DELEGATE_BIND(3, 0, 2, _DPP_DELEGATE_BTDEFS(2, 0, 1), _a0, _a1);
#endif

I suggest that you could set Yes in Properties->C/C++->Preprocessor->Preprocess to file. Then, you could see the macro definitions in XXX.i file in the debug floder of the project.

Related

Is there any way to force visual studio to show me location of an error in *my* code, instead of pointing to the standard library?

I have a small piece of code that does not compile
Visual Studio shows me this error and points to xhash:
Error C2064 term does not evaluate to a function taking 1 arguments C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xhash 114
I know that error is somewhere in my code, probably related to unordered map, so template does not resolve. I'm wondering if there's a way to see which part of my code causes compilation error
The full build output will have many more lines, in the form ".. Instantiated from here...". Typically the last of these lines will point to your faulty code, possibly more if you wrote a template yourself.

Locating error in source which is boost related [duplicate]

This question already has answers here:
C++ Boost: what's the cause of this warning?
(6 answers)
Closed 2 years ago.
I'm porting an old project from Boost 1.48 to Boost 1.61. The project is compiled using MSVC 2013. There are several reported errors during build which I think are boost related but unfortunately the bug reports are not very helpful at all.
3> entry.cpp
4>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(2715): error C2220: warning treated as error - no 'object' file generated
4>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(2715): warning C4996: 'std::_Fill_n': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
4> c:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(2701) : see declaration of 'std::_Fill_n'
4> c:\boost\boost_1_61_0\boost\random\detail\polynomial.hpp(114) : see reference to function template instantiation '_OutIt std::fill_n<boost::random::detail::polynomial_ops::digit_t*,size_t,boost::random::detail::polynomial_ops::digit_t>(_OutIt,_Diff,const _Ty &)' being compiled
4> with
4> [
4> _OutIt=boost::random::detail::polynomial_ops::digit_t *
4> , _Diff=size_t
4> , _Ty=boost::random::detail::polynomial_ops::digit_t
4> ]
I cannot see anything in the above that helps me identify where the problem is, there are no line numbers and the snippet of code is not from the compiled file.
#Eljay, does it have a human readable text option I could locate in the IDE? – SPlatten 43 mins ago
The thing you posted IS human readable text. It actually describes a warning with a reference to documentation. ¯\(ツ)/¯ Maybe you can just tell the compiler you don't want to receive warnings
In addition, you can use the keywords to google additional information:
C++ Boost: what's the cause of this warning?
Many libraries in addition already have a warning-suppression header (look for e.g. boost/iostreams/detail/config/disable_warnings.hpp or boost/random/detail/disable_warnings.hpp). The fact that known benign warnings "slip through" might indicate that the library needs to update their suppressions, OR you might need to upgrade your boost version.

Visual Studio C++ NPAPI plugin with Twain support

I want to make a Google Chrome plugin that use Twain to remote control a Digital Camera.
I want this to run on Windows and I'm using Visual Studio Express 2012 C++.
I have this sample for NPAPI and this sample of CppWrapper for Twain which has 3 interesting files (TwainCpp.cpp TwainCpp.h twain.h)
Before doing anything, I want to merge these two projects.
First step: putting twain.h in the npsimple project which failed, twain.h errors caught.
Second step: putting CppTwain in npsimple, which also failed because twain.h "contains" errors.
Problem is that when I create an empty project, and put twain.h in it, there is no error! So I tried to put npsimple files in that empty project, and this time I get error from npsimple files..
Error type :
I have this code in twain.h :
#ifdef _MSWIN_
typedef HANDLE TW_HANDLE;
typedef LPVOID TW_MEMREF;
and I get plenty of errors like :
error C2146: syntax error : missing ';' before identifier 'TW_HANDLE'
How can I merge these projects?
HANDLE is an unspecified type because you don't include anything that is specificing it. You'll want to include windows.h.
Obviously there is no error when you add only the twain.h header file to the empty project - you haven't added any sources to compile, hence there can be no compilation errors.

error PRJ0019: A tool returned an error code from "moc'ing qt/gui/QFloatSlider.h

I'm building a big C++ project on Visual Studio 2008 I'm getting this error message and I don't understand it. Is it a failure to include the .h file?
I know this thread is dated, but I had the exact same problem with a C++ project on Visual Studio 2008, here was my resolution...
One of the things the VS2008 compile told me was that it generated a log on:
"file://C:\Documents and Settings\adam\My Documents\Visual Studio 2008\Projects\MyProject\Debug\BuildLog.htm"
This log demystified the problem for me.
In my case, it had the following explicit error message:
c:\Documents and Settings\adam\My Documents\Visual Studio 2008\Projects\MyProject\MyProject\UnitTests.h(36): Error: Meta object features not supported for nested classes
The problem had been that INSIDE the class I defined here, I defined yet another internal (nested) class, that included the QT macro (so I could define signals and slots):
Q_OBJECT
Obviously QT wasn't happy that this class was nested/internal in another class. So I simply moved the class definition outside (IE made it non-internal).
No, it is not.
Did you look up the error code error PRJ0019.

static_assert not working in Visual C++ 10

I was under impression Visual C++ 10 had built-in static_assert. However when I compile the following
void test()
{
static_assert( sizeof( char ) == 1, "" );
}
I get
error C3861: 'static_assert': identifier not found
What am I doing wrong and how do I use static_assert in Visual C++ 10?
I was under impression Visual C++ 10 had built-in static_assert.
It indeed does and this compiles perfectly fine for me:
int main(){
static_assert( sizeof( char ) == 1, "" );
}
Do you have any other errors in your code? Maybe this error is a result of the chain of other erros.
The reason was Visual Studio was set up to use Visual C++ 9 compiler (the one which is shipped with Visual Studio 2008). I don't know how it happened, perhaps the wizard configuring Visual Studio imported paths to the previous version.
The settings is changed in project properties - on "VC++ Directories" pane. The easy way to check which compiler is invoked is to add -Bv option to the compiler command line which will make the compiler report its version.