Last active
September 3, 2018 00:39
-
-
Save etcadinfinitum/51ce1f97c529f5ff8011be8999cd950c to your computer and use it in GitHub Desktop.
Notes for myself (in advance of UW Bothell BootUp sessions)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Say you have 2 files: | |
hello.cpp --> has main() | |
fib.cpp --> has no main() | |
You also have a header file for fib.cpp | |
fib.h --> contains method signature for fib.cpp | |
All files are in the same directory | |
*/ | |
// fib.cpp must (?) have a header file declaring the method signature. | |
// hello.cpp must have an include statement: | |
#include <fib.h> | |
// to compile, do these in order: | |
// 1. Compile fib.cpp | |
g++ -c fib.cpp | |
output: fib.o (an object file, which is the compiled binary copy of fib.cpp) | |
// 2. compile hello.cpp | |
g++ -c hello.cpp -I . | |
// 3. package all compiled files into an executable | |
g++ -o my_program_name hello.o fib.o | |
// 4. run my_program_name | |
./my_program_name | |
// chain these calls in linux using && for a one-line step | |
g++ -c fib.cpp && g++ -c hello.cpp -I . && g++ -o hey hello.o fib.o && ./hey | |
Options used: | |
-c: compile and assemble, but do not link | |
-o: place output into named file (in this example, -o hey places executable copy of .o files into an executable named "hey") | |
-I: search the named directory for header files; searches named directory/ies before searching system standard directories |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment