error: Id returned 1 exit status

I have to make a program that codes it's own queue(cola) class for plane(avion) type objects, but when compiling I receive this message without information of what line has caused the problem. I'd be very grateful if someone can tell me what's wrong with my code because this is driving me crazy.

The error message is;
=== Build: Debug in Prac1 (compiler: GNU GCC Compiler) ===
error: Id returned 1 exit status
=== Build failed: 1 error (s), 0 warning (s) (0 minute (s), 0 second (s)) ===

-------------- Build: Debug in Prac1 (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -o bin\Debug\Prac1.exe obj\Debug\Avion.o Avion.h.gch obj\Debug\Cola.o obj\Debug\main.o obj\Debug\Nodo.o
Avion.h.gch: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))

My code:

Cola.h (queue)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef COLA_H_INCLUDED
#define COLA_H_INCLUDED
#include <string>
#include "Avion.h"
#include "Nodo.h"

using namespace std;

class Cola
{
public:
    Cola();
    ~Cola();
    void encolar(Avion);
    string desencolar();

private:
    pnodo ultimo, primero;
};

#endif 


Cola.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "Cola.h"
#include <cstddef>

using namespace std;

Cola::Cola()
{
    ultimo = NULL;
    primero = NULL;
}

Cola::~Cola()
{
    while(primero) desencolar();
}

void Cola::encolar(Avion a)
{
    pnodo nuevo;
    nuevo = new Nodo(a);
    if (ultimo) ultimo->siguiente = nuevo;
    ultimo = nuevo;
    if (!primero) primero = nuevo;
}

string Cola::desencolar()
{
    pnodo nodo;
    string a;
    nodo = primero;
    if(!nodo) return NULL;
    primero = nodo->siguiente;
    a = nodo->avion.getId();
    delete nodo;
    if(!primero) ultimo = NULL;
    return a;
}


Avion.h (plane)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef AVION_H_INCLUDED
#define AVION_H_INCLUDED
#include <string>

using namespace std;

class Avion{
    private:
        string id, origen, destino;
        int hSalida, hDestino, hLlegada, tEspera, combustible;

    public:
        Avion();
        Avion(string, string, string, int, int, int, int, int);
        string getId();
        int getHDestino();
        int getHLlegada();
        int getTEspera();
        int getCombustible();
};


#endif 


Avion.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "Avion.h"

using namespace std;

Avion::Avion()
{

}

Avion::Avion(string iden, string orgn, string dest, int hS, int hD, int hL, int tE, int c)
{
    id = iden;
    origen = orgn;
    destino = dest;
    hSalida = hS;
    hDestino = hD;
    hLlegada = hL;
    tEspera = tE;
    combustible = c;
}

string Avion::getId()
{
    return id;
}

int Avion::getHDestino()
{
    return hDestino;
}

int Avion::getHLlegada()
{
    return hLlegada;
}

int Avion::getTEspera()
{
    return tEspera;
}

int Avion::getCombustible()
{
    return combustible;
}


Nodo.h (node)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef NODO_H_INCLUDED
#define NODO_H_INCLUDED
#include "Avion.h"

using namespace std;

class Nodo
{
    private:
        Avion avion;
        Nodo *siguiente;
        friend class Cola;

    public:
        Nodo(Avion);
};

typedef Nodo *pnodo;


#endif 


Nodo.cpp
1
2
3
4
5
6
7
8
9
10
#include "Nodo.h"
#include <cstddef>

using namespace std;

Nodo::Nodo(Avion a)
{
    avion = a;
    siguiente = NULL;
}


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include "Cola.h"
#include "Avion.h"
#include "Nodo.h"

using namespace std;

int main()
{
    Cola c = Cola();
    Avion a1("ES1111", "MAD", "AGP", 1600, 1700, 1710, 0005, 40);
    Avion a2("GP0432", "CDG", "AGP", 1550, 1655, 1705, 0010, 35);
    c.encolar(a1);
    c.encolar(a2);
    cout << c.desencolar();
    cout << c.desencolar();
    cout << c.desencolar();

    return 0;
}
Last edited on
Why don't you say what compiler you are using? All modern compilers that I know of will say the line number that something is failing on.

I didn't actually compile your code, but while reading through it, I notice you have the following:
1
2
3
4
5
6
7
string Cola::desencolar()
{
    pnodo nodo;
    string a;
    nodo = primero;
    if(!nodo) return NULL;
    ....


NULL is the old way of signifying that you want to return a null pointer. It is most likely just a #defined way of saying 0. (i.e. #define NULL 0 ).

Your method expects a string to be returned -- you are trying to return a pointer or int.


Edit: Didn't realize std::string s = 0; is legal in C++... ignore this post.
Last edited on
Please post the FULL output text from your compiler.

if the message is "ld returned exit status 1", that's generally an indication of a linker error.
The linker output (which you haven;t shown) should give an indication of the problem.
Last edited on
I've edited the post with the full output I receive.

Usually when I have an error GCC indicates the line where it's been produced, but apparently not this time.

Also I've changed the line:
1
2
3
4
5
string Cola::desencolar()
{
...
if(!nodo) return NULL;
...


For:

1
2
3
4
5
string Cola::desencolar()
{
...
if(!nodo) return " ";
...


And it hasn't solved it.
According to your edited post, it doesn't know what GCH files are.
GCH seem to be GCC pre-compiled header files. Pre-compiled headers are used to reduce compilation time.

However, as far as I know, pre-compiled headers do not work on mingw32.

I would say, try cleaning your workspace/directories and re-compile/link.
If that doesn't work, perhaps someone more experienced in pre-compiled headers or MinGW can help.

(PS: I forgot that C++ allows for implicit conversion from integer to string, so my previous post is irrelevant)
Last edited on
Just updated with the Build log, if it's of any use.
closed account (1vf9z8AR)
I think you have not included the avion.h file in your compiler.Some files have to be added manually to the compiler
Well I've solved the problem, just had to uncheck "Compile File" and "Link File" in the properties of Avion.h so the compiler wouldn't make that gch file. I use Code::Blocks by the way. Thanks for the help.
Note that both std::string s = 0; and if(!nodo) return NULL; exhibit undefined behavior.
Among every possible integer literal, only the literal zero is also a null pointer constant.
That is, in this context, 0 is implicitly converted to a char*, and used to copy-initialize s. The behavior is undefined, because the null pointer doesn't point to a zero-terminated array of characters.

See the fifth constructor overload here:
http://en.cppreference.com/w/cpp/string/basic_string/basic_string
http://eel.is/c++draft/string.cons#12
Last edited on
Thanks for the gotcha info, mbozzi.
Topic archived. No new replies allowed.