forked from ChicoState/CppMath
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic c++ code to run within cpp-container
- Loading branch information
Showing
3 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
FROM ubuntu:noble | ||
LABEL title="CPP Container" | ||
LABEL version=1.0 | ||
ENV GTEST_REPO=/googletest | ||
ENV GTEST_DIR=${GTEST_REPO}/googletest | ||
ENV WORKDIR=/usr/src | ||
WORKDIR /usr/src | ||
|
||
# Set Docker arguments | ||
ARG DEBIAN_FRONTEND=noninteractive | ||
|
||
# Install dependencies | ||
RUN apt-get update && \ | ||
apt-get install -y \ | ||
build-essential \ | ||
g++ \ | ||
cmake \ | ||
git-all \ | ||
dos2unix | ||
RUN apt-get clean | ||
|
||
# Setup GoogleTest | ||
RUN git clone --depth=1 https://github.com/google/googletest ${GTEST_REPO} | ||
RUN mkdir ${GTEST_REPO}/build && cd ${GTEST_REPO}/build \ | ||
&& cmake .. -DBUILD_GMOCK=OFF && make && cd ${WORKDIR} | ||
|
||
# Copy repo source into container | ||
COPY . ${WORKDIR} | ||
|
||
# Assure Unix linefeed for all files | ||
RUN find . -type f -print0 | xargs -0 dos2unix -- | ||
|
||
# Build project | ||
CMD sh -c ${WORKDIR}/test_runner.sh |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,26 @@ | ||
# CppMath | ||
# CppMath | ||
|
||
|
||
## Building in docker container | ||
|
||
If you have not already built the Docker container, use the following: | ||
|
||
``` | ||
docker build -t cpp-container . | ||
``` | ||
|
||
Once you have a built Docker container, run it interactively: | ||
|
||
``` | ||
docker run -v "$(pwd)":/usr/src -it cpp-container sh | ||
``` | ||
|
||
Then -- inside of the container -- compile the program: | ||
|
||
``` | ||
g++ main.cpp | ||
``` | ||
|
||
and if it compiles successfully, run it with `./a.out` | ||
|
||
To exit the container, type `exit` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <iostream> | ||
|
||
int main(){ | ||
double first, second; | ||
|
||
std::cout<< "First number: "; | ||
std::cin>> first; | ||
std::cout<< "Second number: "; | ||
std::cin>> second; | ||
|
||
std::cout<< "Addition: "<< first << "+" << second << "="; | ||
std::cout<< (first+second) << std::endl; | ||
std::cout<< "Subtraction: "<< first << "-" << second << "="; | ||
std::cout<< (first-second) << std::endl; | ||
|
||
return 0; | ||
} |