#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;
}
没有合适的资源?快使用搜索试试~ 我知道了~
gyp工具_2016/12/24
共1668个文件
py:473个
gyp:424个
c:182个
需积分: 15 75 下载量 84 浏览量
2016-12-25
00:32:34
上传
评论
收藏 12.59MB ZIP 举报
温馨提示
2016年12月24日在https://chromium.googlesource.com/external/gyp/上用git clone下来的gyp工具,可用来在windows下生成breakpad工程文件
资源推荐
资源详情
资源评论
收起资源包目录
gyp工具_2016/12/24 (1668个子文件)
override_asm.asm 285B
safeseh_zero.asm 119B
a.asm 119B
safeseh_zero64.asm 103B
asm-function.assem 209B
AUTHORS 454B
dummy.bar 223B
foo.bar 206B
somecmd.bat 265B
as.bat 226B
gyp.bat 201B
samples.bat 196B
go.bat 189B
bat with spaces.bat 189B
as.bat 63B
stuff.blah 19B
program.c 3KB
check-version-min.c 1KB
check-version-min.c 1KB
main.c 708B
file.c 680B
includes.c 553B
program.c 519B
staticlib.c 475B
defines.c 467B
GypKext.c 463B
calculate.c 459B
prog3.c 430B
prog2.c 430B
prog1.c 430B
test.c 420B
foo.c 419B
prog3.c 398B
b.c 393B
sharedlib.c 383B
program.c 380B
hello.c 376B
main.c 371B
win-driver-target-type.c 355B
configurations.c 355B
program.c 344B
hello2.c 326B
hello.c 319B
hello.c 319B
cflags.c 311B
subdir_includes.c 311B
test.c 305B
program.c 294B
prog2.c 291B
prog1.c 291B
hello.c 290B
mymalloc.c 288B
precomp.c 285B
main.c 276B
main-crt.c 269B
valid_c.c 266B
program.c 263B
prog.c 260B
hello.c 260B
there.c 259B
hello.c 259B
defines-escaping.c 259B
module.c 255B
hello.c 255B
hello.c 254B
hello.c 254B
hello.c 254B
hello2.c 252B
hello2.c 249B
warn_about_missing_newline.c 249B
input_dirname.c 243B
configurations.c 238B
c.c 238B
test.input_root.c 237B
test.c 237B
test.c 237B
foo.c 236B
input_ext.c 235B
configurations.c 231B
a.c 227B
program.c 226B
c.c 222B
b.c 222B
d.c 222B
hello.c 219B
a.c 219B
a.c 217B
file.c 216B
mylib.c 205B
mylib.c 205B
b3.c 204B
main.c 194B
main.c 194B
main.c 194B
main.c 194B
main.c 194B
file.c 192B
file.c 192B
program.c 188B
lib1.c 181B
共 1668 条
- 1
- 2
- 3
- 4
- 5
- 6
- 17
资源评论
一名啥都不会的见习工程师
- 粉丝: 34
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功