Conflict between OpenCV and Boost filesystem - c++

I'm having a problem with Boost libraries, particularly filesystem when used with OpenCV. Apparently the problem is similar to the one described in Conflict between Boost, OpenCV and Eigen libraries?. In that particular case the problem was solved by preceding the "using namespace" statement with all the "#include" statements. In my case, this was done in this way from the beginning.
I'm using OpenCV 2.4.3 and Boost 1.48 (already tried with 1.52 having the same exact problem). The programming is being done in Windows 7 (64 bit) using Eclipse CPP plugin and MinGW.
When trying to build my program I get the following errors:
C:\Boost\boost_1_48_0/boost/type_traits/decay.hpp:28:66: error: 'cvflann::<anonymous enum>' is/uses anonymous type
C:\Boost\boost_1_48_0/boost/type_traits/decay.hpp:28:66: error: trying to instantiate 'template<class T> struct boost::remove_reference'
C:\Boost\boost_1_48_0/boost/type_traits/decay.hpp:38:17: error: 'cvflann::<anonymous enum>' is/uses anonymous type
C:\Boost\boost_1_48_0/boost/type_traits/decay.hpp:38:17: error: trying to instantiate 'template<class T> struct boost::remove_reference'
In my case the using namespace statements are after the include statements:
#include <opencv2/opencv.hpp>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <vector>
#include <boost/filesystem.hpp>
#include <boost/multi_index_container.hpp>
using namespace std;
using namespace cv;
using namespace boost::filesystem;
Any idea in how to solve this problem will be greatly appreciated :D:D:D
Regards,
Luis

I suggest you remove the section:
using namespace std;
using namespace cv;
using namespace boost::filesystem;
and use the scope operator :: in code.
Here's an example of these 2 different modes.

Related

Cannot resolve namespace std in Android Studio

I have a native library for an Android app. When I load the entire C++ project in Android Studio, some errors are thrown by the IDE saying:
cannot resolve namespace std and cannot find any C++ headers.
#include <fstream>
#include <iostream>
#include <map>
using namespace std;
For all of the above code, fstream, iostream, etc is being marked red and shows cannot find. Any workaround to fix the above issue?

Using declaration "not found" in mongodb c++ driver

I'm using the mongo-cxx-driver-r3.1.1 based on mongo-c-driver-1.6.2.
Using the latest examples provided on github, I managed to find how to connect the database and how to save documents.
I'm struggling to fetch results using a filter following the informations provided in the mongocxx/query.cpp example.
There's a lot of call to a make_document method but I have no class/method/template in the bsoncxx namespace with that name (same problem with make_array).
Heres's the includes, the using directives and using declarations :
#include <bsoncxx/builder/basic/document.hpp>
#include <bsoncxx/builder/basic/array.hpp>
#include <bsoncxx/builder/basic/kvp.hpp>
#include <bsoncxx/types.hpp>
#include <bsoncxx/json.hpp>
#include <bsoncxx/stdx/make_unique.hpp>
#include <bsoncxx/stdx/optional.hpp>
#include <bsoncxx/stdx/string_view.hpp>
#include <mongocxx/instance.hpp>
#include <mongocxx/pool.hpp>
#include <mongocxx/stdx.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/logger.hpp>
#include <mongocxx/uri.hpp>
#include <mongocxx/exception/exception.hpp>
#include <mongocxx/options/find.hpp>
using namespace mongocxx;
using namespace bsoncxx;
using bsoncxx::builder::basic::document;
using bsoncxx::builder::basic::kvp;
using bsoncxx::builder::basic::sub_document;
using bsoncxx::builder::basic::sub_array;
using bsoncxx::builder::basic::array;
using bsoncxx::types::value;
using mongocxx::result::insert_one;
The using declarations "not found" :
using bsoncxx::builder::basic::make_array;
using bsoncxx::builder::basic::make_document;
Am I missing something obvious ?
Are there more recent examples ?
Your code looks right, as you included all necessary header files needed for make_document and make_array.
You said in your comment, that the document.hpp doesn't contain the make_document and the array.hpp doesn't contain the make_array template.
This is right for the release mongo-cxx-driver-r3.1.1.
In the current master branch the header files exists as you can see if you follow the source links for them: document.hpp and array.hpp. The examples you use are probably for the new master branch as they are also from a current branch from git.

line_descriptor.hpp is included, but KeyLine and also BinaryDescriptor are still undefined

I have been using OpenCV 3.0 that are combined with the extra modules using CMake 3.5. I am using Visual Studio 2012 32bit as my IDE.
However, i cannot seem to use both KeyLine and also BinaryDescriptor. They give me error which is "identifier KeyLine is undefined". I have set the Paths and also library setting.
#include <opencv2/opencv.hpp>
#include <opencv2/line_descriptor.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main( void ) {
Ptr<BinaryDescriptor> bd = BinaryDescriptor::createBinaryDescriptor();// this line gives error
vector<KeyLine> lines; // same as this
}
I have tried the other header, for instance the tracking.hpp. I am able to define:
Ptr<Tracker> tkr;
Without having the Tracker giving me error.
Anyone know if the error is caused during CMake process or i miss out something?
I just had the same problem, and stumbled upon your question.
The answer I just found out is you have to add,
using namespace line_descriptor;
at the top along with cv namespace.Got this hint from line_descriptor.hpp source code.

apache Thrift TNonblockingServer Error

I've been following Thrift C++ wiki tutorial. and everything works fine with TSimpleServer.
But, when I try to implement TNonblockingServer I'm getting this error :(
undefined reference to `apache::thrift::server::TNonblockingServer::serve()
undefined reference to `apache::thrift::server::TNonblockingServer::~TNonblockingServer()
I think its something related to the header files or the namespaces.
The following headers im using:
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/server/TSimpleServer.h>
#include <thrift/transport/TServerSocket.h>
#include <thrift/transport/TBufferTransports.h>
#include <thrift/concurrency/ThreadManager.h>
#include <thrift/concurrency/PosixThreadFactory.h>
#include <thrift/server/TThreadedServer.h>
#include <thrift/server/TNonblockingServer.h>
using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::server;
using namespace ::apache::thrift::concurrency;
any idea whats wrong?
I understand that this is really late reply.
It is due to missing libthriftnb library for TNonblockingServer.
while Tsimplesever and TThreadedServer are in libthrift library so it was works with you.

C++ #include not working in Microsoft Visual Studio 2010

I have been using Visual Studio and I think I must have messed with some setting. I can't include basic things like <iostream>. How can I fix this?
#include <iostream> // for standard I/O
#include <string> // for strings
#include <iomanip> // for controlling float print precision
#include <sstream> // string to number conversion
#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur
#include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/highgui/highgui.hpp> // OpenCV window I/O
using namespace std;
using namespace cv;
All the above lines are in red squiggle below. My guess is while trying to configure Visual Studio to use OpenCv, I messed with some setting.
More than likely, you forgot to add 'using namespace std' as pretty much nothing in iostream is really useful without it. If you are getting 'cant find ...', then you have a setup problem and should reinstall Visual Studio because the headers were not properly placed.
Hope this helps, feel free to post your code and I can tell you for sure what the problem is, but that is the most likely of them.