Tag Archives: c++

[Error] invalid operands to binary ^ (have ‘double‘ and ‘float‘)

C. It cannot be used directly in C + +^

In C and C + +, you can’t use ^ to represent the index, only * can be used. If you want to use the index, you can only establish a cycle to multiply multiple times or write multiple directly by multiplication. The following is my code. The comment part is the original index form, and the above error will be reported.

Or reference mathematical functions and add #include & lt; math.h>;

Pow (x, y) is used to solve the Y power of X;

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	double p0=1000,r1=0.0036,r2=0.0225,r3=0.0198,p1,p2,p3;
	p1=p0*(1+r1)*(1+r1)*(1+r1)*(1+r1)*(1+r1)*(1+r1);
	//p1=p0*(1+r1)^6;
	p2=p0*(1+r2)*(1+r2)*(1+r2);
	//p2=p0*(1+r2)^3;
	p3=p0*(1+r3)*(1+r3);
	//p3=p0*(1+r3)^2;
	double x=1,y=2,p;
	p = pow(x+1,y);  //Find the yth power of x+1, which is the exponent 
	printf("The square of 1+1 is %lf",p);
	printf("deposit 1 year %lf, deposit 2 years %lf, deposit 3 years %lf",p1,p2,p3);
	return 0;
}

C++ Primer Program in VsCode error: no match for call to ‘(std::__cxx11::string…)

In the original file, total. Isbn() = = trans. Isbn() will report an error in vscode, “unable to match the call error”
compile. CPP: 12:37: error: no match for call to ‘(STD:: _cxx11:: String
{aka STD:: _cxx11:: basic_string}) ()’
if (total. Isbn() = = trans. Isbn())
solution: remove the brackets after. Isbn() and change the primitive sentence to

if (total.isbn==trans.isbn)

The reason is that ISBN should be a parameter value rather than a method, or it may be caused by my environment. It is for reference only.

#include <iostream>

#include"Sales_item.h"
int main(){
   Sales_item total;
   if (std::cin>>total)
   {Sales_item trans;
   while (std::cin>>trans)
   {
       if (total.isbn()==trans.isbn())
            total+=trans;
        else
        {
       std::cout<<total<<std::endl;
       total=trans;
        }
   
     
   }
   
    std::cout<<total<<std::endl;
   }
   else{
       std::cerr<<"NO Data?!"<<std::endl;
       return -1;
   }
   return 0;
    
}

Ubuntu 18.04 installation of opencv2.4.13 encountered fatal error. Possible solutions

Ubuntu 18.04 installation of opencv2.4.13 encountered fatal error. Possible solutions

During the installation process, some fatal errors may occur. I haven’t found a method for a long time. I happened to see an article that the installation can be successful according to the following methods. Although the errors reported are not consistent, they can be used in this way.

Ubuntu installation opencv step pit

1、 Installation process

apt-get update
apt-get install build-essential
apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
     
     
cd opencv-2.4.13
mkdir release
cd release/

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j4
sudo make install

[UNK]ह_;;

CMake Error at cmake/OpenCVDetectCXXCompiler.cmake:85 (list):

CMake Error at cmake/OpenCVDetectCXXCompiler.cmake:85 (list):
  list GET given empty list
Call Stack (most recent call first):
  CMakeLists.txt:77 (include)


CMake Error at cmake/OpenCVDetectCXXCompiler.cmake:86 (list):
  list GET given empty list
Call Stack (most recent call first):
  CMakeLists.txt:77 (include)




CMake Error at cmake/OpenCVDetectCXXCompiler.cmake:89 (math):
  math cannot parse the expression: "*100 + ": syntax error, unexpected
  exp_TIMES, expecting exp_PLUS or exp_MINUS or exp_OPENPARENT or exp_NUMBER
  (1)
Call Stack (most recent call first):
  CMakeLists.txt:77 (include)

Solution
replace the contents of opencvdetectcxxcompiler.cmake with the following:

# ----------------------------------------------------------------------------
# Detect Microsoft compiler:
# ----------------------------------------------------------------------------
if(CMAKE_CL_64)
    set(MSVC64 1)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  set(CMAKE_COMPILER_IS_GNUCXX 1)
  set(CMAKE_COMPILER_IS_CLANGCXX 1)
endif()
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
  set(CMAKE_COMPILER_IS_GNUCC 1)
  set(CMAKE_COMPILER_IS_CLANGCC 1)
endif()
if("${CMAKE_CXX_COMPILER};${CMAKE_C_COMPILER}" MATCHES "ccache")
  set(CMAKE_COMPILER_IS_CCACHE 1)
endif()

# ----------------------------------------------------------------------------
# Detect Intel ICC compiler -- for -fPIC in 3rdparty ( UNIX ONLY ):
#  see  include/opencv/cxtypes.h file for related   ICC & CV_ICC defines.
# NOTE: The system needs to determine if the '-fPIC' option needs to be added
#  for the 3rdparty static libs being compiled.  The CMakeLists.txt files
#  in 3rdparty use the CV_ICC definition being set here to determine if
#  the -fPIC flag should be used.
# ----------------------------------------------------------------------------
if(UNIX)
  if  (__ICL)
    set(CV_ICC   __ICL)
  elseif(__ICC)
    set(CV_ICC   __ICC)
  elseif(__ECL)
    set(CV_ICC   __ECL)
  elseif(__ECC)
    set(CV_ICC   __ECC)
  elseif(__INTEL_COMPILER)
    set(CV_ICC   __INTEL_COMPILER)
  elseif(CMAKE_C_COMPILER MATCHES "icc")
    set(CV_ICC   icc_matches_c_compiler)
  endif()
endif()

if(MSVC AND CMAKE_C_COMPILER MATCHES "icc|icl")
  set(CV_ICC   __INTEL_COMPILER_FOR_WINDOWS)
endif()

# ----------------------------------------------------------------------------
# Detect GNU version:
# ----------------------------------------------------------------------------
if(CMAKE_COMPILER_IS_CLANGCXX)
  set(CMAKE_GCC_REGEX_VERSION "4.2.1")
  set(CMAKE_OPENCV_GCC_VERSION_MAJOR 4)
  set(CMAKE_OPENCV_GCC_VERSION_MINOR 2)
  set(CMAKE_OPENCV_GCC_VERSION 42)
  set(CMAKE_OPENCV_GCC_VERSION_NUM 402)

  execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -v
                  ERROR_VARIABLE CMAKE_OPENCV_CLANG_VERSION_FULL
                  ERROR_STRIP_TRAILING_WHITESPACE)

  string(REGEX MATCH "version.*$" CMAKE_OPENCV_CLANG_VERSION_FULL "${CMAKE_OPENCV_CLANG_VERSION_FULL}")
  string(REGEX MATCH "[0-9]+\\.[0-9]+" CMAKE_CLANG_REGEX_VERSION "${CMAKE_OPENCV_CLANG_VERSION_FULL}")

