Tag Archives: c++

Windows: How to Solve PCL C2065 Error

Solution of PCL running error under Windows

Configuration: vs2019 + pcl1 11.1+CMake3. twenty-two

The program has no problem, but there are a lot of error codes when running

Kdtree program

Solution:

Copy the program to a new txt file, save it, and then copy it to the vs2019 cpp document

Rerun results

reason

Maybe the program is downloaded from GitHub, and the coding method is wrong. It needs to be copied to TXT document for transcoding

How to Solve Ceres library Error when compiling A-LOAM

The C++ version in the CMakeLists for direct download of the A-LOAM library is 11, as follows:

cmake_minimum_required(VERSION 2.8.3)
project(aloam_velodyne)

set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS "-std=c++11")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g")

But Ceres 2.0 and above requires C++14 compiler, so you just need to change the C++ compiler to 14

cmake_minimum_required(VERSION 2.8.3)
project(aloam_velodyne)

set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS "-std=c++14")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g")

[Solved] ROS Error: Could NOT find move_base_msgs

Ubuntu18.04 + ROS melodic, catkin compile mbot error:

-- +++ processing catkin package: 'mbot_navigation'
-- ==> add_subdirectory(mbot_navigation)
-- Could NOT find move_base_msgs (missing: move_base_msgs_DIR)
-- Could not find the required component 'move_base_msgs'. The following CMake error indicates that you either need to install the package with the same name or change your environment so that it can be found.
CMake Error at /opt/ros/melodic/share/catkin/cmake/catkinConfig.cmake:83 (find_package):
  Could not find a package configuration file provided by "move_base_msgs"
  with any of the following names:
    move_base_msgsConfig.cmake
    move_base_msgs-config.cmake

 

Solution:

sudo apt-get install ros-melodic-move-base-msgs

MFC:: error C2065: “IDD_DIALOG1”: undeclared identifier Sending and handling custom messages in MFC threads

Just add the resource header file.

#include "Resource.h"

Send message in MFC thread

1. Write the meaning first and accept it

#define WM_SET_FOCUS WM_USER+100



BEGIN_MESSAGE_MAP(CWriteSnDlg, CDialogEx)
    //
	ON_MESSAGE(WM_SET_FOCUS, OnSetFocus)
END_MESSAGE_MAP()



	afx_msg LRESULT OnSetFocus(WPARAM wP, LPARAM lp);


LRESULT CWriteSnDlg::OnSetFocus(WPARAM wP, LPARAM lp)
{
	UNREFERENCED_PARAMETER(wP);
	UNREFERENCED_PARAMETER(lp);
	GetDlgItem(IDC_EDIT1)->SetFocus();
	return 0;
}

2. Send message

UINT  WriteSNProc(LPVOID  lParam){
    CWriteSnDlg *pWnd = (CWriteSnDlg *)lParam; 
    PostMessage(*pWnd,WM_SET_FOCUS, NULL,NULL);
    //SendMessage(*pWnd,WM_SET_FOCUS, NULL,NULL);
}



 PostMessage(this,WM_SET_FOCUS, NULL,NULL);

Debug Error: Failed to fetch current robot state [How to Solve]

Problem: when I write my own code to debug the manipulator, there is a problem after the rosrun node, as shown in the figure below

Solution: add the following two sentences at the entrance of the main function

ros::NodeHandle nh;
ros::AsyncSpinner spinner(1);

The reason is that movegroupinterface depends on ROS spinning, so just add the above two sentences before movegroupinterface

[Solved] AndroidStudio libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined referen

1. Error reporting:

The error of Android C + + OpenSSL link is as follows:

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined reference to 'sigfillset'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined reference to 'sigdelset'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined reference to 'sigdelset'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined reference to 'sigdelset'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined reference to 'sigdelset'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(ui_openssl.o):ui_openssl.c:function open_console: error: undefined reference to 'tcgetattr'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'signal'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'tcsetattr'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'tcsetattr'

clang++: error: linker command failed with exit code 1 (use -v to see invocation)

2. Reason:

Sigdelset, sigfillset and signal cannot be found in the SDK of Android

3. Solution:

Modify the minSdkVersion of build.grandle to a version number after 21:

