[Cs3] Templated Function Definitions

Mikhail Nesterenko mikhail at cs.kent.edu
Mon Mar 21 10:32:50 EDT 2022


> Here are the 2 files. So if I put any of the function definitions for the
> classes in another cpp file, I get an error. It's not a big deal or
> anything, but I was just wondering why this was occurring.
> 

By default, once done, the g++ or clang compiler invokes a linker that
tries to link the project and produce an executable. If your function
definitions are in two source files, as they well should be, you need to
invoke the compiler twice - on each source file:

prompt% g++ -c diceImplementation.cpp // compiling the first source file
prompt% g++ -c diceMain.cpp // compiling the second source file
prompt% g++ -o dice diceImplementation.o diceMain.o // linking the two
                                            // resultant object files
prompt% ./dice  // running the produced executable 


Thanks,
--
Mikhail


More information about the cs3 mailing list