SPLASH SPLASH - 1 month ago 11
C++ Question

What is /var/tmp//ccz0ct2G.o?

So, I'm running a CPU scheduling smulation code but I came across a few errors while compiling

Undefined first referenced
symbol in file
std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /var/tmp//ccz0ct2G.o
std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&)) /var/tmp//ccz0ct2G.o
std::cout /var/tmp//ccz0ct2G.o
std::basic_ofstream<char, std::char_traits<char> >::close() /var/tmp//ccz0ct2G.o
std::ios_base::Init::~Init() /var/tmp//ccz0ct2G.o
std::ios_base::Init::Init() /var/tmp//ccz0ct2G.o
std::basic_ios<char, std::char_traits<char> >::operator!() const /var/tmp//ccz0ct2G.o
__gxx_personality_v0 /var/tmp//ccz0ct2G.o
std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) /var/tmp//ccz0ct2G.o
std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(char const*, std::_Ios_Openmode) /var/tmp//ccz0ct2G.o
std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&) /var/tmp//ccz0ct2G.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status


I don't understand why I'm getting these errors and what is
/var/tmp//ccz0ct2G.o
?

Almost all the errors have it.

Answer

I don't understand why I'm getting these errors

Your program tries to use something that's part of an external library or a different object file, but you're not passing that to the linker as well.

and what is /var/tmp//ccz0ct2G.o?

A temporary object file, that contains intermediate data that's going to be used in later stages of the compilation process.

Let me guess: You tried to compile with a command that went something like

g++ somesource.cc

You see, compilation consists of several stages:

1. compiling the individual source files (`*.c`, `*.cc` and so on) into *object files* (`*.o`).
2. linking the produced object files together into the actual program or library

When you call the compiler like you did, this is a shorthand that does both operations from a single call. But for the sake of simplicity and also because object files can grow rather large and it can pose a problem to keep them all in memory, the result of compiling the source file is placed into a temporary object file. That's what you have there.

Comments