Error including header in QtCreator project

0

My question is how can I solve the following error:

In this case you have two different projects in QT. One of them contains a class called "Numbers".

File .h:

 #ifndef NUMEROS_H
 #define NUMEROS_H

 class Numeros
 {
 public:
     Numeros(int a, int b);
     Numeros();
     int suma();

 private:
     int m_a, m_b;
 };

 #endif // NUMEROS_H

.cpp file:

#include "numeros.h"

Numeros::Numeros(int a, int b):
   m_a(a), m_b(b)
{
}

Numeros::Numeros()
{
    m_a = 2;
    m_b = 3;
}

int Numeros::suma(){
    return m_a+m_b;
}

You want to use the "Numbers" class of the first project in the other project. For this, the route of Project 1 is included in the .pro file of Project 2 and the following code is written in the "main":

#include <iostream>

#include <numeros.h>

int main()
{

Numeros *s2;

s2 = new Numeros();

return 0;
}

When executing this program, the following error occurs:

main.obj: -1: error: LNK2019: unresolved external symbol "public: __cdecl Numbers :: Numbers (void)" (?? 0Numeros @@ QEAA @ XZ) referenced in function main

debug \ Proof2.exe: -1: error: LNK1120: 1 unresolved externals

How could it be solved? Thanks

    
asked by Adrian 26.09.2017 в 17:09
source

1 answer

0

If the files are not in the same folder as main.cpp you can simplify the inclusion path by adding search paths:

INCLUDEPATH += carpeta_con_includes

If you do not do this you have to write the complete inclusion path

#include "ruta_a_carpeta_con_el_include/numeros.h"
    
answered by 27.09.2017 / 07:35
source