.tpp
is not one of the file endings recognized by g++
, see its documentation.
Therefore g++
assumes that you want the file to be passed to the linker directly. But since you used the -c
flag, which indicates that you want g++
to only compile, but not invoke the linker, you get that error message.
The solution is to tell g++
what kind of file it is that you are passing it explicitly:
g++ -c -o ./tree.o -x c++ ./tree.tpp -I ./tree.h
or, better, rename your C++ source file use one of the common file endings for C++ source files, e.g. .cpp
, .cc
, .cxx
, etc. That would result in less trouble with build tools and less confusion for others looking at your project.
As noted in the question comments -I ./tree.h
also is clearly wrong, but not the cause of this particular error (and probably it just doesn't belong there at all).
However:
If your .tpp
contains the implementation of methods of a class template, then you should not rename it (.tpp
is appropriate in that case), but you also should not compile it as translation unit at all. That means it should not appear in any g++
command.
.tpp
files implementing a template classes methods need to be included in the .h
file with the class template definition, instead. Otherwise you will get linker errors later when you try to link your files, see Why can templates only be implemented in the header file?.