Tag Archives: c++

[Solved] ModuleNotFoundError: No module named ‘_polyiou‘

Problem recurrence

//install swig
sudo apt-get install swig
swig -c++ -python polyiou.i
python setup.py build_ext --inplace

//report error
ModuleNotFoundError: No module named '_polyiou'

Solution:

Swig is not installed correctly. Because there are python2 and python3 in the environment, the command to install swig is modified as follows

sudo apt-get install swig
swig -c++ -python polyiou.i
python3 setup.py build_ext --inplace

Error encountered during QT + opencv compilation: file not recognized: file format not recognized error resolution

catalogue

1. Error message:

2. Analysis  

3. Solution


1. Error message:

D:\InstallSoftware\opencv\OpenCV-MinGW-Build-OpenCV-4.5.2-x64\x64\mingw\bin\libopencv_ calib3d452.dll:-1: error: file not recognized: File format not recognized

2. Analysis  

This is because the opencv compiled file version is different from the QT project version. You should choose the correct version of the toolkit.

3. Solution

For example, my opencv compilation file is opencv build_ 64 bit, then select MinGW 64 bit for the project.

 

[Solved] C++ Compile: error LNK2019: unresolved external “XX“

Link error: linker tools error LNK2019

The error prompt error LNK2019: unresolved external "XX" often appears during the compilation of C + + projects. The main reason is that the definition of the corresponding reference variable or function cannot be found in the currently referenced library during the linking process. At this time, you need to add the library that defines the reference variable to the corresponding project.

There are two main ways to solve this problem:

To manually add the powrprof.lib </KBD> library, do the following:

Method 1: use #pragma comment , such as
#pragma comment (LIB, "powrprof. Lib") method 2: properties under the corresponding item in vs: enter the corresponding position
Properties > Configuration Properties > Linker > Input > Additional dependencies add the powrprof.lib library, as shown in the following figure:

[Solved] Error reading comm device when writing serial communication with MSComm control

1. Problem description

In the process of serial communication written with MSComm control, when receiving the data sent by the serial port under the message response function OnComm function, in get_ An error reading comm develop error occurs in the input() function. The specific codes are as follows:

void XXXDlg::OnCommMscommLaser()
{
	memset(chstrLaser, 0, 1024);    //chstrLaseris a global variable.

	short i = m_mscomLaser.get_InBufferCount(); // statement 1.
	if(m_mscomLaser.get_CommEvent() == 2) // An event value of 2 means there are characters in the receive buffer.
	{
		/*m_recivedMsg = "";
		
		CString csstr = "";*/

		VARIANT InputData = m_mscomLaser.get_Input(); //Statement 2, read buffer.

		COleSafeArray csa = InputData; //VARIANT variable is converted to COleSafeArray variable.

		//translate to byte class.
		DWORD size = csa.GetOneDimSize();
		for(long k = 0; k < size; k++)
			csa.GetElement(&k, chstrLaser + k);
	}

    // Further processing of the received data ......

	return;
}

Each time the function is triggered, the data length of the receive buffer obtained by statement 1 is 30, which means that the receive buffer has data with a length of 30. However, the above error prompt will appear in statement 2, and the code after statement 2 will not be executed.

2.Method exploration

1. At first, I thought it was a data line problem. By changing the data line and making the data line myself, the problem could not be solved.

2. I suspected that there was a problem with the communication equipment. I also changed the equipment for debugging, but the same problem still occurred.

3. Suspected that the communication protocol was not clear.

4. Wait

3. Solution

After many serial port debugging assistants failed, I found that a serial port debugging assistant can communicate normally. I will provide the debugging assistant later. The current problem may be that the code is written incorrectly, and the data cable and equipment are OK.

Through a large number of searches, I found that one solution was to update the serial driver. After trying, I found that it was really possible. After a whole day, I finally solved this problem. I was very excited.

Here is the solution:

1. Download serial driver

My is a USB to 232 data cable, so I downloaded the prolific USB to serial comm port driver. You can download the corresponding driver according to your actual situation. Here I provide the driver that solves my problem: Click to download the serial port driver.

2. Update driver

After downloading the driver, start updating the driver:

a. Click Manage – > Click device manager -> Locate the serial port configured through the MSComm control

b. Right click the serial driver and click Update Driver Software – > Select browse computer for driver software

c. Click Browse to find the downloaded serial driver

d. Click next to solve the above problems after updating.

C++: fatal error: variant: No such file or directory

Question

When compiling with C + + 17, you will be prompted with “fatal error: variant: no such file or directory” error;

reason

STD:: variant is a feature of C + + 17. Although I compiled and installed gcc7.5.0, I still prompted this error
with the help of colleagues, the problem was solved because GCC did not switch to GCC 7.5.0;

apt-get install gcc-7
apt-get install gcc-7 g++-7
rm /usr/bin/g++
ln -s /usr/bin/g++-7 /usr/bin/g++

Test

1. C + + variables doesn’t like file directories

