#include <stdio.h>
#include <stdlib.h>
#if defined(PLATFORM_WIN)
#include <windows.h>
#elif defined(PLATFORM_MAC) || defined(PLATFORM_LINUX)
#include <dlfcn.h>
#include <libgen.h>
#include <string.h>
#include <sys/param.h>
#define MAX_PATH PATH_MAX
#endif
#if defined(PLATFORM_WIN)
#define MODULE_SUFFIX ".dll"
#elif defined(PLATFORM_MAC)
#define MODULE_SUFFIX ".so"
#elif defined(PLATFORM_LINUX)
#define MODULE_SUFFIX ".so"
#endif
typedef void (*module_symbol)(void);
char bin_path[MAX_PATH + 1];
void CallModule(const char* module) {
char module_path[MAX_PATH + 1];
const char* module_function = "module_main";
module_symbol funcptr;
#if defined(PLATFORM_WIN)
HMODULE dl;
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
if (_splitpath_s(bin_path, drive, _MAX_DRIVE, dir, _MAX_DIR,
NULL, 0, NULL, 0)) {
fprintf(stderr, "Failed to split executable path.\n");
return;
}
if (_makepath_s(module_path, MAX_PATH, drive, dir, module, MODULE_SUFFIX)) {
fprintf(stderr, "Failed to calculate module path.\n");
return;
}
dl = LoadLibrary(module_path);
if (!dl) {
fprintf(stderr, "Failed to open module: %s\n", module_path);
return;
}
funcptr = (module_symbol) GetProcAddress(dl, module_function);
if (!funcptr) {
fprintf(stderr, "Failed to find symbol: %s\n", module_function);
return;
}
funcptr();
FreeLibrary(dl);
#elif defined(PLATFORM_MAC) || defined(PLATFORM_LINUX)
void* dl;
char* path_copy = strdup(bin_path);
char* bin_dir = dirname(path_copy);
int path_size = snprintf(module_path, MAX_PATH, "%s/%s%s", bin_dir, module,
MODULE_SUFFIX);
free(path_copy);
if (path_size < 0 || path_size > MAX_PATH) {
fprintf(stderr, "Failed to calculate module path.\n");
return;
}
module_path[path_size] = 0;
dl = dlopen(module_path, RTLD_LAZY);
if (!dl) {
fprintf(stderr, "Failed to open module: %s\n", module_path);
return;
}
funcptr = dlsym(dl, module_function);
if (!funcptr) {
fprintf(stderr, "Failed to find symbol: %s\n", module_function);
return;
}
funcptr();
dlclose(dl);
#endif
}
int main(int argc, char *argv[])
{
fprintf(stdout, "Hello from program.c\n");
fflush(stdout);
#if defined(PLATFORM_WIN)
if (!GetModuleFileName(NULL, bin_path, MAX_PATH)) {
fprintf(stderr, "Failed to determine executable path.\n");
return 1;
}
#elif defined(PLATFORM_MAC) || defined(PLATFORM_LINUX)
// Using argv[0] should be OK here since we control how the tests run, and
// can avoid exec and such issues that make it unreliable.
if (!realpath(argv[0], bin_path)) {
fprintf(stderr, "Failed to determine executable path (%s).\n", argv[0]);
return 1;
}
#endif
CallModule("lib1");
CallModule("lib2");
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
最新Google V8 GYP 包
共2343个文件
svn-base:1107个
py:365个
gyp:318个
5星 · 超过95%的资源 需积分: 9 635 下载量 156 浏览量
2014-09-14
21:17:42
上传
评论 5
收藏 677KB 7Z 举报
温馨提示
最新GYP包,因为V8 引擎更新了 ,所以需要最新的GYP包。实用有问题,请联系我。
资源推荐
资源详情
资源评论
收起资源包目录
最新Google V8 GYP 包 (2343个子文件)
override_asm.asm 277B
asm-function.assem 199B
AUTHORS 190B
somecmd.bat 265B
as.bat 226B
samples.bat 196B
gyp.bat 194B
go.bat 182B
bat with spaces.bat 182B
as.bat 55B
stuff.blah 18B
program.c 3KB
check-version-min.c 1KB
check-version-min.c 1KB
main.c 683B
file.c 658B
includes.c 552B
program.c 519B
staticlib.c 475B
defines.c 462B
calculate.c 444B
prog2.c 430B
prog3.c 430B
prog1.c 430B
writefile.c 402B
test.c 402B
prog3.c 398B
sharedlib.c 383B
hello.c 380B
program.c 379B
b.c 375B
main.c 349B
cflags.c 349B
program.c 344B
configurations.c 334B
hello.c 322B
hello.c 322B
subdir_includes.c 315B
hello2.c 313B
test.c 298B
program.c 297B
hello.c 295B
prog1.c 293B
prog2.c 293B
32or64.c 291B
precomp.c 277B
defines-escaping.c 266B
there.c 265B
hello.c 265B
hello.c 265B
main.c 262B
hello.c 261B
hello.c 261B
hello.c 260B
hello2.c 259B
valid_c.c 258B
module.c 244B
warn_about_missing_newline.c 242B
hello.c 240B
hello2.c 239B
input_dirname.c 234B
program.c 232B
c.c 228B
test.c 228B
test.input_root.c 228B
test.c 228B
input_ext.c 226B
configurations.c 226B
foo.c 225B
a.c 218B
configurations.c 216B
b.c 213B
d.c 213B
hello.c 212B
c.c 212B
file.c 210B
a.c 209B
a.c 208B
mylib.c 198B
b3.c 195B
program.c 194B
program.c 190B
program.c 190B
main.c 187B
main.c 187B
main.c 187B
main.c 187B
file.c 186B
file.c 186B
main.c 175B
main.c 173B
main.c 173B
file_g.c 171B
file_h.c 171B
file.c 171B
empty.c 171B
lib1_moveable.c 165B
lib2_moveable.c 165B
prog5.c 154B
lib1.c 152B
共 2343 条
- 1
- 2
- 3
- 4
- 5
- 6
- 24
志汉天涯
- 粉丝: 27
- 资源: 23
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 安卓课程设计python实现人脸识别考勤源码(95分以上).zip
- 基于Opencv测量油滴尺寸python源码(高分课设).zip
- Vue从0搭建后台管理系统框架
- 基于puma560机械臂RRT路径规划matlab仿真源码(高分课设).zip
- 管道焊缝质量检测数据集VOC+YOLO格式1134张2类别.7z
- 西北工业大学-智慧树大学生心理健康章节测试答案.doc
- 基于python实现的小说推荐系统源码+超详细注释(高分期末大作业).zip
- 西北工业大学-核心听力雨课堂答案.docx
- 西北工业大学-计算机网络SPOC测验答案.docx
- 基于亚博K210的人脸识别项目源码(高分期末大作业).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页