本文介绍了DLL项目不在Visual Studio 2019中生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2019将项目构建到DLL中。但是,当我按下构建按钮时,出现了很多错误,这些错误表明我没有意识到自己的理解。我是c ++的新手,请对我好一点。

I'm using Visual Studio 2019 to build my project into DLL. But when i press build button a lot of errors appear that I didn't make ot that I didn't understand. I'm new in c++ so please be kind to me.

这是错误日志:

Severity    Code    Description Project File    Line    Suppression State
Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int    robocadSimLibCpp    D:\robocad\robocadSimLibCpp\robocadSimLibCpp\RE21mini.h 51
Error   C3646   'imageFromCamera': unknown override specifier   robocadSimLibCpp    D:\robocad\robocadSimLibCpp\robocadSimLibCpp\RE21mini.h 51
Error   C3646   'ReadCamera': unknown override specifier    robocadSimLibCpp    D:\robocad\robocadSimLibCpp\robocadSimLibCpp\RE21mini.h 62
Error   C2059   syntax error: '('   robocadSimLibCpp    D:\robocad\robocadSimLibCpp\robocadSimLibCpp\RE21mini.h 62
Error   C2238   unexpected token(s) preceding ';'   robocadSimLibCpp    D:\robocad\robocadSimLibCpp\robocadSimLibCpp\RE21mini.h 62
Error   C3646   'pathTMP': unknown override specifier   robocadSimLibCpp    D:\robocad\robocadSimLibCpp\robocadSimLibCpp\RE21mini.h 77
Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int    robocadSimLibCpp    D:\robocad\robocadSimLibCpp\robocadSimLibCpp\RE21mini.h 77
Error   C3646   'pathToMotors': unknown override specifier  robocadSimLibCpp    D:\robocad\robocadSimLibCpp\robocadSimLibCpp\RE21mini.h 78
Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int    robocadSimLibCpp    D:\robocad\robocadSimLibCpp\robocadSimLibCpp\RE21mini.h 78
Error   C3646   'pathToOMS': unknown override specifier robocadSimLibCpp    D:\robocad\robocadSimLibCpp\robocadSimLibCpp\RE21mini.h 79
Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int    robocadSimLibCpp    D:\robocad\robocadSimLibCpp\robocadSimLibCpp\RE21mini.h 79
Error   C3646   'pathToEncs': unknown override specifier    robocadSimLibCpp    D:\robocad\robocadSimLibCpp\robocadSimLibCpp\RE21mini.h 80
Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int    robocadSimLibCpp    D:\robocad\robocadSimLibCpp\robocadSimLibCpp\RE21mini.h 80
Error   C3646   'pathToLED': unknown override specifier robocadSimLibCpp    D:\robocad\robocadSimLibCpp\robocadSimLibCpp\RE21mini.h 81
Error   C3646   'pathToSensors': unknown override specifier robocadSimLibCpp    D:\robocad\robocadSimLibCpp\robocadSimLibCpp\RE21mini.h 82
Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int    robocadSimLibCpp    D:\robocad\robocadSimLibCpp\robocadSimLibCpp\RE21mini.h 81
Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int    robocadSimLibCpp    D:\robocad\robocadSimLibCpp\robocadSimLibCpp\RE21mini.h 82

还有80个类似我提供的错误。

And there are 80 errors like the ones I provided.

这是头文件:

// RE21mini.h
#pragma once

#ifdef ROBOCADSIMLIBCPP_EXPORTS
#define ROBOCADSIMLIBCPP_API __declspec(dllexport)
#else
#define ROBOCADSIMLIBCPP_API __declspec(dllimport)
#endif

#include <windows.h>
#include <opencv2/opencv.hpp>
#include <fileapi.h>
#include <fstream>


#define MAX_PATH 260

class ROBOCADSIMLIBCPP_API RE21mini
{
public:
    float rightMotorSpeed;
    float leftMotorSpeed;
    float backMotorSpeed;

    float liftMotorSpeed;
    float bigServoAngle;
    float smallServoDir;

    float rightMotorEnc;
    float leftMotorEnc;
    float backMotorEnc;
    float liftMotorEnc;

    bool resetRightEnc;
    bool resetLeftEnc;
    bool resetBackEnc;
    bool resetLiftEnc;

    bool resetGyro;

    bool buttonEMS;
    bool buttonStart;
    bool buttonLimit;

    float rightUS;
    float rightIR;
    float leftUS;
    float leftIR;

    float navX;

    Mat imageFromCamera;
    char* bytesFromCamera;

    RE21mini();

    void WriteMotors(float right, float left, float back);
    void WriteOMS(float lift, float big, float small_s);
    void WriteReset(bool right, bool left, bool back, bool lift, bool gyro);
    float* ReadEncs();
    float* ReadSensors();
    bool* ReadButtons();
    Mat ReadCamera();
    char* ReadCameraBytes();

    void WriteMotorsVoid();
    void WriteOMSVoid();
    void WriteResetVoid();
    void ReadEncsVoid();
    void ReadSensorsVoid();
    void ReadButtonsVoid();
    void ReadCameraVoid();
    void ReadCameraBytesVoid();

private:
    bool IsPathExist(const std::string& s);

    string pathTMP;
    string pathToMotors;
    string pathToOMS;
    string pathToEncs;
    string pathToLED;
    string pathToSensors;
    string pathToButtons;
    string pathToReset;
    string pathToCamera;
    string pathToOtherSet;
    string pathToOtherGet;

    string lastEncsRead = "0.0;0.0;0.0;0.0";
    string lastSensRead = "0.0;0.0;0.0;0.0;0.0";
    string lastButtonsRead = "0;0;0";

    DWORD dwBuffSize = MAX_PATH;
    char lpPathBuffer[MAX_PATH];

};

有人可以告诉我我必须做些什么来构建我的项目吗?

Can someone tell me what I have to do to build my project?

// RE21mini.cpp
#include "pch.h"
#include "RE21mini.h"

using namespace cv;
using namespace std;


RE21mini::RE21mini()
{
    dwBuffSize = MAX_PATH;
    lastEncsRead = "0.0;0.0;0.0;0.0";
    lastSensRead = "0.0;0.0;0.0;0.0;0.0";
    lastButtonsRead = "0;0;0";

    GetTempPathA(dwBuffSize, lpPathBuffer);
    pathTMP = lpPathBuffer;
    if (!IsPathExist(pathTMP + "RCADChannels"))
    {
        CreateDirectoryA((pathTMP + "RCADChannels").c_str(), NULL);
    }
    pathToMotors = pathTMP + R"(RCADChannels\motors.rcadch)";
    pathToOMS = pathTMP + R"(RCADChannels\oms.rcadch)";
    pathToEncs = pathTMP + R"(RCADChannels\encs.rcadch)";
    pathToLED = pathTMP + R"(RCADChannels\leds.rcadch)";
    pathToSensors = pathTMP + R"(RCADChannels\sensors.rcadch)";
    pathToButtons = pathTMP + R"(RCADChannels\buttons.rcadch)";
    pathToReset = pathTMP + R"(RCADChannels\reset.rcadch)";
    pathToCamera = pathTMP + R"(RCADChannels\camera.rcadch)";
    pathToOtherSet = pathTMP + R"(RCADChannels\otherSet.rcadch)";
    pathToOtherGet = pathTMP + R"(RCADChannels\otherGet.rcadch)";
}


//*****************************************BASIC FUNCTIONS******************************************************


void RE21mini::WriteMotors(float right, float left, float back)
{
    std::ostringstream rm(right);
    std::ostringstream lm(left);
    std::ostringstream bm(back);

    std::ofstream outfile(pathToMotors);
    outfile << rm.str() + ";" + lm.str() + ";" + bm.str();
    outfile.close();
}

void RE21mini::WriteOMS(float lift, float big, float small_s)
{
    std::ostringstream rm(lift);
    std::ostringstream lm(big);
    std::ostringstream bm(small_s);

    std::ofstream outfile(pathToOMS);
    outfile << rm.str() + ";" + lm.str() + ";" + bm.str();
    outfile.close();
}

void RE21mini::WriteReset(bool right, bool left, bool back, bool lift, bool gyro)
{
    std::ostringstream rr; rr << (int)right;
    std::ostringstream lr; lr << (int)left;
    std::ostringstream br; br << (int)back;
    std::ostringstream liftr; liftr << (int)lift;
    std::ostringstream gr; gr << (int)gyro;

    std::ofstream outfile(pathToReset);
    outfile << rr.str() + ";" + lr.str() + ";" + br.str() + ";" + liftr.str() + ";" + gr.str();
    outfile.close();
}

float* RE21mini::ReadEncs()
{
    std::string line;
    std::ifstream myfile(pathToEncs);
    if (myfile.is_open())
    {
        getline(myfile, line);
        myfile.close();
    }
    else return NULL;

    if (line.empty()) return NULL;

    std::string delimiter = ";";
    float mas[4] = {};

    size_t pos = 0;
    int ind = 0;
    std::string token;
    while ((pos = line.find(delimiter)) != std::string::npos) {
        token = line.substr(0, pos);
        mas[ind] = std::stof(token);
        line.erase(0, pos + delimiter.length());
        ind++;
    }
    return mas;
}

float* RE21mini::ReadSensors()
{
    std::string line;
    std::ifstream myfile(pathToSensors);
    if (myfile.is_open())
    {
        getline(myfile, line);
        myfile.close();
    }
    else return NULL;

    if (line.empty()) return NULL;

    std::string delimiter = ";";
    float mas[5] = {};

    size_t pos = 0;
    int ind = 0;
    std::string token;
    while ((pos = line.find(delimiter)) != std::string::npos) {
        token = line.substr(0, pos);
        mas[ind] = std::stof(token);
        line.erase(0, pos + delimiter.length());
        ind++;
    }
    return mas;
}

bool* RE21mini::ReadButtons()
{
    std::string line;
    std::ifstream myfile(pathToButtons);
    if (myfile.is_open())
    {
        getline(myfile, line);
        myfile.close();
    }
    else return NULL;

    if (line.empty()) return NULL;

    std::string delimiter = ";";
    bool mas[3] = {};

    size_t pos = 0;
    int ind = 0;
    std::string token;
    while ((pos = line.find(delimiter)) != std::string::npos) {
        token = line.substr(0, pos);
        mas[ind] = (bool)std::stoi(token);
        line.erase(0, pos + delimiter.length());
        ind++;
    }
    return mas;
}

Mat RE21mini::ReadCamera() {
    return cv::imread(pathToCamera);
}

char* RE21mini::ReadCameraBytes() {
    std::ifstream ifs(pathToCamera, std::ios::binary | std::ios::ate);
    std::ifstream::pos_type pos = ifs.tellg();

    // What happens if the OS supports really big files.
    // It may be larger than 32 bits?
    // This will silently truncate the value/
    int length = pos;

    // Manuall memory management.
    // Not a good idea use a container/.
    char* pChars = new char[length];
    ifs.seekg(0, std::ios::beg);
    ifs.read(pChars, length);

    // No need to manually close.
    // When the stream goes out of scope it will close the file
    // automatically. Unless you are checking the close for errors
    // let the destructor do it.
    ifs.close();
    return pChars;
}


//************************************************VOID FUNCTIONS****************************************************


void RE21mini::WriteMotorsVoid()
{
    std::ostringstream rm(rightMotorSpeed);
    std::ostringstream lm(leftMotorSpeed);
    std::ostringstream bm(backMotorSpeed);

    std::ofstream outfile(pathToMotors);
    outfile << rm.str() + ";" + lm.str() + ";" + bm.str();
    outfile.close();
}

void RE21mini::WriteOMSVoid()
{
    std::ostringstream rm(liftMotorSpeed);
    std::ostringstream lm(bigServoAngle);
    std::ostringstream bm(smallServoDir);

    std::ofstream outfile(pathToOMS);
    outfile << rm.str() + ";" + lm.str() + ";" + bm.str();
    outfile.close();
}