Accounting subject

[Solved] Qt Vtk wglMakeCurrent failed in MakeCurrent(), error: The handle is invalid.

Problem description

The qvtkwidget control is used in QT’s interface. When clicking the close button in the upper right corner of the window, an error is reported: wglmakecurrent failed in makecurrent(), error: the handle is invalid .

Solution:

By overriding the void closeevent (qcloseevent * event) function, manually delete all qvtkwidget type controls, and then close the window.

Example

The qvtkwidget type controls in the QT design interface are as follows:

mymainwindow. H

class MyMainWindow : public QMainWindow
{
    Q_OBJECT
public:
    MyMainWindow(QWidget *parent = Q_NULLPTR);
protected:
	void closeEvent(QCloseEvent *event); 
private:
    Ui::MainWindow ui;
};

mymainwindow.cpp

MyMainWindow::MyMainWindow(QWidget *parent): QMainWindow(parent)
{
    ui.setupUi(this);
}

void MyMainWindow::closeEvent(QCloseEvent *event) {
	delete ui.qvtkWidget;
	delete ui.qvtkWidget_2;
	delete ui.qvtkWidget_3;
	delete ui.qvtkWidget_4;
	event->accept();
}

Postscript

I don’t know whether such hasty delete processing will cause other problems. I hope you can make more corrections.

C++: terminate called after throwing an instance of ‘std::length_error‘ (sort function cmp sorting rules problem)

Leetcode-539: encountered a big problem when brushing the minimum time difference:

Errors are reported as follows:

terminate called after throwing an instance of 'std::length_error'
  what():  basic_string::_M_create

The error code is as follows:

class Solution {
public:
    static bool cmp(string x,string y){ //Handwritten sorting rules Sort by chronological ascending order
        int Xshi= (x[0]-'0')*10+x[1]-'0';
        int Xfen= (x[3]-'0')*10+x[4]-'0';
        int Yshi= (y[0]-'0')*10+y[1]-'0';
        int Yfen= (y[3]-'0')*10+y[4]-'0';
        if(Xshi>Yshi || (Xshi==Yshi && Xfen> Yfen))  return false;
        else return true;
    }
    //input time has been sorted x is less than y to find two time minute difference function
    int Time_diff(string x,string y){
        int Xshi= (x[0]-'0')*10+x[1]-'0';
        int Xfen= (x[3]-'0')*10+x[4]-'0';
        int Yshi= (y[0]-'0')*10+y[1]-'0';
        int Yfen= (y[3]-'0')*10+y[4]-'0';

        int diff=(Yshi-Xshi)*60;
        if(Yfen>Xfen) diff+=Yfen-Xfen;
        else diff-=Xfen-Yfen;
        return diff;
    }
    int findMinDifference(vector<string>& timePoints) {
        //After sorting, compare the two adjacent to each other and also compare the first and last
        sort(timePoints.begin(),timePoints.end(),cmp);
        //compare the first and the last
        int T_min=min(  Time_diff(timePoints[0],timePoints[timePoints.size()-1]),  
                        1440-(Time_diff(timePoints[0],timePoints[timePoints.size()-1])) );
        //Two adjacent to each other for comparison
        for(int i=1;i<timePoints.size();i++)
        {
            T_min=min(T_min, Time_diff(timePoints[i-1],timePoints[i]) );
        }
        return T_min;
    }
};

Looking back and forth at the code, I was stunned that I couldn’t see any problems. I consulted hundreds of relevant web pages, basically for the following two reasons:

    1. an empty string was entered. The array subscript is out of bounds

However, these two problems are obviously not in my code. Finally, I checked all night and found the official description of sort sorting comparison.

https://en.cppreference.com/w/cpp/named_req/Compare

Let’s focus here:

In other words, for the CMP comparison function we handwritten, the following three points should be met:

      1. for all input a, input two identical elements, namely CMP (a, a). If the returned result is false, it cannot be false. If the result of entering CMP (a, b) is true, conversely, the result of entering CMP (B, a) is false, that is, if a > b. No more B > a. Otherwise, there will be contradictions. If the result of input CMP (a, b) is true, and the result of input CMP (B, c) is true, then the result of CMP (a, c) should also be true, which is also well understood. If a > B and B > C then a must be greater than C

Here, we should mainly pay attention to the first point. When the two numbers are the same, the returned result should be false, and my code:

    static bool cmp(string x,string y){ //Handwritten sorting rules Sort by chronological ascending order
        int Xshi= (x[0]-'0')*10+x[1]-'0';
        int Xfen= (x[3]-'0')*10+x[4]-'0';
        int Yshi= (y[0]-'0')*10+y[1]-'0';
        int Yfen= (y[3]-'0')*10+y[4]-'0';
        if(Xshi>Yshi || (Xshi==Yshi && Xfen> Yfen))  return false;
        else return true;
    }

