Attempt to access private member in dynamic_bitset - boost

I am using Visual Studio 2017 to build LucenePlusPlus which in turn uses boost/dynamic_bitset.
The following code in LucenePlusPlus
const uint64_t* BitSet::getBits() {
return bitSet.empty() ? NULL : static_cast<const uint64_t*>(&bitSet.m_bits[0]);
}
generates the following fatal compiler error:
1>g:\luceneplusplus\src\core\util\bitset.cpp(20): error C2248: 'boost::dynamic_bitset<uint64_t,std::allocator<Block>>::m_bits': cannot access private member declared in class 'boost::dynamic_bitset<uint64_t,std::allocator<Block>>'
1> with
1> [
1> Block=uint64_t
1> ]
Suggestions?

I have traced the code for my boost 1_75_0 and I see it has a define to conditionally reserve access to friends:
#if defined(BOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS)
#define BOOST_DYNAMIC_BITSET_PRIVATE public
#else
#define BOOST_DYNAMIC_BITSET_PRIVATE private
#endif
So it looks like you should be able to add -DBOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS to the compiler defines to fix this.
In fact, my LucenePlusPlus tree already contains it in
include/config_h/Config.h.in line 107:
#define BOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS
Previously ("rebuilt cmake buildsystem") this apparently
came from include/Config.h.cmake, where it was always present, unconditionally all the way since 2010:
What Can You Do?
Maybe you are not including the required headers that include the config? Also check any interfering precompiled header settings.
If you have boost/dynamic_bitset.hpp included BEFORE including LucenePlusPlus headers at any point you will run with the wrong config.
This is especially bad if you don't detect it because that would violate the ODR rule

Related

How to use lemon graph library on Omnet++ projects?

