0

I was trying to compile a program, and one of the error that I was given while I was doing it was this:

g++ -o ./obj/Matriz2D.o ./src/Matriz2D.cpp -I./include -std=c++11
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/8.2.1/../../../../lib/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
/usr/bin/ld: /tmp/cc6kEtM3.o: in function `Matriz2D::Aniade(Secuencia)':
Matriz2D.cpp:(.text+0x4fd): undefined reference to `Secuencia::TotalUtilizados()'
/usr/bin/ld: Matriz2D.cpp:(.text+0x566): undefined reference to `Secuencia::Elemento(int)'
/usr/bin/ld: /tmp/cc6kEtM3.o: in function `Matriz2D::Inserta(int, Secuencia)':
Matriz2D.cpp:(.text+0x5bc): undefined reference to `Secuencia::TotalUtilizados()'
/usr/bin/ld: Matriz2D.cpp:(.text+0x6a0): undefined reference to `Secuencia::Elemento(int)'
/usr/bin/ld: /tmp/cc6kEtM3.o: in function `Matriz2D::Fila(int)':
Matriz2D.cpp:(.text+0x7b8): undefined reference to `Secuencia::Secuencia(int)'
/usr/bin/ld: Matriz2D.cpp:(.text+0x7ff): undefined reference to `Secuencia::Aniade(int)'
/usr/bin/ld: Matriz2D.cpp:(.text+0x814): undefined reference to `Secuencia::~Secuencia()'
/usr/bin/ld: /tmp/cc6kEtM3.o: in function `Matriz2D::Columna(int)':
Matriz2D.cpp:(.text+0x878): undefined reference to `Secuencia::Secuencia(int)'
/usr/bin/ld: Matriz2D.cpp:(.text+0x8bf): undefined reference to `Secuencia::Aniade(int)'
/usr/bin/ld: Matriz2D.cpp:(.text+0x8d4): undefined reference to `Secuencia::~Secuencia()'
collect2: error: ld returned 1 exit status
make: *** [makefile_sesion09.mak:74: obj/Matriz2D.o] Error 1

I've tried to delete from .cpp #include "Secuencia.h", from .h and at the same time in both of them but I didn't have success

jww
  • 97,681
  • 90
  • 411
  • 885
Kernel
  • 107
  • 1
  • 10

1 Answers1

0

If you don't ask otherwise, gcc will try to produce an executable binary. Just specifying .o extension to the output file does not change this. To just produce the object file, you need to add -c switch:

g++ -c -o ./obj/Matriz2D.o ./src/Matriz2D.cpp -I./include -std=c++11
hyde
  • 60,639
  • 21
  • 115
  • 176