elseif(CMAKE_COMPILER_IS_GNUCXX)
  execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -dumpversion
                OUTPUT_VARIABLE CMAKE_OPENCV_GCC_VERSION_FULL
                OUTPUT_STRIP_TRAILING_WHITESPACE)

  execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} -v
                ERROR_VARIABLE CMAKE_OPENCV_GCC_INFO_FULL
                OUTPUT_STRIP_TRAILING_WHITESPACE)

  # Typical output in CMAKE_OPENCV_GCC_VERSION_FULL: "c+//0 (whatever) 4.2.3 (...)"
  # Look for the version number, major.minor.build
  string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}")
  if(NOT CMAKE_GCC_REGEX_VERSION)#major.minor
    string(REGEX MATCH "[0-9]+\\.[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}")
  endif()

  if(CMAKE_GCC_REGEX_VERSION)
    # Split the parts:
    string(REGEX MATCHALL "[0-9]+" CMAKE_OPENCV_GCC_VERSIONS "${CMAKE_GCC_REGEX_VERSION}")

    list(GET CMAKE_OPENCV_GCC_VERSIONS 0 CMAKE_OPENCV_GCC_VERSION_MAJOR)
    list(GET CMAKE_OPENCV_GCC_VERSIONS 1 CMAKE_OPENCV_GCC_VERSION_MINOR)
  else()#compiler returned just the major version number
    string(REGEX MATCH "[0-9]+" CMAKE_GCC_REGEX_VERSION "${CMAKE_OPENCV_GCC_VERSION_FULL}")
    if(NOT CMAKE_GCC_REGEX_VERSION)#compiler did not return anything reasonable
      set(CMAKE_GCC_REGEX_VERSION "0")
      message(WARNING "GCC version not detected!")
    endif()
    set(CMAKE_OPENCV_GCC_VERSION_MAJOR ${CMAKE_GCC_REGEX_VERSION})
    set(CMAKE_OPENCV_GCC_VERSION_MINOR 0)
  endif()

  set(CMAKE_OPENCV_GCC_VERSION ${CMAKE_OPENCV_GCC_VERSION_MAJOR}${CMAKE_OPENCV_GCC_VERSION_MINOR})
  math(EXPR CMAKE_OPENCV_GCC_VERSION_NUM "${CMAKE_OPENCV_GCC_VERSION_MAJOR}*100 + ${CMAKE_OPENCV_GCC_VERSION_MINOR}")
  message(STATUS "Detected version of GNU GCC: ${CMAKE_OPENCV_GCC_VERSION} (${CMAKE_OPENCV_GCC_VERSION_NUM})")

  if(WIN32)
    execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpmachine
              OUTPUT_VARIABLE OPENCV_GCC_TARGET_MACHINE
              OUTPUT_STRIP_TRAILING_WHITESPACE)
    if(OPENCV_GCC_TARGET_MACHINE MATCHES "amd64|x86_64|AMD64")
      set(MINGW64 1)
    endif()
  endif()
endif()

if(MSVC64 OR MINGW64)
  set(X86_64 1)