I am trying to design a network(Random Graph) in omnet++ where I want to parse the network nodes using Lemon Graph Library. I have installed the library and it works fine if I try to compile any normal c++ file with nodes and edges in any graph using command line g++ -o file file.cpp/cc -lemon. But when i tried it with one of my omnet++ project(which has nothing in it now) the code is as below
#include <omnetpp.h>
#include <iostream>
#include <lemon/list_graph.h>
using namespace lemon;
using namespace std;
class Facility : public cSimpleModule
{
protected:
virtual void initialize();
virtual void handleMessage(cMessage *msg);
};
Define_Module(Facility);
void Facility :: initialize(){
}
void Facility :: handleMessage(cMessage *msg){
}`
the include headers are in angle brackets(not to be confused with double quotes). So when i build the code I get the following errors:
Description Resource Path Location Type
‘class cEnvir’ has no member named ‘push_back’ PSUC line 686, external location: /usr/local/include/lemon/bits/graph_extender.h C/C++ Problem
‘class cEnvir’ has no member named ‘push_back’ PSUC line 687, external location: /usr/local/include/lemon/bits/graph_extender.h C/C++ Problem
‘test’ does not name a type test.cc /ztest line 9 C/C++ Problem
invalid use of qualified-name ‘cSimulation::getActiveEnvir’ PSUC line 69, external location: /home/vijay/omnetpp-4.6/include/cenvir.h C/C++ Problem
make: *** [out/gcc-debug//psuc.o] Error 1 PSUC C/C++ Problem
make: *** [out/gcc-debug//test.o] Error 1 ztest C/C++ Problem
no matching function for call to ‘lemon::AlterationNotifier<lemon::GraphExtender<lemon::ListGraphBase>, lemon::ListGraphBase::Arc>::add(cEnvir&)’ PSUC line 688, external location: /usr/local/include/lemon/bits/graph_extender.h C/C++ Problem
Why doesn't the Omnet++ code get compatible with Lemon graph Library?
OMNeT++ includes a macro definition for ev in cEnvir.h (which is included from omnetpp.h)
#define ev (*cSimulation::getActiveEnvir())
Because you include omnetpp.h before graph_extender.h, this macro is expanded in the library's header file, which conflicts with its use as a variable name in
ev.push_back(Parent::direct(edge, true));
A simple solution would be to include graph_extender.h before omnetpp.h, so the macro is not yet defined when graph_extender.h is read. If this is not possible, you might have some luck with manually undefining the macro before (and possibly restoring the definition after), as follows.
#pragma push_macro("ev")
#undef ev
#include "graph_extender.h"
#pragma pop_macro("ev")

Error during compilation of the code using make file in VC++

I am using below snippet in my code.
//from Vista WinNT.h
//
typedef struct _TOKEN_MANDATORY_LABEL {
SID_AND_ATTRIBUTES Label;
} TOKEN_MANDATORY_LABEL, *PTOKEN_MANDATORY_LABEL;
When I build this through VS2005 it give no error. But when I am building using make file i am getting below error in cmd:
Test.cpp(337) : error C2011: '_TOKEN_MANDATORY_LABEL' : 'struct' type redefinition
C:\Program Files\Microsoft SDKs\Windows\v6.1\include\winnt.h(7351) : see declaration of '_TOKEN_MANDATORY_LABEL'
I am using Opus software to use make file. Please let me know if I am missing something or needs to add some libs to overcome this error.

Linking to winmm.dll in Visual Studio 2013 Express for mciSendString

I am trying to use mciSendString in visual studio express 2013 (Visual C++) but I keep getting an error
Error 1 error C3861: 'mciSendStringA': identifier not found
I assume this i because I have not linked to the correct dll, but I cannot find any details online or on msdn about how to link to the dll. It seems quite strange that there wouldn't be more obvious documentation about this. Can someone tell me how to link to the dll?
EDIT:
Here is the code I am trying to run:
#include <Windows.h>
#include <iostream>
#include <mmsystem.h>
extern char command1[] = "open C:\\boing.mp3 type MPEGVideo alias 0";
extern char command2[] = "play 0 from 0";
int main()
{
mciSendStringA(command1, NULL, 0, 0);
mciSendStringA(command2, NULL, 0, 0);
}
To make mciSendString() to work, you need to link to winmm.lib.
Just adding winmm.lib to Project Properties > Linker > Input > Additional Dependencies will be fine.
Looking at mmsystem.h (admittedly from the V7.1A Windows SDK, which is the most recent I have installed), I can see that there's a #ifdef _WIN32 block in there. If _WIN32 is not defined, then mciSendStringA is not declared. Instead mciSendString is declared.
Check your project options and ensure that both WIN32 and _WIN32 are defined. I'm guessing that you started from a console project, rather than a Windows Application project, and that at least one of those isn't defined.

Unknown error when compiling Clang 3.3 with Mingw

I'm not able to compile clang(3.3) using MinGW 4.8.1. The following error always pops-up when 70% build is complete:
clang/lib/Basic/FileManager.cpp includes sys/stat.h, which defines #define stat _stat64i32 (actually there are a few other defines in between, but you get the idea ;)
clang/include/clang/Basic/FileManager.h does not include sys/stat.h; instead only has a forward-declaration.
Hence, while parsing the header, the forward declaration is used (struct stat)
But when it finally arrives at the implementation, the preprocessor will kick in and replace struct stat with struct stat64i32. Hence the mismatch.
The best solution would be to change the forward declaration in the header to instead include sys/stat.h. (I didn't actually test if it will compile then)
The current trunk does not contain the code anymore.
Update: regarding off64_t. This is defined in _mingw_off_t.h these days as:
#ifndef _OFF64_T_DEFINED
#define _OFF64_T_DEFINED
__MINGW_EXTENSION typedef long long _off64_t;
#if !defined(NO_OLDNAMES) || defined(_POSIX)
__MINGW_EXTENSION typedef long long off64_t;
#endif
#endif /*_OFF64_T_DEFINED */
So you probably want to define _POSIX before including io.h (or stdio.h)

IntelliSense: argument of type "_TCHAR *" is incompatible with parameter of type "const char *"

Sorry for asking such a beginner question but I'm really new to openCV and VC++2010. I searched the net for an answer but I did not get an appropriate one.
Building the first project "First Program-Display a Picture" of the OReilly-LearningOpenCV book, I encountered these errors:
1-error C2664: 'cvLoadImage' : cannot convert parameter 1 from '_TCHAR *' to 'const char *'
2-IntelliSense: argument of type "_TCHAR *" is incompatible with parameter of type "const char *"
here's the code:
#include "stdafx.h"
#include "opencv\highgui.h"
int _tmain(int argc, _TCHAR* argv[])
{ IplImage* img = cvLoadImage( argv[1] );
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage( "Example1", img );
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "Example1" );
system("pause");
return 0;
}
and here's the message that I get from Microsoft Visual Studio 2010:
1>------ Build started: Project: FirstProgram_DisplayAPicture3, Configuration: Debug x64 ------
1>Build started 7/6/2013 11:13:00 AM.
1>InitializeBuildStatus:
1> Touching "x64\Debug\FirstProgram_DisplayAPicture3.unsuccessfulbuild".
1>ClCompile:
1> All outputs are up-to-date.
1> FirstProgram_DisplayAPicture3.cpp
1>FirstProgram_DisplayAPicture3.cpp(9): error C2664: 'cvLoadImage' : cannot convert parameter 1 from '_TCHAR *' to 'const char *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.68
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Additional information that may be required:
I have made a win32 Console Application and in the second page of the wizard I have chosen precompiled header setting.
I have changed the platform of the project to x64 because I'm using win7x64 as the OS.
I have linked openCV library to my project properly.
I have just introduced highgui.lib as the additional dependencies
Any help would be appreciated.
What can I do to solve the two errors?
Edited section:
Note that these errors occur in line 6, I mean the line IplImage* img = cvLoadImage( argv[1] );
My edited section based on Roger Rowland's suggestion:
Based on what Roger Rowland said, I changed the Character Set property of the project to Not Set. The two errors mentioned above got solved but these errors rose up.
error LNK1120: 1 unresolved externals
error LNK2019: unresolved external symbol cvReleaseImage referenced in function main
How can I solve the problem?
Your project is configured for Unicode which means that the _TCHAR macro evaluates to wchar_t, which is a 16 bit UTF-16 data type on Windows. But the library you are calling accepts 8 bit char data.
So, you will need to make both sides of the interface match. Lots of ways to do that. The obvious options are:
Change your project to target ANSI (change the character set to multi byte in the VS project configuration).
Convert the input argument from UTF-16 to ANSI before calling the library.
It seems to me to be needlessly complex to use _TCHAR these days. That was useful when we needed to support Win9x (no Unicode support) and WinNT (supports Unicode) from a single code base. But I expect that nowadays you are targeting NT based systems and so you are safe to assume support for Unicode. In which case you can use wchar_t, wstring etc.
On the other hand, perhaps this is just a simple program for your personal use. In which case, since your library wants 8 bit characters, maybe it's simplest for you to target ANSI.
But either way I rather suspect that _TCHAR is just going to confuse you. I'd abandon that if I were you.
One final point is that you mention that you target x64 since your system is 64 bit. Do be aware that 64 bit systems can run 32 bit code perfectly well. If you want your program to be capable of running on a 32 bit system, and you don't have a pressing need to run under 64 bit, then it may be easier to target x86.
Your edit to the question asks a separate question, which I'll attempt to answer in spite of my reservations.
The unresolved external symbol error indicates that the linker could not resolve that particular symbol. In order for the linker to resolve it, it needs to be passed the .lib file that defines that symbol. You should double check that you have included all required .lib files in your additional dependencies. From what I can glean, there are multiple .lib files for OpenCV and you are probably missing the one which defines cvReleaseImage.
In my case I was including a header file twice.
I modified my library to be like:
#ifndef MY_LIB
#define MY_LIB
// code
#endif

Resources