diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile | 12 | ||||
-rw-r--r-- | helloworld.cpp | 12 | ||||
-rw-r--r-- | main.cpp | 8 | ||||
-rw-r--r-- | math.cpp | 17 | ||||
-rw-r--r-- | math.h | 6 |
6 files changed, 41 insertions, 16 deletions
@@ -1,2 +1,4 @@ */*.o +*.o helloworld +mine @@ -1,3 +1,5 @@ +# references: +# BUILD_DIR and per-.cpp file https://spin.atomicobject.com/2016/08/26/makefile-c-projects/ awkbin :=$(shell which awk) cpbin :=$(shell which cp) echobin :=$(shell which echo) @@ -20,13 +22,15 @@ LDFLAGS = -g src = $(wildcard *.cpp) obj = $(src:.cpp=.o) -OUTEXE = helloworld +BUILD_DIR ?= . + +OUTEXE = mine all: $(OUTEXE) -# compile -$(obj): $(src) - $(CXX) -c $(CXXFLAGS) $< +# compile, which is not actually used? +$(BUILD_DIR)%.o: %.cpp + $(CXX) -c $(CXXFLAGS) $+ # link $(OUTEXE): $(obj) diff --git a/helloworld.cpp b/helloworld.cpp deleted file mode 100644 index 8474a1e..0000000 --- a/helloworld.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include <iostream> - -int return5() -{ - return 5 ; -} - -int main() { - //int x { }, y { } ; - std::cout << return5() << '\n' ; - return 0 ; -} diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..735cd75 --- /dev/null +++ b/main.cpp @@ -0,0 +1,8 @@ +#include <iostream> +#include "math.h" + +int main() +{ + std::cout << doubleNumber(getNumberFromUser()) << '\n' ; + return 0 ; +} diff --git a/math.cpp b/math.cpp new file mode 100644 index 0000000..5aeebfd --- /dev/null +++ b/math.cpp @@ -0,0 +1,17 @@ +#include <iostream> +#include "math.h" + +int getNumberFromUser() +{ + std::cout << "Enter an integer: " ; + int x ; + std::cin >> x ; + return x ; +} + +int doubleNumber(int x) +{ + //int z { 3 } ; + //z = z * 2 ; + return x * 2 ; +} @@ -0,0 +1,6 @@ +#ifndef MATH9385 +#define MATH9385 +int getNumberFromUser() ; +int doubleNumber(int x) ; + +#endif |