0

I've researched a lot for this problem, but I can´t find what exactly is causing the error.

I'm using VS 2017 and this is my header file

#ifndef FUNCTION_H
#define FUNCTION_H 
#include <iostream>
#include <vector>
#include <map>

extern "C" {
#include "extApi.h"
}

void BufferToMatrix(simxUChar* buffer, unsigned int** matrix, int dim_fil, int dim_col);
void PrintMatrix(unsigned int** matriz, int dim_fil, int dim_col);

class Graph
{
        // representacion por Adjacency List
        std::vector<std::vector<int>> graph;
        std::map<int, std::vector<int>> neighbors;  // Los nodos posibles, orden izquierda, abajo, derecha, arriba

public:
        // Constructores crean el numero de nodos basados en una matriz
        Graph(unsigned int**, int, int);
        ~Graph();

};

#endif

and the .cpp file

#include <iostream>
#include <vector>
#include <map>

extern "C" {
#include "extApi.h"
}

using namespace std;

void BufferToMatrix(simxUChar* buffer, unsigned int** matrix, int dim_fil, int dim_col)
{
    // Sacamos la data del buffer, dim_fil = res[1] y dim_col = res[0]
    for (int i = 0; i < dim_fil; i++) // filas
    {
        for (int j = 0; j < dim_col; j++) // Columnas
        {
            matrix[j][dim_fil-1 - i] = buffer[i*dim_col + j]; // Matriz con las filas invertidas... el buffer lo entrega asi.
        }
    }
}

void PrintMatrix(unsigned int** matriz, int dim_fil, int dim_col)
{
    // Imprimimos la matriz en consola
    for (int i = 0; i < dim_fil; i++) // filas
    {
        for (int j = 0; j < dim_col; j++) // columnas
        {
            cout << matriz[j][i] << " ";
        }
        cout << endl;
    }
}

Graph::Graph(unsigned int** map, int dim_fil, int dim_col) {}

Graph::~Graph() {}

and the main so far

#include <iostream>
#include "function.h"
#include "function.cpp"

extern "C" {
#include "extApi.h"
}

using namespace std;

int main(int argc, char* argv[])
{
    // Obtenemos los Handlers enviandos en la llamada del ejecutable
    int portNb = 0;
    int mappingSensorHandle = 0;
    //int leftMotorHandle = 0;
    //int rightMotorHandle = 0;
    //int graphHandle = 0;
    //int proximitySensorHandle = 0;

    if (argc >= 3)
    {
        portNb = atoi(argv[1]);
        mappingSensorHandle = atoi(argv[2]);
        //leftMotorHandle = atoi(argv[3]);
        //rightMotorHandle = atoi(argv[4]);
        //graphHandle = atoi(argv[5]);
        //proximitySensorHandle = atoi(argv[6]);
    }
    else
    {
        cout << "Es necesario indicar los handlers en V-rep" << endl;
        extApi_sleepMs(5000);
        return 0;
    }

    // Iniciamos la simulacion
    int clientID = simxStart((simxChar*)"127.0.0.1", portNb, true, true, 2000, 5);
    if (clientID != -1)
    {
        // Declaraciones de variables auxiliares
        int retVal = 0;
        bool OneTimeFlag = 0;

        // Declaraciones de variables, lectura del mapa
        simxInt res[2];                 //res[0] son columnas y res[1] son filas
        simxUChar* image;               //apuntador al arreglo con la data del sensor de vision 
        simxUChar options = 1;          //en 1 recibe en escala de grises, en 0 recibe en rgb

        // Habilitamos el Streaming del mapa
        simxGetVisionSensorImage(clientID, mappingSensorHandle, res, &image, options, simx_opmode_streaming);
        OneTimeFlag = 1;

        // Creamos una matriz dinamica para el mapa
        unsigned int** map = new unsigned int* [res[1]];
        for (int i = 0; i < res[1]; i++)
        {
            map[i] = new unsigned int[res[0]];
        }

        // Loop de la simulacion en V-rep
        while (simxGetConnectionId(clientID) != -1)
        {
            if (OneTimeFlag)
            {
                retVal = simxGetVisionSensorImage(clientID, mappingSensorHandle, res, &image, options, simx_opmode_buffer);
                if (retVal == simx_return_ok)
                {
                    BufferToMatrix(image, map, res[1], res[0]);     // Llenamos la matriz
                    PrintMatrix(map, res[1], res[0]);               // Imprimimos la matriz en CMD
                    OneTimeFlag = 0;                                // Colocamos la flag en 0 para no ejecutar esta parte
                }

                // Creamos el grafo y el SpanningTree
                //Graph grafo(map, res[1], res[0]);

            }







        }

        // Borramos la matriz del mapa
        for (int i = 0; i < res[1]; i++)
        {
            delete [] map[i];
        }
        delete [] map;

        simxFinish(clientID);
    }

    else
    {
        // Terminamos la simulacion, no se realizo la conexion
        cout << "Conexion no lograda" << endl;
        simxFinish(clientID);
        return(0);
    }
    return(0);
}

this is a script to use a external API in V-rep, the only lines that cause trouble is this two lines in the .h file

std::vector<std::vector<int>> graph;
std::map<int, std::vector<int>> neighbors;

Cause this problems:

Error LNK2001 símbolo externo __imp___CrtDbgReport sin resolver.

Error LNK2001 símbolo externo __imp___invalid_parameter sin resolver.

Error LNK1120 2 externos sin resolver coverageBotClient.

I apologize because this is to simple but I can´t see the error.

  • 3
    You have to include `` header as well. Try it and see. – P.W Jan 30 '19 at 05:50
  • 3
    What does your cpp file look like? It's hard to imagine those errors from this code alone. – Retired Ninja Jan 30 '19 at 05:51
  • Make sure you haven't crossed debug files with a release build. – user4581301 Jan 30 '19 at 05:56
  • post your main code if possible – gameon67 Jan 30 '19 at 06:24
  • the include of if necesary of course, but is not the problem. Also a edit the topic and post the .cpp and the main. – Domingo Luis Jan 30 '19 at 13:44
  • What you could try is to make a *new* project that contains just the three files you posted. Maybe you will have to make some adjustments, e.g. replace `#include "extApi.h"` with `using simxUChar = int;` or something like that. Then: Does it compile? If yes, maybe you forgot to link a library. If no, then what is the error message? Try to eliminate code until it compiles. Try to reduce the code (or "dependancies" or the "haystack") you have to search in. – TobiMcNamobi Jan 30 '19 at 14:03
  • "extApi.h" is the library for v-rep I can´t change it, the problem is the vector, something happen with Visual Studio 2017, if I declare a vector the link error appear – Domingo Luis Jan 30 '19 at 14:11
  • after more research I find this https://stackoverflow.com/questions/6003368/unresolved-externals-in-c-when-using-vectors-and-find, it looks like the _DEBUG in the preprocessor configuration is the problem. user4581301 was right – Domingo Luis Jan 30 '19 at 14:27

0 Answers0