void RE21mini::WriteResetVoid()
{
    std::ostringstream rr; rr << (int)resetRightEnc;
    std::ostringstream lr; lr << (int)resetLeftEnc;
    std::ostringstream br; br << (int)resetBackEnc;
    std::ostringstream liftr; liftr << (int)resetLiftEnc;
    std::ostringstream gr; gr << (int)resetGyro;

    std::ofstream outfile(pathToReset);
    outfile << rr.str() + ";" + lr.str() + ";" + br.str() + ";" + liftr.str() + ";" + gr.str();
    outfile.close();
}

void RE21mini::ReadEncsVoid()
{
    std::string line;
    std::ifstream myfile(pathToEncs);
    if (myfile.is_open())
    {
        getline(myfile, line);
        myfile.close();
    }
    else return;

    if (line.empty()) return;

    std::string delimiter = ";";
    float mas[4] = {};

    size_t pos = 0;
    int ind = 0;
    std::string token;
    while ((pos = line.find(delimiter)) != std::string::npos) {
        token = line.substr(0, pos);
        mas[ind] = std::stof(token);
        line.erase(0, pos + delimiter.length());
        ind++;
    }
    rightMotorEnc = mas[0];
    leftMotorEnc = mas[1];
    backMotorEnc = mas[2];
    liftMotorEnc = mas[3];
}

void RE21mini::ReadSensorsVoid()
{
    std::string line;
    std::ifstream myfile(pathToSensors);
    if (myfile.is_open())
    {
        getline(myfile, line);
        myfile.close();
    }
    else return;

    if (line.empty()) return;

    std::string delimiter = ";";
    float mas[5] = {};

    size_t pos = 0;
    int ind = 0;
    std::string token;
    while ((pos = line.find(delimiter)) != std::string::npos) {
        token = line.substr(0, pos);
        mas[ind] = std::stof(token);
        line.erase(0, pos + delimiter.length());
        ind++;
    }
    rightUS = mas[0];
    leftUS = mas[1];
    rightIR = mas[2];
    leftIR = mas[3];
    navX = mas[4];
}

void RE21mini::ReadButtonsVoid()
{
    std::string line;
    std::ifstream myfile(pathToButtons);
    if (myfile.is_open())
    {
        getline(myfile, line);
        myfile.close();
    }
    else return;

    if (line.empty()) return;

    std::string delimiter = ";";
    bool mas[3] = {};

    size_t pos = 0;
    int ind = 0;
    std::string token;
    while ((pos = line.find(delimiter)) != std::string::npos) {
        token = line.substr(0, pos);
        mas[ind] = (bool)std::stoi(token);
        line.erase(0, pos + delimiter.length());
        ind++;
    }
    buttonEMS = mas[0];
    buttonStart = mas[1];
    buttonLimit = mas[2];
}

void RE21mini::ReadCameraVoid() {
    imageFromCamera = cv::imread(pathToCamera);
}

void RE21mini::ReadCameraBytesVoid() {
    std::ifstream ifs(pathToCamera, std::ios::binary | std::ios::ate);
    std::ifstream::pos_type pos = ifs.tellg();

    // What happens if the OS supports really big files.
    // It may be larger than 32 bits?
    // This will silently truncate the value/
    int length = pos;

    // Manuall memory management.
    // Not a good idea use a container/.
    char* pChars = new char[length];
    ifs.seekg(0, std::ios::beg);
    ifs.read(pChars, length);

    // No need to manually close.
    // When the stream goes out of scope it will close the file
    // automatically. Unless you are checking the close for errors
    // let the destructor do it.
    ifs.close();
    bytesFromCamera = pChars;
}

bool RE21mini::IsPathExist(const std::string& s)
{
    struct stat buffer;
    return (stat(s.c_str(), &buffer) == 0);
}



推荐答案

您可以尝试在 RE21mini.h 中添加头文件。

You could try to add header files in RE21mini.h.

#include <string>
#include "highgui.h"

using namespace cv;

cv::Mat ReadCamera();

这篇关于DLL项目不在Visual Studio 2019中生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 16:01