forked from nothingelsematters/libs-acquaintance
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
49 lines (43 loc) · 1.53 KB
/
Copy pathmain.cpp
File metadata and controls
49 lines (43 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <string>
#include <dlfcn.h>
#include "combination.h"
#include "printer.h"
const char LOADED_LIB_NAME [] = "./libfibonacci.so";
void printErrorMessage(std::string const& message) {
std::cerr << message <<": " << dlerror() << std::endl;
}
int main() {
int number = 0;
unsigned long long mask = 0;
int numberNth = 0;
std::cout << "Type in integer number" << std::endl;
std::cin >> number;
printInt(number);
std::cout << "Type in unsigned long long (combination bit mask)" << std::endl;
std::cin >> mask;
unsigned long long nextMask = nextCombinationMask(mask);
std::cout << "Next combination mask = " << nextMask << std::endl;
std::cout << "Type in Fibonacci number you want to calculate" << std::endl;
std::cin >> numberNth;
void* loadedLibrary = dlopen(LOADED_LIB_NAME, RTLD_LAZY);
if (loadedLibrary == nullptr) {
printErrorMessage("Failed to load library");
exit(EXIT_FAILURE);
}
auto fibNumberFunction = (int (*)(int)) dlsym(loadedLibrary, "calculateNthFibonacci");
if (fibNumberFunction == nullptr) {
printErrorMessage("Failed lo load symbol");
if (dlclose(loadedLibrary) != 0) {
printErrorMessage("Failed to close library");
}
exit(EXIT_FAILURE);
}
int fibNumber = fibNumberFunction(numberNth);
std::cout << fibNumber << std::endl;
if (dlclose(loadedLibrary) != 0) {
printErrorMessage("Failed to close library");
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}