Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22097

Compiling C++ in VSCode gives me an undefined reference

$
0
0

normally i use VS19 for C++ programming, but i wanted to try if it works on VSCode on my Macbook, so i wrote i real simple programm

main

#include <iostream>
#include "test.hpp"
using namespace std;

int main()
{
  testfile obj(5);
  cout << "main.cpp"<< endl;
  obj.output();
  return 0;
}

class header (.hpp)

#pragma once
using namespace std;

class testfile
{
private:
  int i;
public:
  testfile(int in) : i(in) {}
  void output();
};

class file (.cpp)

#include "test.hpp"
#include <iostream>
using namespace std;

void testfile::output()
{
  cout << i << endl;
}

i know i could write the little output in the header, but i want to try if it works if the code is split up into many different files. I get the following error:

(PATH)..\Temp\ccITg6NM.o:main.cpp:(.text+0x48): undefined reference to `testfile::output()' collect2.exe: error: ld returned 1 exit status

the same goes for my windows laptop. I ran the exact same code on Visual Studio and it worked perfectly fine. I tried googling the error but tbh, i didn't got anything out of it...

i run VSCode with C/C++ intellisense and the compile & run plugin.


Viewing all articles
Browse latest Browse all 22097

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>