Skip to content
Snippets Groups Projects
Commit e5311d4f authored by Sirathee Koomgreng's avatar Sirathee Koomgreng
Browse files

Merge branch 'sirko805' into 'main'

cmake

See merge request !1
parents cd986479 f11bac05
No related branches found
No related tags found
1 merge request!1cmake
cmake_minimum_required(VERSION 3.10)
# set the project name
project(MainProgram)
option(TRIG_FUNCTIONS "Use trig func" ON)
set(IS_HOST_WINDOWS,ON)
configure_file(MainProgramConfig.h.in MainProgramConfig.h)
add_library(copyfile SHARED copyfile.c)
if(${CMAKE_HOST_SYSTEM_NAME}!="Windows")
set(IS_HOST_WINDOWS,OFF)
endif()
# add the executable
add_executable(MainProgram main.cpp)
target_link_libraries(MainProgram ${CMAKE_DL_LIBS} copyfile)
target_include_directories(MainProgram PUBLIC
"${PROJECT_BINARY_DIR}"
)
\ No newline at end of file
#define CopyFile_VERSION_MAJOR @CopyFile_VERSION_MAJOR@
#define CopyFile_VERSION_MINOR @CopyFile_VERSION_MINOR@
#cmakedefine TRIG_FUNCTIONS
#cmakedefine IS_HOST_WINDOWS
\ No newline at end of file
amongus
\ No newline at end of file
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <dlfcn.h>
#include "MainProgramConfig.h"
#include <fcntl.h>
#if !(IS_HOST_WINDOWS)
#include <linux/fs.h>
#include <sys/ioctl.h>
#endif
#include <errno.h>
void copy_files() void copy_files()
{ {
int dest_fd, src_fd; int dest_fd, src_fd;
printf("lib called\n");
src_fd = open("a", O_RDONLY); src_fd = open("a", O_RDONLY);
dest_fd = open("b", O_WRONLY); /* Needs to exist; not checking this */ dest_fd = open("b", O_WRONLY); /* Needs to exist; not checking this */
#if 1 #if !(IS_HOST_WINDOWS)
printf("Using FICLONE\n"); printf("Using FICLONE\n");
if (ioctl(dest_fd, FICLONE, src_fd) < 0) { if (ioctl(dest_fd, FICLONE, src_fd) < 0) {
fprintf(stderr, "error: %s\n", strerror(errno)); fprintf(stderr, "error: %s\n", strerror(errno));
......
#include <stdio.h> #include <stdio.h>
#include <dlfcn.h>
#include <math.h>
#include "MainProgramConfig.h"
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
void (*cpfileLib)();
/* Note: dlopen does not exist on Windows and the filename will not be .so. /* Note: dlopen does not exist on Windows and the filename will not be .so.
* If you are performing the labs on Windows, you need to change this. * If you are performing the labs on Windows, you need to change this.
*/ */
void *ptr = dlopen("libcopyfile.so", RTLD_LAZY); void *ptr = dlopen("libcopyfile.so", RTLD_LAZY);
if (ptr != NULL) {
cpfileLib = (void(*)()) dlsym(ptr,"copy_files");
cpfileLib();
}
/* TODO: Call copy_files() from the opened shared object */ /* TODO: Call copy_files() from the opened shared object */
{ /* Disable this if --without-trig-functions or -DTRIG_FUNCTIONS:BOOL=OFF */ #ifdef TRIG_FUNCTIONS
/* Disable this if --without-trig-functions or -DTRIG_FUNCTIONS:BOOL=OFF */
double d = cos(1.5); double d = cos(1.5);
printf("The result of cos (a trigonometric function) is: %f\n", d); printf("The result of cos (a trigonometric function) is: %f\n", d);
} #endif
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment