Tag Archives: c++

self._handle = _dlopen(self._name, mode) OSError: [WinError126] The specified module could not found

When doing the project, due to the need to do DLL to speed up, but often burst out error

File "C:\Users\32373\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 434, in LoadLibrary
    return self._dlltype(name)
  File "C:\Users\32373\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

The example code is as follows

from ctypes import cdll
class Demo():
	def __init__(self):
		self.__path = "ZeissControl2.dll"
		self.__Library = cdll.LoadLibrary(self.__path)

It’s also a bug that has been bothering me for a long time.
for this problem, I summarize two reasons:

    the first thing is to check whether the path of the DLL file is correct. If it is correct, that is the second reason. When we generate a custom DLL, we usually rely on a variety of other DLL files, so we need to add other DLL files that the DLL calls depends on to the program running directory. In this case, the program can run perfectly in general

    However, in general, in addition to the specified DLL files, user-defined DLL files may also rely on the DLL files of the system environment
    in the latter case, we generally do not know which DLL files we rely on

    Fortunately, Visual Studio provides dumpbin/dependencies tool to get the list of DLL files that the specified DLL depends on
    specific operation
    Start Menu = & gt& gt; visual studio 2017 or 2019 ===>& gt; Developer Command Prompt for VS 2017 or 2019

    After opening the terminal and entering the dumpbin command, you can see that

    we want to view the list of other DLL files that the specified DLL file depends on. The command is as follows

    dumpbin /dependents your_ dll_ path

    For example,

error C2065: ‘_beginthread‘ : undeclared identifier

error C2065: ‘_ beginthread’ : undeclared identifier

First, include & lt; process.h> Header file. If an error is reported, set the engineering parameters as follows:
Project – & gt; Select the C/C + + page in settings… And then select code generation in category, and then select multithreaded (or multithreader DLL or debug multithreader DLL or debug multithreader) in use runtime library below it

If you still report an error, put the following two sentences at the beginning of the cpp file
extern “C” unsigned long __ cdecl _ beginthread (void (__ cdecl *) (void *),
unsigned, void *);
extern “C” void __ cdecl _ endthread(void);

The test is effective
this is equivalent to manually declaring the two functions.

Qt development, using ODBC interface, query mysql, appear qsqlquery:: Value: not positioned on a valid record

Qt development, using ODBC interface, query mysql, appear qsqlquery:: Value: not positioned on a valid record

Question: in the library management system developed by QT craetor integrated development environment, the newly created database class is used to operate the database. It inherits from QObject and uses the interface provided by ODBC to connect with the database. The database is mysql5.7, When using the following query statement, we report an error:

error information: qsqlquery:: Value: not positioned on a valid record

we query the relevant information:
the solutions we have found
try according to the solutions provided in the article, the problems still exist.

Later, some information was printed in various locations, and it was found that qdebug & lt& lt; condition<& lt; content<& lt;“ The variables condition and content in “on” can be printed normally, but “on” printed out is “?”
when I thought of creating a window before, the window title set in Chinese would be garbled. The solution I found at that time was to add the following code to the. Cpp file of the corresponding class:
?Pragma execution_ character_ set("utf-8")

Solution:
add the code block as shown above to the database.cpp file:

edit test information:

test output successful:

end! Scatter flowers! Record it!

[Solved] C++ error: undefined reference to `xxx‘

        Error: undefined reference to ` xxx ‘in C + + means that an undefined method is referenced. There are many reasons for this problem. Here are two problems I encountered.

1. The corresponding header file is not referenced or the versions of library functions referenced in the header file are inconsistent. In different versions of libraries, the names of the same implementation method may be inconsistent, which causes this problem.

2. The method of using extern keyword is wrong. There are many uses of extern. The function of extern here is to refer to functions of other files.

a.h:

//a.h

#ifndef AH
#define AH

extern int test();//Here the return type and parameters must be the same as the implementation method

#endif

aaa.cpp

//aaa.cpp

#include <stdio.h>
#include <iostream>
#include "a.h"  //Both need to refer to the corresponding header file, otherwise an error will be reported

using namespace std;

int test()
{
cout << "abc" <<endl;
}

