opencv - cmake mingw32-make error [duplicate] - c++

opencv installation using mingw32-make command in windows 10 platform, then likely end up in getting the below error.
Windows version : 10
OpenCv:3.2.0
Please suggest me in installing.
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In constructor 'testing::internal::Mutex::Mutex()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8829:45: error: cannot convert 'CRITICAL_SECTION* {aka _CRITICAL_SECTION*}' to '_RTL_CRITICAL_SECTION*' in initialization
critical_section_(new CRITICAL_SECTION) {
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8830:48: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void InitializeCriticalSection(LPCRITICAL_SECTION)'
::InitializeCriticalSection(critical_section_);
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In destructor 'testing::internal::Mutex::~Mutex()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8840:46: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'PCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void DeleteCriticalSection(PCRITICAL_SECTION)'
::DeleteCriticalSection(critical_section_);
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In member function 'void testing::internal::Mutex::Lock()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8848:43: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void EnterCriticalSection(LPCRITICAL_SECTION)'
::EnterCriticalSection(critical_section_);
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In member function 'void testing::internal::Mutex::Unlock()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8858:43: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void LeaveCriticalSection(LPCRITICAL_SECTION)'
::LeaveCriticalSection(critical_section_);
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp: In member function 'void testing::internal::Mutex::ThreadSafeLazyInit()':
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8879:27: error: cannot convert 'CRITICAL_SECTION* {aka _CRITICAL_SECTION*}' to '_RTL_CRITICAL_SECTION*' in assignment
critical_section_ = new CRITICAL_SECTION;
^
D:\installers\opencv\sources\modules\ts\src\ts_gtest.cpp:8880:54: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void InitializeCriticalSection(LPCRITICAL_SECTION)'
::InitializeCriticalSection(critical_section_);
^
modules\ts\CMakeFiles\opencv_ts.dir\build.make:237: recipe for target 'modules/ts/CMakeFiles/opencv_ts.dir/src/ts_gtest.cpp.obj' failed
mingw32-make[2]: *** [modules/ts/CMakeFiles/opencv_ts.dir/src/ts_gtest.cpp.obj] Error 1
CMakeFiles\Makefile2:5379: recipe for target 'modules/ts/CMakeFiles/opencv_ts.dir/all' failed
mingw32-make[1]: *** [modules/ts/CMakeFiles/opencv_ts.dir/all] Error 2
Makefile:159: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

I also faced the same problem while trying to build OpenCV 3.2.0 using mingw32 on Windows10. I searched a bit to find a fix on Github for similar problem. It said the problem was:
MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two separate (equivalent) structs, instead of using typedef
So, you have to add another typedef GTEST_CRITICAL_SECTION for _CRITICAL_SECTION and _RTL_CRITICAL_SECTION and use this typedef for either case.
Here is what to do :
Edit "ts_gtest.h" which is inside "opencv\sources\modules\ts\include\opencv2\ts\"
Replace this line (probably line 723)
// assuming CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION.
// This assumption is verified by
// WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION.
struct _RTL_CRITICAL_SECTION;
with
#if GTEST_OS_WINDOWS_MINGW
// MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two
// separate (equivalent) structs, instead of using typedef
typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#else
// Assume CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION.
// This assumption is verified by
// WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION
typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#endif
Replace this line (probably on line 3060 before your edit - line number would have changed as you modified first part)
_RTL_CRITICAL_SECTION* critical_section_;
with
GTEST_CRITICAL_SECTION* critical_section_;
These two changes should fix your above error.

It was fixed by using TDM-gcc mingw compiler.

Related

Problem with Petsc Complex Configuration for Windows

I m trying to build Petsc Complex Version on windows.(VS2019 and c++17)
the configuration is as bellow :
./configure --with-cc="win32fe cl" --with-cxx="win32fe cl" --with-fc=0 --download-f2cblaslapack --with-memalign=64 --with-mpi-include=/cygdrive/c/software/Mpich2/Include --with-mpi-lib=/cygdrive/c/software/Mpich2/lib/mpi.lib --with-mpi-mpiexec=/cygdrive/c/software/Mpich2/bin/mpiexec.exe CFLAGS="-MD -wd4996" CXXFLAGS="-MD -wd4996" COPTFLAGS="-O2" CXXOPTFLAGS="-O2" --with-debugging=0 --with-scalar-type=complex --with-clanguage=cxx
when I try to make the configuration an error appear :
CXX arch-mswin-cxx-opt/obj/vec/is/sf/impls/basic/sfpack.o
sfpack.c
C:\software\PETSC-~1.4\src\vec\is\sf\impls\basic\sfpack.c(977): error C2664: 'int MPI_Reduce_local(void *,void *,int,MPI_Datatype,MPI_Op)': cannot convert argument 1 from 'const char *' to 'void *'
C:\software\PETSC-~1.4\src\vec\is\sf\impls\basic\sfpack.c(977): note: Conversion loses qualifiers
C:\software\Mpich2\Include\mpi.h(887): note: see declaration of 'MPI_Reduce_local'
C:\software\PETSC-~1.4\src\vec\is\sf\impls\basic\sfpack.c(980): error C2664: 'int MPI_Reduce_local(void *,void *,int,MPI_Datatype,MPI_Op)': cannot convert argument 1 from 'const void *' to 'void *'
C:\software\PETSC-~1.4\src\vec\is\sf\impls\basic\sfpack.c(980): note: Conversion loses qualifiers
C:\software\Mpich2\Include\mpi.h(887): note: see declaration of 'MPI_Reduce_local'
C:\software\PETSC-~1.4\src\vec\is\sf\impls\basic\sfpack.c(1001): error C2664: 'int MPI_Reduce_local(void *,void *,int,MPI_Datatype,MPI_Op)': cannot convert argument 1 from 'const char *' to 'void *'
C:\software\PETSC-~1.4\src\vec\is\sf\impls\basic\sfpack.c(1001): note: Conversion loses qualifiers
C:\software\Mpich2\Include\mpi.h(887): note: see declaration of 'MPI_Reduce_local'
make[3]: *** [gmakefile:184: arch-mswin-cxx-opt/obj/vec/is/sf/impls/basic/sfpack.o] Error 2
make[2]: *** [/cygdrive/c/software/petsc-3.13.4/lib/petsc/conf/rules:50: libs] Error 2
**************************ERROR*************************************
Error during compile, check arch-mswin-cxx-opt/lib/petsc/conf/make.log
Send it and arch-mswin-cxx-opt/lib/petsc/conf/configure.log to petsc-maint#mcs.anl.gov
********************************************************************
For the Real Version there is no issue !!! please Any help

How can I resolve ReLU is not a member of torch::nn error while building?

I am trying to build a simple network using torch. But when I try to build the project it returns some error messages like error: ‘ReLU’ is not a member of ‘torch::nn’
My network definitions is as follows:
#pragma once
#include <torch/torch.h>
class ConvNetImpl : public torch::nn::Module {
public:
explicit ConvNetImpl(int64_t num_classes = 10);
torch::Tensor forward(torch::Tensor x);
private:
torch::nn::Sequential layer1{
torch::nn::Conv2d(torch::nn::Conv2dOptions(1, 16, 5).stride(1).padding(2)),
torch::nn::BatchNorm2d(16),
torch::nn::ReLU(),
torch::nn::MaxPool2d(torch::nn::MaxPool2dOptions(2).stride(2))
};
torch::nn::Sequential layer2{
torch::nn::Conv2d(torch::nn::Conv2dOptions(16, 32, 5).stride(1).padding(2)),
torch::nn::BatchNorm2d(32),
torch::nn::ReLU(),
torch::nn::MaxPool2d(torch::nn::MaxPool2dOptions(2).stride(2))
};
torch::nn::Linear fc;
};
TORCH_MODULE(ConvNet);
When I try to build with: cmake --build . --config Release
It returns me this message:
[ 33%] Building CXX object CMakeFiles/freespace_torch.dir/src/convnet.cpp.o
In file included from /home/fugurcal/freespace_torch/src/convnet.cpp:2:0:
/home/fugurcal/freespace_torch/include/convnet.h:13:20: error: ‘BatchNorm2d’ is not a member of ‘torch::nn’
torch::nn::BatchNorm2d(16),
^~~~~~~~~~~
/home/fugurcal/freespace_torch/include/convnet.h:13:20: note: suggested alternative: ‘BatchNorm’
torch::nn::BatchNorm2d(16),
^~~~~~~~~~~
BatchNorm
/home/fugurcal/freespace_torch/include/convnet.h:14:20: error: ‘ReLU’ is not a member of ‘torch::nn’
torch::nn::ReLU(),
^~~~
/home/fugurcal/freespace_torch/include/convnet.h:15:20: error: ‘MaxPool2d’ is not a member of ‘torch::nn’
torch::nn::MaxPool2d(torch::nn::MaxPool2dOptions(2).stride(2))
^~~~~~~~~
/home/fugurcal/freespace_torch/include/convnet.h:15:41: error: ‘MaxPool2dOptions’ is not a member of ‘torch::nn’
torch::nn::MaxPool2d(torch::nn::MaxPool2dOptions(2).stride(2))
^~~~~~~~~~~~~~~~
/home/fugurcal/freespace_torch/include/convnet.h:15:41: note: suggested alternative: ‘Conv2dOptions’
torch::nn::MaxPool2d(torch::nn::MaxPool2dOptions(2).stride(2))
^~~~~~~~~~~~~~~~
Conv2dOptions
/home/fugurcal/freespace_torch/include/convnet.h:16:5: error: could not convert ‘{torch::nn::Conv2d((* &(& torch::nn::ConvOptions<2>(1, 16, torch::ExpandingArray<2, long int>(5)).torch::nn::ConvOptions<2>::stride(torch::ExpandingArray<2, long int>(1)))->torch::nn::ConvOptions<2>::padding(torch::ExpandingArray<2, long int>(2)))), <expression error>, <expression error>, <expression error>}’ from ‘<brace-enclosed initializer list>’ to ‘torch::nn::Sequential’
};
^
/home/fugurcal/freespace_torch/include/convnet.h:20:20: error: ‘BatchNorm2d’ is not a member of ‘torch::nn’
torch::nn::BatchNorm2d(32),
^~~~~~~~~~~
/home/fugurcal/freespace_torch/include/convnet.h:20:20: note: suggested alternative: ‘BatchNorm’
torch::nn::BatchNorm2d(32),
^~~~~~~~~~~
BatchNorm
/home/fugurcal/freespace_torch/include/convnet.h:21:20: error: ‘ReLU’ is not a member of ‘torch::nn’
torch::nn::ReLU(),
^~~~
/home/fugurcal/freespace_torch/include/convnet.h:22:20: error: ‘MaxPool2d’ is not a member of ‘torch::nn’
torch::nn::MaxPool2d(torch::nn::MaxPool2dOptions(2).stride(2))
^~~~~~~~~
/home/fugurcal/freespace_torch/include/convnet.h:22:41: error: ‘MaxPool2dOptions’ is not a member of ‘torch::nn’
torch::nn::MaxPool2d(torch::nn::MaxPool2dOptions(2).stride(2))
^~~~~~~~~~~~~~~~
/home/fugurcal/freespace_torch/include/convnet.h:22:41: note: suggested alternative: ‘Conv2dOptions’
torch::nn::MaxPool2d(torch::nn::MaxPool2dOptions(2).stride(2))
^~~~~~~~~~~~~~~~
Conv2dOptions
/home/fugurcal/freespace_torch/include/convnet.h:23:5: error: could not convert ‘{torch::nn::Conv2d((* &(& torch::nn::ConvOptions<2>(16, 32, torch::ExpandingArray<2, long int>(5)).torch::nn::ConvOptions<2>::stride(torch::ExpandingArray<2, long int>(1)))->torch::nn::ConvOptions<2>::padding(torch::ExpandingArray<2, long int>(2)))), <expression error>, <expression error>, <expression error>}’ from ‘<brace-enclosed initializer list>’ to ‘torch::nn::Sequential’
};
^
CMakeFiles/freespace_torch.dir/build.make:62: recipe for target 'CMakeFiles/freespace_torch.dir/src/convnet.cpp.o' failed
make[2]: *** [CMakeFiles/freespace_torch.dir/src/convnet.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/freespace_torch.dir/all' failed
make[1]: *** [CMakeFiles/freespace_torch.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
I know mentioned methods are member of torch::nn. How can I resolve this issue?
Issue solved. While making "cmake -DCMAKE_PREFIX_PATH=/absolute/path/to/libtorch .." my libtorch directory was "/home/user/folder/libtorch". After changing the libtorch directory to "/home/user/libtorch" issue solved.

Cassandra cpp-driver compile error

I'm trying to install Cassandra cpp-driver in Ubuntu.
I've done the steps specified in DataStax C/C++ Driver for Apache Cassandra (Beta), but i keep getting the following compile error.
[ 1%] Building CXX object CMakeFiles/cassandra.dir/src/buffer_collection.cpp.o
In file included from /root/libraries/cass_cpp-driver/git2/cpp-driver/src/session.hpp:29:0, from /root/libraries/cass_cpp-driver/git2/cpp-driver/src/types.hpp:22, from /root/libraries/cass_cpp-driver/git2/cpp-driver/src/buffer_collection.cpp:19:
/root/libraries/cass_cpp-driver/git2/cpp-driver/src/logger.hpp: In member function 'int cass::Logger::init()':
/root/libraries/cass_cpp-driver/git2/cpp-driver/src/logger.hpp:40:59: error: no matching function for call to 'cass::AsyncQueue<cass::MPMCQueue<cass::Logger::LogMessage*> >::init(uv_loop_t*, cass::Logger* const, void (&)(uv_async_t*, int))'
int init() { return log_queue_.init(loop(), this, on_log); }
^
/root/libraries/cass_cpp-driver/git2/cpp-driver/src/logger.hpp:40:59: note: candidate is:
In file included from /root/libraries/cass_cpp-driver/git2/cpp-driver/src/event_thread.hpp:21:0,
from /root/libraries/cass_cpp-driver/git2/cpp-driver/src/session.hpp:20,
from /root/libraries/cass_cpp-driver/git2/cpp-driver/src/types.hpp:22,
from /root/libraries/cass_cpp-driver/git2/cpp-driver/src/buffer_collection.cpp:19:
/root/libraries/cass_cpp-driver/git2/cpp-driver/src/async_queue.hpp:34:7: note: int cass::AsyncQueue<Q>::init(uv_loop_t*, void*, uv_async_cb) [with Q = cass::MPMCQueue<cass::Logger::LogMessage*>; uv_loop_t = uv_loop_s; uv_async_cb = void (*)(uv_async_s*); uv_async_t = uv_async_s] <near match>
int init(uv_loop_t* loop, void* data, uv_async_cb async_cb) {
^
/root/libraries/cass_cpp-driver/git2/cpp-driver/src/async_queue.hpp:34:7: note: no known conversion for argument 3 from 'void(uv_async_t*, int) {aka void(uv_async_s*, int)}' to 'uv_async_cb {aka void (*)(uv_async_s*)}'
make[2]: *** [CMakeFiles/cassandra.dir/src/buffer_collection.cpp.o] Error 1
make[1]: *** [CMakeFiles/cassandra.dir/all] Error 2
make: *** [all] Error 2
I've already fixed this compile errors in Cassandra cpp-driver, by down-versioning libuv to version libuv-0.10, the compile errors will be gone.
It seems that the latest updates for libuv is not yet supported by Cassandra cpp-driver.

Make Error Compiling Armadillo 4.300.8

I am trying to compile the newest version of the Armadillo Linear Algebra library (4.300.8) and am running into the following errors when running make after cmake . runs successfully.
Scanning dependencies of target armadillo
[100%] Building CXX object CMakeFiles/armadillo.dir/src/wrapper.cpp.o
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp: In function ‘hid_t arma::arma_H5Dopen(hid_t, const char*, hid_t)’:
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp:890:43: error: too many arguments to function ‘hid_t H5Dopen1(hid_t, const char*)’
/usr/include/H5Dpublic.h:145:14: note: declared here
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp: In function ‘hid_t arma::arma_H5Dcreate(hid_t, const char*, hid_t, hid_t, hid_t, hid_t, hid_t)’:
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp:900:83: error: too many arguments to function ‘hid_t H5Dcreate1(hid_t, const char*, hid_t, hid_t, hid_t)’
/usr/include/H5Dpublic.h:143:14: note: declared here
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp: In function ‘herr_t arma::arma_H5Eset_auto(hid_t, H5E_auto1_t, void*)’:
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp:950:54: error: invalid conversion from ‘hid_t {aka int}’ to ‘H5E_auto1_t {aka int (*)(void*)}’ [-fpermissive]
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp:950:54: error: invalid conversion from ‘H5E_auto1_t {aka int (*)(void*)}’ to ‘void*’ [-fpermissive]
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp:950:54: error: too many arguments to function ‘herr_t H5Eset_auto1(H5E_auto1_t, void*)’
/usr/include/H5Epublic.h:216:15: note: declared here
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp: In function ‘herr_t arma::arma_H5Eget_auto(hid_t, herr_t (**)(void*), void**)’:
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp:955:54: error: invalid conversion from ‘hid_t {aka int}’ to ‘herr_t (**)(void*) {aka int (**)(void*)}’ [-fpermissive]
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp:955:54: error: invalid conversion from ‘herr_t (**)(void*) {aka int (**)(void*)}’ to ‘void**’ [-fpermissive]
/home/user/Desktop/armadillo-4.300.8/src/wrapper.cpp:955:54: error: too many arguments to function ‘herr_t H5Eget_auto1(herr_t (**)(void*), void**)’
/usr/include/H5Epublic.h:212:15: note: declared here
make[2]: *** [CMakeFiles/armadillo.dir/src/wrapper.cpp.o] Error 1
make[1]: *** [CMakeFiles/armadillo.dir/all] Error 2
make: *** [all] Error 2
I am using gcc version 4.7.3 and running Ubuntu 12.04.
Thanks!
It looks like the HDF5 library is causing problems. Uninstall the HDF5 library, and then reinstall Armadillo.
Another option is to update your system to Ubuntu 14.04. The previous Ubuntu LTS release (12.04) is ancient by open-source standards.

How to compile C++ program with using html tidy C++

I installed tidy-dev from ubuntu repository, checked installation path - it's okay (/usr/include/tidy).
But I can not find a true flags to compile my c++ script with include tidy c++ wrapper tidyx.h from http://users.rcn.com/creitzel/tidy/tidyx.h
Can you help me?
My test script file named 1.cpp, tidyx.h I put near. 1.cpp content:
#include "tidyx.h"
int main()
{
}
I try it, but no-good:
$ gcc -I/usr/include/tidy 1.cpp -ltidy
In file included from 1.cpp:1:
tidyx.h: In constructor ‘Tidy::Source::Source()’:
tidyx.h:83: error: invalid conversion from ‘int (*)(ulong)’ to ‘int (*)(void*)’
tidyx.h:84: error: invalid conversion from ‘void (*)(ulong, byte)’ to ‘void (*)(void*, byte)’
tidyx.h:85: error: invalid conversion from ‘Bool (*)(ulong)’ to ‘Bool (*)(void*)’
tidyx.h:86: error: invalid conversion from ‘ulong’ to ‘void*’
tidyx.h: In constructor ‘Tidy::Sink::Sink()’:
tidyx.h:123: error: invalid conversion from ‘void (*)(ulong, byte)’ to ‘void (*)(void*, byte)’
tidyx.h:124: error: invalid conversion from ‘ulong’ to ‘void*’
tidyx.h: In member function ‘void Tidy::Buffer::Attach(void*, uint)’:
tidyx.h:165: error: invalid conversion from ‘void*’ to ‘byte*’
tidyx.h:165: error: initializing argument 2 of ‘void tidyBufAttach(TidyBuffer*, byte*, uint)’
tidyx.h: In member function ‘int Tidy::Document::Create()’:
tidyx.h:496: error: invalid conversion from ‘ulong’ to ‘void*’
tidyx.h:496: error: initializing argument 2 of ‘void tidySetAppData(const _TidyDoc*, void*)’
tidyx.h: In member function ‘void Tidy::Document::SetAppData(ulong)’:
tidyx.h:511: error: invalid conversion from ‘ulong’ to ‘void*’
tidyx.h:511: error: initializing argument 2 of ‘void tidySetAppData(const _TidyDoc*, void*)’
tidyx.h: In member function ‘ulong Tidy::Document::GetAppData()’:
tidyx.h:512: error: invalid conversion from ‘void*’ to ‘ulong’
To include a header file you need to use the #include preprocessor directive. It will look for the header file in compiler include paths.
If tidyx.h is in /usr/include/tidy you could put in your source file:
#include <tidy/tidyx.h>
and then compile just with gcc script.cpp, since /usr/include is most likely a default include path for your compiler.
Otherwise you could also put in your source file:
#include <tidyx.h>
And then tell GCC to look in /usr/include/tidy: gcc -I/usr/include/tidy script.cpp
At this point the header will be found. If you'll get other errors related to tidy (eg: some tidy functions are not defined) you'll need to link your binary to some library using GCC -l option.
EDIT after OP's massive edit.
Your problem here is that tidyx.h contains C++ code, and also your source file, looking to its extensions, seems to be a C++ source file. You'll need a C++ compiler in order to compile it. Use g++ instead of gcc:
g++ script.cpp