This rule is not satisfied. So add one   =  Number to make it comply with the rules.

    static bool cmp(string x,string y){ //Handwritten sorting rules Sort by chronological ascending order
        int Xshi= (x[0]-'0')*10+x[1]-'0';
        int Xfen= (x[3]-'0')*10+x[4]-'0';
        int Yshi= (y[0]-'0')*10+y[1]-'0';
        int Yfen= (y[3]-'0')*10+y[4]-'0';
        if(Xshi>Yshi || (Xshi==Yshi && Xfen>= Yfen))  return false;
        else return true;
    }

The problem that bothered me all night was solved.

Debug error: abort() has been called error causes and Solutions

report errors

Error reporting reason

    pointer problems, such as illegal pointer access, pointer access out of bounds, memory leakage, memory out of bounds and insufficient memory allocation of multithreaded access resources. Check whether exe and DLL are mixed with different versions of CRT

    terms of settlement

      check that the requested space is not released. Check whether the stack space has been fully allocated. It is recommended that each memory allocation should not be too large, and remember that the release pointer points to an unexpected memory location

Module not found:Error:Can’t resolve ‘rc-animate/lib/CSSMotionList’ in ‘……’

explain

After the react project is compiled, sometimes the following error will be reported if you enter cnpm start

Add the following code to the package.json file to specify the version

"resolutions": {
  "css-animation": "1.5.0",
  "rc-animate": "2.8.2"
},

 

Add the following configuration in dependencies

"css-animation": "1.5.0",
"rc-animate": "2.8.2",

How to Solve Msys2/mingw64 Run cmake GUI Error

August 24, 2021
It has been updated to the latest version.

MINGW64 ~
$ cmake-gui –version
cmake version 3.21.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).

But still error as below:

$ cmake-gui
C:/msys64/mingw64/bin/cmake-gui.exe: error while loading shared libraries: zlib1.dll: cannot open shared object file: No such file or directory

Finally found that the installation of qt5 can be solved

pacman -S mingw-w64-x86_64-qt5
resolving dependencies…
looking for conflicting packages…
Packages (16) mingw-w64-x86_64-assimp-5.0.1-11  mingw-w64-x86_64-dbus-1.12.20-3  mingw-w64-x86_64-double-conversion-3.1.5-1  mingw-w64-x86_64-icu-debug-libs-68.2-3  mingw-w64-x86_64-libgcrypt-1.9.2-2
mingw-w64-x86_64-libgpg-error-1.42-1  mingw-w64-x86_64-libmng-2.0.3-4  mingw-w64-x86_64-libmysofa-1.2-1  mingw-w64-x86_64-libxslt-1.1.34-4  mingw-w64-x86_64-minizip-git-1.2.445.e67b996-2  mingw-w64-x86_64-openal-1.21.1-2
mingw-w64-x86_64-pcre2-10.36-1  mingw-w64-x86_64-qtbinpatcher-2.2.0-4  mingw-w64-x86_64-xpm-nox-4.2.0-6  mingw-w64-x86_64-z3-4.8.9-2  mingw-w64-x86_64-qt5-5.15.2-10
Total Download Size:   223.16 MiB
Total Installed Size:  873.75 MiB
…………………………

then re-run:

cmake-gui

You will be able to value the dialog box of the gui pop-up!

Error 1 error MSB3721: Command ““C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\nvcc.exe” -genco

Error 1 error msb3721: command “C:\program files\NVIDIA GPU computing toolkit\CUDA\v9.0\bin\nvcc. Exe” – gencode = arch = compute_ 20,code=“sm_ 20,compute_20” -gencode=arch=compute_ 30,code=“sm_30,compute_30” -gencode=arch=compute_50,code=“sm_50,compute_50” –use-local-env -ccbin “C:\Program Files
(cuda9.0targets 707)

Windows10 + cuda9.0 + cudnn + visual stdio2015 (originally, visual stdio2017 was used. Some blogs said no and changed it. If you downloaded 2017, you can directly change it at the change place. A single component will be OK under 2015. Some blogs talked about it and you can search it)

My computer graphics card version is gtx1050

After query, I changed compute and SM to compute_30,sm_30; compute_61,sm_ But it seems useless, but some bloggers say it’s useful, mainly because of different mistakes. You can try it.

I set the CUDA toolkit custom dir to C: \program files\NVIDIA GPU computing toolkit\CUDA at the beginning. When I opened the file, I found an error. It needs to be set to C: \program files\NVIDIA GPU computing toolkit\CUDA\v9.0

Then it’s solved. It’s been busy for two days. I’ve read a lot of blogs. I hope it can inspire you!!!

[Solved] Vs2015 error c2065: undeclared identifier error (__func__)

Problem: vs2015 compiles vtk8.2 with an error    Error c2065 undeclared identifier error (__ func__)

Solution: (two)

(1) Change the header file sequence online (the first method is tested, but it doesn’t work. It’s here temporarily, and the second method is effective)

#include "StdAfx.h"

Put it first

(2) Change,, name (test valid)

__func__ replace to __FUNCTION__

Test valid