bbb.cpp

//bbb.cpp

#include <stdio.h>
#include <iostream>
#include "a.h" //Both need to refer to the corresponding header file, otherwise an error will be reported


int main()
{
    test();
}

Results of operation:

If any cpp file does not refer to the corresponding header file, an error will be reported.

Vscode compiles multiple files, compiles files in subfolders

Shame to say, in fact, for vscode configuration, the writer of C/C + + only referred to the tutorial, and then copied several JSON files, but did not understand the meaning.

For this problem, we need to solve the compilation problem, so in task.json, my configuration file is as follows

in which two parameters are command and args

Command: compiler for compilation args: command for compilation

As a matter of fact, it can be seen from the familiar partners of GCC. Here we post the parameter

so we need to connect our file names. The workspace in front represents the workspace, so we only need to write our own directory name at the back, as shown in the figure of linear_ List, connect them.

How to Use qdbusinterface to call DBUS interface

        // Create QDBusInterface
        QDBusInterface iface("org.onboard.Onboard",
                             "/org/onboard/Onboard/Keyboard",
                             "org.onboard.Onboard.Keyboard");
        if (!iface.isValid()) {
            qInfo() << qPrintable(QDBusConnection::sessionBus().lastError().message());
        }
        QDBusReply<void> reply = iface.call("Show");
        if (reply.isValid()) {
            qInfo() << "call org.onboard.Onboard.Keyboard success";
            return;
        }
        qInfo() << "call corg.onboard.Onboard.Keyboard failed" << reply.error();
    });

Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools“

Alipay’s online payment function has recently been developed to download and pay the SDK package. The wrong presentation is as follows:
reported false prompts: Microsoft Visual C++ 14 or greater is required. Get it it ” https://visualstudio.microsoft.com/visual-cpp-build-tools/

Reason: python3 is compiled with VC + + 14, python27 is compiled with C + + 9, and the package to install python3 needs to be compiled with C + + 14 or above

Don’t panic for small scenes

That’s the thing above. Double click the installation. Do you think it’s over?

In case of no accident, most of the installation packages you download will finally prompt you: the installation package is missing or damaged
some netizens say that it can succeed with a ladder, and others say that it can’t succeed
I uploaded an offline version here. You can try

ROS generate_messages_cpp [Compiler error resolution]

ROS generate_ messages_ Solution of CPP compilation error

Learning the knowledge of C + + and python joint programming under ROS, there is an error report when compiling cpp file, the following process is recorded:

    1. in the reference → Article 1 ← for configuration, the insertion of CPP and py has been completed, and

catkin is performed_ There are errors in the make

    1. steps, and the error contents are as follows:
CMake Error at my_pkg/CMakeLists.txt:27 (add_dependencies):
  The dependency target "my_pkg_generate_messages_cpp" of target "listener"
  does not exist.

The cmake version is adjusted according to Article 2 ←, and no error is reported. The principle is that cmake before 3.0 will turn this error report into a warning, and it has passed the compilation, but in actual use, it is still unable to find the listener program built from CPP. Finally, the cmakelists is adjusted according to Article 3 ←,
– first of all, Add the following code block:

catkin_package(
 INCLUDE_DIRS include
# LIBRARIES strands_gazing
 CATKIN_DEPENDS std_msgs
# DEPENDS system_lib
)

After that, in Add_ Added ${catkin> to dependencies _ EXPORTED_ Targets} finally, when compiling, execute catkin first_ make --pkg my_ PKG (here is the PKG name) , and then execute catkin_ Make problem solving

Finally, the revised cmakelists :

cmake_minimum_required(VERSION 3.0.2)
project(my_pkg)

## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
)

catkin_package(
  INCLUDE_DIRS include
# LIBRARIES strands_gazing
  CATKIN_DEPENDS std_msgs
# DEPENDS system_lib
)

include_directories(include/my_pkg ${catkin_INCLUDE_DIRS}) 
add_executable(listener src/listener.cpp) 
target_link_libraries(listener ${catkin_LIBRARIES}) 
add_dependencies(listener my_pkg_generate_messages_cpp ${catkin_EXPORTED_TARGETS})