elseif(MINGW OR (MSVC AND NOT CMAKE_CROSSCOMPILING))
  set(X86 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
  set(X86_64 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686.*|i386.*|x86.*|amd64.*|AMD64.*")
  set(X86 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm.*|ARM.*)")
  set(ARM 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)")
  set(AARCH64 1)
endif()

# Workaround for 32-bit operating systems on 64-bit x86_64 processor
if(X86_64 AND CMAKE_SIZEOF_VOID_P EQUAL 4 AND NOT FORCE_X86_64)
  message(STATUS "sizeof(void) = 4 on x86/x86_64 processor. Assume 32-bit compilation mode (X86=1)")
  unset(X86_64)
  set(X86 1)
endif()

# Similar code exists in OpenCVConfig.cmake
if(NOT DEFINED OpenCV_STATIC)
  # look for global setting
  if(NOT DEFINED BUILD_SHARED_LIBS OR BUILD_SHARED_LIBS)
    set(OpenCV_STATIC OFF)
  else()
    set(OpenCV_STATIC ON)
  endif()
endif()

if(MSVC)
  if(CMAKE_CL_64)
    set(OpenCV_ARCH x64)
  elseif((CMAKE_GENERATOR MATCHES "ARM") OR ("${arch_hint}" STREQUAL "ARM") OR (CMAKE_VS_EFFECTIVE_PLATFORMS MATCHES "ARM|arm"))
    # see Modules/CmakeGenericSystem.cmake
    set(OpenCV_ARCH ARM)
  else()
    set(OpenCV_ARCH x86)
  endif()
  if(MSVC_VERSION EQUAL 1400)
    set(OpenCV_RUNTIME vc8)
  elseif(MSVC_VERSION EQUAL 1500)
    set(OpenCV_RUNTIME vc9)
  elseif(MSVC_VERSION EQUAL 1600)
    set(OpenCV_RUNTIME vc10)
  elseif(MSVC_VERSION EQUAL 1700)
    set(OpenCV_RUNTIME vc11)
  elseif(MSVC_VERSION EQUAL 1800)
    set(OpenCV_RUNTIME vc12)
  elseif(MSVC_VERSION EQUAL 1900)
    set(OpenCV_RUNTIME vc14)
  elseif(MSVC_VERSION EQUAL 1910)
    set(OpenCV_RUNTIME vc15)
  endif()
elseif(MINGW)
  set(OpenCV_RUNTIME mingw)

  if(MINGW64)
    set(OpenCV_ARCH x64)
  else()
    set(OpenCV_ARCH x86)
  endif()
endif()

/Usr/include/C + +/7/cstdlib: 75:15: fatal error: stdlib. H: there is no such file or directory
solution: change the cmake instruction

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local .. -D ENABLE_PRECOMPILED_HEADERS=OFF ..

Solution to dev C + + error [error] LD returned 1 exit status

        I am a beginner of C language. When using dev C + + compiler, I encountered a situation: the program is correct and can be compiled and run normally, but it appears when I run it again after running it once   Error [error] LD returned 1 exit status. The reason for this problem is that although the last running window is closed, the program is still running in the background. This can be viewed through the task manager.

      The usual method on the Internet is to close the program and then open it. This is OK, but it is too inconvenient. Here is a method. I used this method to solve my problem:

     

Right click the compatibility attribute of devcpp.exe and check the run as administrator.     Just.

[Solved] Opencv error: assertion__acrt_first_block == header

Problem description

In a project using OpenCV, after changing MDD to MTD, the debug mode encountered an error.

debug_heap.cpp   Line 996

        if (header->_block_header_prev)
        {
            header->_block_header_prev->_block_header_next = header->_block_header_next;
        }
        else
        {
            _ASSERTE(__acrt_first_block == header);            //# 996 LINE
            __acrt_first_block = header->_block_header_next;
        }

        memset(header, dead_land_fill, sizeof(_CrtMemBlockHeader) + header->_data_size + no_mans_land_size);
        _free_base(header);

Solution

Add the following functions to region.cpp

void findContours(const cv::Mat &src, std::vector<std::vector<cv::Point>> &contours, std::vector<cv::Vec4i> &hierarchy, int retr = cv::RETR_LIST, int method = cv::CHAIN_APPROX_SIMPLE, cv::Point offset = cv::Point(0, 0))
{
    using namespace cv;
    CvMat c_image = src;
    MemStorage storage(cvCreateMemStorage());
    CvSeq *_ccontours = 0;
    cvFindContours(&c_image, storage, &_ccontours, sizeof(CvContour), retr, method, CvPoint(offset));

    if (!_ccontours)
    {
        contours.clear();
        return;
    }
    Seq<CvSeq *> all_contours(cvTreeToNodeSeq(_ccontours, sizeof(CvSeq), storage));
    int total = (int)all_contours.size();
    contours.resize(total);

    SeqIterator<CvSeq *> it = all_contours.begin();
    for (int i = 0; i < total; i++, ++it)
    {
        CvSeq *c = *it;
        ((CvContour *)c)->color = (int)i;
        int count = (int)c->total;
        int *data = new int[count * 2];
        cvCvtSeqToArray(c, data);
        for (int j = 0; j < count; j++)
        {
            contours[i].push_back(Point(data[j * 2], data[j * 2 + 1]));
        }
        delete[] data;
    }

    hierarchy.resize(total);
    it = all_contours.begin();
    for (int i = 0; i < total; i++, ++it)
    {
        CvSeq *c = *it;
        int h_next = c->h_next ?((CvContour *)c->h_next)->color : -1;
        int h_prev = c->h_prev ?((CvContour *)c->h_prev)->color : -1;
        int v_next = c->v_next ?((CvContour *)c->v_next)->color : -1;
        int v_prev = c->v_prev ?((CvContour *)c->v_prev)->color : -1;
        hierarchy[i] = Vec4i(h_next, h_prev, v_next, v_prev);
    }
    storage.release();
}

There are still errors after adding,   Find our business code   Change this one to that one:

std::vector<cv::Mat> chs;                //BEFORE
std::vector<cv::Mat> chs(m.channels());  //NEW

It can run successfully

[Solved] Mac Cmake Complie openmp Error: fatal error: ‘omp.h‘ file not found

Mac OS 11.5.2, cmake default compiler appleclang 12.0.5

Make keeps reporting errors after compiling

fatal error: 'omp.h' file not found
#include<omp.h>

The reason is that a.cpp file introduces OpenMP, OMP.H

It can be compiled successfully through G + +, but the make default clang compilation in MAcc is not successful. In other words, it cannot be compiled through cmake on Mac

Try to resolve:

Adding before the project line of cmake has no effect

SET(CMAKE_C_COMPILER "/usr/bin/gcc")
SET(CMAKE_CXX_COMPILER "/usr/bin/g++")

On the command line, the export cxx = “usr/bin/G + +” variable also has no effect

Solution

Brew install libomp

brew install libomp

Change the path corresponding to OMP. H where. CPP introduces OMP. H

#include</usr/local/opt/libomp/include/omp.h>

Vs2019 + QT parses the XML file and reports an error at doc.setcontent (& file)

Vs2019 + QT parses the XML file and reports an error at doc.setcontent

Made a very low-level mistake. Record the process.

A QT project was established long ago. Now to add a function of parsing XML files using the qdom class, there is always an error in the sentence doc.setcontent (& amp; file) , and there is no error message. The relevant C + + codes are as follows:

QString error;
int line, column;
if (doc.setContent(&file, &error, &line, &column)) {
    qDebug() << doc.toString(4);
}
else {
    qDebug() << "Error:" << error << "in line " << line << "column" << column;
}
file.close();

When doc.setcontent (& amp; file, & amp; error, & amp; line, & amp; column) , critical error detected c00000374 is displayed

The first reaction is that the XML file is incorrectly written. For example, there is no space in the space, Chinese punctuation is entered, or the two sides of the tag are inconsistent
after repeatedly confirming that the XML file is correct, the stackoverflow search said that the relative path cannot be used, but the absolute path must be used… Another attempt of the absolute path is useless.

Create a new project and run it with the same code without error. Through careful comparison, it is found that in the new project, I added the XML class library

but not in the original project!

So far, add $(qtdir) \ include \ qtxml in the C/C + + include directory, add qt5xmld.lib [debug mode] and qt5xml. Lib [release mode] in the linker, and the operation is successful!

Finally, I found that if the XML file is written incorrectly, the above program can locate the error location. Direct reporting of fatal error/critical error or unresolved external symbols like this__ declspec(dllimport) public: __ Cdecl , the probability is that the Lib file link is wrong rather than the code problem. You need to check whether the environment is configured correctly.

A simple question has been wordy for a long time… Mainly to warn yourself that you must think more and think more about ways to expose the problem when you encounter a problem that has no solution on the Internet!

[Solved] CMake Error: Could not create named generator Visual Studio 16 2019

Cmake error: could not create named generator visual studio 16 2019

When running the demo in openvino, this bug is always prompted. According to the suggestions of stackoverflow and official documents, use cmake - G "Visual Studio 16 2019" - a x64 this command to compile, which is also invalid. Later, after troubleshooting, I thought it might be the problem of cmake version. Because the old version of cmake (before 3.14) may not find the latest visual studio, I went to the official website to download it, Run the. Bat file in the demo to solve the problem


Error 1 fatal error LNK1220: ‘/PGD‘ requires ‘/LTCG:[PGINSTRUMENT|PGOPTIMIZE]‘ specification

VS2008 compilation of an MFC project pop-up error, looking for a long time, did not find the problem.

  resolvent,

According to the official article:/PGD (specify database for profile guided optimizations) | Microsoft docs

  It says how to solve this problem,

  Setup steps,

1. Open the project property setting (right click on the solution project and select properties),

2. Select link = & gt; Optimization=> Profile Guided Database

3. Select & lt; inherit from parent or project defaults>, Click apply and confirm. Then compile and solve the problem.