Tag Archives: c++

error: non-const lvalue reference to type cannot bind to a value of unrelated type

Project scenario:

The error information reported during project code compilation is as follows:

error: non-const lvalue reference to type '...' cannot bind to a value of unrelated type '...'

Problem Description:

After the project problem is simply abstracted, it is equivalent to the following problems:

Do this and compile through

 int a;
 const double& m = a;

However, an error is reported in this compilation

 int a;
 double& m = a;

Error information such as title


Cause analysis:

Because temporary variables cannot be bound to a non const reference

 double& m = a;

a is an int variable that will be implicitly converted to a double variable, so this process generates a temporary variable. Non const reference cannot bind temporary variables


Solution:

Avoid implicit conversion or add const

error: ‘CLOCK_MONOTONIC‘ undeclared (first use in this function)

  Error message:

/home/xx/test/main.c: In function ‘main’:
/home/xx/test/main.c:37:21: error: storage size of ‘start’ isn’t known
   37 |     struct timespec start, end; //nanoseconds
      |                     ^~~~~
/home/xx/test/main.c:37:28: error: storage size of ‘end’ isn’t known
   37 |     struct timespec start, end; //nanoseconds
      |                            ^~~
/home/xx/test/main.c:43:5: warning: implicit declaration of function ‘clock_gettime’ [-Wimplicit-function-declaration]
   43 |     clock_gettime(CLOCK_MONOTONIC, &start);
      |     ^~~~~~~~~~~~~
/home/xx/test/main.c:43:19: error: ‘CLOCK_MONOTONIC’ undeclared (first use in this function)
   43 |     clock_gettime(CLOCK_MONOTONIC, &start);
      |                   ^~~~~~~~~~~~~~~