apply plugin: 'com.android.application'
def LIBWEBRTC_HOME_PATH = "I:/webrtc/android/webrtc_m84_20201001/webrtc_android/src/"
//def LIBWEBRTC_HOME_PATH = "I:/webrtc/android/androidnativeapi/app/webrtc/"
android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "org.webrtc.examples.androidnativeapi"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                arguments "-DLIBWEBRTC_HOME_PATH=" + LIBWEBRTC_HOME_PATH,
                        "-DANDROID_STL=c++_static"
            }
        }
        ndk {
            abiFilters  "armeabi-v7a"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    sourceSets {
        main {
            // 1. configure the root directory libs to load third-party so libraries, (it is best not to create jniLibs, in the many open source libraries may cause conflicts, not yet found)
            // 2. automatically copy the so libraries in the libs directory to the specified directory when running
            // 3. If you don't need to recompile the so you created, you can copy the so generated by (app/build/intermediates/transforms) to this directory
            jniLibs.srcDirs = ['libs']
            // If it is a single folder, you can directly configure it as follows
            // jniLibs.srcDir 'libs'
        }
    }
    buildToolsVersion '28.0.2'//ADD
}
repositories {
    flatDir{
        dirs'libs'
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.aar"])

    //implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    //implementation(name: 'libwebrtc', ext: 'aar')
    //implementation 'org.webrtc:google-webrtc:1.0.+'
}

[Solved] QT Error: error: undefined reference to `GameModel::~GameModel()’

When compiling Qt program, error: undefined reference to `GameModel::~GameModel()’ is reported.
This is because Qt does not automatically generate the class destructor, so we need to write it ourselves, even if it is an empty function. After we write GameModel::~GameModel() by hand, the problem disappears when we compile it again.

There are two ways to write destructors:
Method 1:
in .cpp file:

Method 2:
in .h file.
in Destructor of

Opencv c++ Read Video Error: capture.isOpened() Return false

#include<iostream>
#include<opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main()
{
    VideoCapture capture;
    Mat frame;
    const string source = "/home/gear/big_disk_c/wangjd/shipintest/789.mp4";
    // frame= capture.open("789.mp4");
    frame= capture.open(source);
    if(!capture.isOpened())
    {
        printf("can not open ...\n");
        return -1;
    }
    printf("1213131\n");
    // namedWindow("output", CV_WINDOW_AUTOSIZE);

    while (capture.read(frame))
    {
        imshow("output", frame);
        waitKey(10);
    }
    capture.release();
    return 0;
}

Reason: Path. I have a permission problem with this server, and it will report an error if I write the full path. And the executable file I generated and the video file are not in the same directory, …/789.mp4 will not be read, only the two put together to read. Later I found out that
The constructor of capture.open() passed in a const string, so I instantiated a const string source first, then I could write the full path, and then passed it in.

const string source = "/home/gear/big_disk_c/wangjd/shipintest/789.mp4";
frame= capture.open(source);

[Solved] Compile Error: cannot open include file ‘afxres.h‘

Problem Description:

compilation error: cannot open include file ‘afxres h’


Cause analysis:

this is the header file of MFC class library</ font>


Solution 1:

If the MFC component is not installed, you can replace it with the next two lines

//#include "afxres.h"
#include <Windows.h>
#include <winres.h>
//Only one line winres.h is OK!

Solution 2:

Just install MFC components

[Solved] C++ Compile Error: prerequisites are different [How to Solve]

Scene

When adding new x.h/x.hpp/X.C/x.cpp files to the UE4 project, even if there are no other files to include these new files, the following errors may appear during compilation (both build and rebuild):
unrealbuildtool prerequisites are different
this error occurs when the x.obj file is compiled, but the link operation cannot be performed correctly

reason

As the name suggests, there is no problem with the code itself, but that the code block cannot be integrated into the existing project. UE4 has preprocessing on the path for the include file. If the path name of the file is duplicate, this problem will occur. For example:

1. Proto/error.pb.h already exists under module 

2. try to add Server/XXServer/proto/error.pb.h

According to the include rule of UE4, #include "proto/error.Pb.H" may point to two files at the same time (when the files in the server/xxserver directory are imported), so it cannot be judged accurately, and an error is reported during compilation.

Note: unrealbuildtool under Windows does not judge case, and the paths of proto/and proto/are the same

Solution:

    directory paths should not overlap. Try to avoid the path with the same name.
    1. There should be no files with the same name under the path