When linking some object files together using ld
, an error occurs:
undefined reference to symbol 'chdir@@GLIBC_2.2.5'
undefined reference to symbol 'setlocale@@GLIBC_2.2.5'
Do I need to link a library for this function? The manpage does not say anything about linking.
C and C++ share a notion of what a standard library is: it is a bunch of libraries that are always available in the C (or C++) build tool.
The problem is that ld
is a far more generic tool: it can be used to link C, C++, Fortran, assembly language, etc. The compilers know how to pass specific options to the loader to ask it to find the relevant libraries, but when you directly use ld
, you have to pass them explicitely.
Alternatively, avoid using ld
and always use c++
(or g++
or whatever name your compiler is called) even for simply linking.