Skip to content
Snippets Groups Projects
Commit 1873980c authored by Nicolas Richart's avatar Nicolas Richart
Browse files

Adding C++ version

parent 0bb5babd
Branches
No related tags found
No related merge requests found
#include <iostream>
int main(void) {
std::printf("The square of 2.0 is %f\n", squared(2.0));
return 0;
}
#include "mymath.h"
#include <iostream>
int main(void) {
std::printf("The square of 2.0 is %f\n", squared(2.0));
return 0;
}
CC ?= gcc
CFLAGS += -fPIC
LDFLAGS += -shared
all: libmymath.so
libmymath.so: mymath.o
$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^
clean:
rm -f *.o libmymath.so
#include "mymath.h" #include "mymath.h"
double squared(double x) { double squared(double x) { return x * x; }
return x*x;
}
#ifndef MYMATH_H
#define MYMATH_H
// clang-format off
#if defined(__cplusplus)
extern "C"
#endif
double squared(double x);
#endif // MYMATH_H
CC=gcc
.PHONY: clean, distclean
library: libmymath.so clean
mymath.o: mymath.c
$(CC) -fPIC -c $<
libmymath.so: mymath.o
$(CC) -shared -o $@ $^
clean:
rm -f *.o
distclean: clean
rm -f *.so
#ifndef MYMATH_H_
#define MYMATH_H_
double squared(double x);
#endif // MYMATH_H_
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment