Skip to content
Snippets Groups Projects
Commit f11bac05 authored by sirko805's avatar sirko805
Browse files

cmake

parent ba4ab29c
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 <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()
{
int dest_fd, src_fd;
printf("lib called\n");
src_fd = open("a", O_RDONLY);
dest_fd = open("b", O_WRONLY); /* Needs to exist; not checking this */
#if 1
#if !(IS_HOST_WINDOWS)
printf("Using FICLONE\n");
if (ioctl(dest_fd, FICLONE, src_fd) < 0) {
fprintf(stderr, "error: %s\n", strerror(errno));
......
#include <stdio.h>
#include <dlfcn.h>
#include <math.h>
#include "MainProgramConfig.h"
int main(int argc, char **argv)
{
void (*cpfileLib)();
/* 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.
*/
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 */
{ /* 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);
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