Return To CS 110 Home

Colour Theme   Font Size Options
 
   
   
   
Compiling Multiple Files

Putting Multiple Files Into a Repl


Video Summary: https://youtu.be/CcY_pvf5SVc


Compile your C++ program on Replit

Let's add hello.cpp from Lab 1 to your Lab 2 Repl. You can click on this link hello.cpp to get the code.

When you press the Run ► button, it tries to compile all the C++ files in your Repl into one program, but sampleio.cpp and hello.cpp are are both complete programs and can't be stuck together.

You will see something like this if you try:

> make -s
/nix/store/v8imx1nvyz0hgvx9cbcmh6gp4ngw3ffj-binutils-2.35.1/bin/ld:
./sampleio.o: in function `main':
/home/runner/Lab2/sampleio.cpp:15: multiple definition of `main';
./hello.o:
/home/runner/Lab2/hello.cpp:15: first defined here
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:8: main] Error 1
exit status 2

I added some line breaks and emphasis to make the problem clearer: multiple definition of `main' - there's one in each program file. You'll have to compile them separately. Important: In labs 2 to 10 you will put all your .cpp for multiple exercises into one repl - the Run button won't like this. You will have to compile and run separately. The next section will remind you how to do that.