/home/xx/test/main.c:43:19: note: each undeclared identifier is reported only once for each function it appears in
make[2]: *** [CMakeFiles/WBSM4.dir/build.make:63: CMakeFiles/xx.dir/test/main.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/xx.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

Solution:

Add a compiler to the cmakelists.txt file:  

add_compile_options(-D_POSIX_C_SOURCE=199309L) 

Solution source [copyright infringement and deletion]:

c++ – error: ‘CLOCK_ MONOTONIC’ undeclared (first use in this function) – Stack Overflow

error: ‘CLOCK_ Mononic ‘undeclared problem solving_ Whahu 1989 column – CSDN blog

How to Solve Fatal error stdatomic in C/C++ Compilation

Fatal error: stdatomic. H: no such file or directory

Under Linux, errors are reported when compiling the source code using gcc

fatal error: stdatomic.h: No such file or directory
 #include <stdatomic.h>
                       ^
compilation terminated.

The reason is that the version of GCC 4.8 is too low and requires a higher version of GCC. How to safely upgrade the GCC version?

The devtoolset package can be installed through CentOS release SCL source

yum install centos-release-scl
yum install devtoolset-8

Or add your own source to install it (I’ll take centos7 as an example)

vi /etc/yum.repos.d/CentOS-SCLo-scl.repo
[centos-sclo-sclo]
name=CentOS-7 - SCLo sclo
baseurl=http://mirror.centos.org/centos/7/sclo/$basearch/rh/
#mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-sclo
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

Activate the GCC version to make it effective

scl enable devtoolset-8 bash

or

source /opt/rh/devtoolset-8/enable

At this time, you can see through the GCC — version command that the GCC version has changed to 8.X.x. it is worth noting that this only takes effect in the current bash. If it needs to take effect permanently, you can add environment variables yourself.

Successfully resolved error c3861: ‘printf’: identifier not found

Problem Description:

The error is as follows: error c3861: ‘printf’: identifier not found.

resolvent

The prompt indicates that the identifier “printf” cannot be found. I guess this may be caused by the compiler’s failure to include the header file stdio. H. then I wrote a new line #include & lt; stdio.h>, After that, the program will not report an error.

GCC compilation error unknown type name ‘bool’‘

Error description

unknown type name ‘bool’

Recently, using C to implement data structure encountered the following error

➜  LinkedList gcc list.c 
list.c:14:1: error: unknown type name ‘bool’; did you mean ‘_Bool’?
 bool is_empty(PNODE pHead);
 ^~~~
 _Bool
list.c:77:1: error: unknown type name ‘bool’; did you mean ‘_Bool’?
 bool is_empty(PNODE pHead)
 ^~~~
 _Bool
list.c: In function ‘is_empty’:
list.c:80:9: error: ‘true’ undeclared (first use in this function); did you mean ‘free’?
  return true;
         ^~~~
         free
list.c:80:9: note: each undeclared identifier is reported only once for each function it appears in
list.c:82:9: error: ‘false’ undeclared (first use in this function); did you mean ‘fclose’?
  return false;
         ^~~~~

Error reason

Unknown type name: ‘bool’, because there is no boolean type defined in the C language standard (C89), an error will be reported. C99 provides a header file & lt; stdbool.h> defines bool , true represents 1 and false represents 0. As long as you import stdpool. H , you can easily operate Boolean types.

resolvent

#include <stdbool.h>

"21442;" 32771;"38142;" 25509

https://www.jianshu.com/p/aa951e784e96

C++:error C2872: ‘byte‘: ambiguous symbol [How to Solve]

The reason is to merge two project programs written by others. There is no problem with separate testing. After merging, compile and report errors

After searching the data, it is suspected that it is related to the header file windows.H

#include<math.h>
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <windows.h> // Commented out to compile properly
#include <map>
#include <any>

My solution is to #include <windows.h> comment it out (the header file is not used in the code), and then it can run successfully. I didn’t delve into the specific reasons, mainly by referring to the reference materials at the end of the article.

[Solved] QT Warning: Slots named on_foo_bar are error prone

Problem phenomenon:

Cause:
this warning appears because when processing the signal slot relationship, we use “go-to slot” in the UI designer to make the program generate automatically
the weakness of this automatic generation is that one day, you may change the name of the control in the UI designer, but the compilation will not report an error. The program still runs normally, and the compilation does not prompt errors
in this way, the control is equivalent to not being connected to the slot function and becomes invalid.

Recommended solution:
recommendation 1: do not automatically generate signal slot connection through “go to slot” of UI designer. The relationship can be established manually. For example:
connect (toolbutton, & QPushButton:: clicked,
this, & yourclassname:: nameofyourslot)
recommendation 1: ignore this warning and just ignore it. Because this is just a kind reminder.

[Solved] Error: In the Function of ‘fmt::v8::detail::error_handler::on_error(char const*)’

1. Reasons

The FMT.H and related dynamic link files were not found

2. Solutions

Download FMT package, compile, install and call

git clone https://hub.fastgit.org/fmtlib/fmt.git
cd fmt
mkdir build
cmake ..
make
sudo make install

Called in the project cmakelists.txt

find_package(FMT REQUIRED)
target_link_libraries(Name of the executable file fmt::fmt)

Error c2375: “wsacleanup”: redefine; Different links, etc

Error c2375: “wsacleanup”: redefine; Different links, etc

Solution

Solution

By default, windows. H will contain Winsock. H. When you include Winsock 2. H, it will conflict. Therefore, before including windows. H, you need to define a macro to remove Winsock. H

Scheme 1
in #include & lt; windows.h> Add #define Win32 to the previous line_ LEAN_ AND_ Mean// remove some uncommon
scheme 2
Project attribute – C/C + + – preprocessor – preprocessor definition
manually add a macro:
Win32_ LEAN_ AND_ MEAN;

[Solved] PySide2 Error: This application failed to start because no Qt platform plugin could be initialized

PySide2 Error: This application failed to start because no Qt platform plugin could be initialized
Add at the first:

import sys,os
import PySide2
 
dirname = os.path.dirname(PySide2.__file__)
plugin_path = os.path.join(dirname, 'plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path

[Solved] opencv-python: recipe for target ‘modules/python3/CMakeFiles/opencv_python3.dir/all‘ failed

1. Question.
Python3.8 environment
When using pip3 to install opencv-python, there is a
[modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o] Error 1
recipe for target ‘modules/python3/CMakeFiles/opencv_python3.dir/all’ failed

2. Cause.
When compiling in opencv-python, it cannot call python3.8 properly
3. Solution:
sudo apt-get install python3.8-dev
4. Successful installation