#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
void create_dynamic_library()
{
FILE *file = fopen("libhello.c", "w");
fprintf(file, "#include <stdio.h>\n");
fprintf(file, "void hello() {\n");
fprintf(file, " printf(\"Hello from the library!\\n\");}\n");
fclose(file);
system("gcc -shared -fPIC -o libhello.so libhello.c");
}
void run_all_files()
{
system("gcc -o test_dynamic_library test_dynamic_library.c");
system("./test_dynamic_library");
}
int main()
{
create_dynamic_library();
FILE *file = fopen("test_dynamic_library.c", "w");
fprintf(file, "#include <stdio.h>\n");
fprintf(file, "#include <dlfcn.h>\n");
fprintf(file, "int (*module_pr)(void);\n");
fprintf(file, "int main(void){\n");
fprintf(file, " void *h;\n");
fprintf(file, " h = dlopen(\"./libmodule.so \", RTLD_NOW|RTLD_GLOBAL);\n");
fprintf(file, " module_pr = dlsym(h, \"m_pr\");\n");
fprintf(file, " module_pr();\n");
fprintf(file, " dlclose(h);\n");
fprintf(file, " dlerror();\n");
fprintf(file, " return 0;\n");
fprintf(file, "}\n");
fclose(file);
run_all_files();
return 0;
}
最后修改:2024 年 07 月 07 日
© 允许规范转载
4 条评论
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# systemd generates mount units based on this file, see systemd.mount(5).
# Please run 'systemctl daemon-reload' after making changes here.
#
#
# / was on /dev/sda1 during installation
UUID=3150d687-0e2e-46dc-b265-b82c3f9d6cfd / ext4 user_xattr,errors=remount-ro 0 1
# swap was on /dev/sda5 during installation
UUID=285c345d-e884-4f97-a3fd-b5cc3ca9b357 none swap sw 0 0
/dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# systemd generates mount units based on this file, see systemd.mount(5).
# Please run 'systemctl daemon-reload' after making changes here.
#
#
# / was on /dev/sda1 during installation
/dev/sda1 / ext4 user_xattr,errors=remount-ro 0 1
# swap was on /dev/sda5 during installation
UUID=285c345d-e884-4f97-a3fd-b5cc3ca9b357 none swap sw 0 0
/dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0
UUID=3150d687-0e2e-46dc-b265-b82c3f9d6cfd
function! ModifyXattr()
" 这里执行修改文件扩展属性的操作
" 假设你使用的是Linux系统并通过setfattr命令来设置xattr
silent !setfattr -n user.modified -v "true" %
endfunction
augroup FileChangeXattr
autocmd!
" 自动加载bufreadpre和bufwritepost事件,以便在缓冲区写入前后进行操作
autocmd BufWritePre * let b:modified = &modified
autocmd BufWritePost * if b:modified && &modified == 0 | call ModifyXattr() | endif
augroup END