create project HelloShared.
File->New->C Project
project name:HelloShared
Project type:Shared Library->Empty Project
Toolcains:Linux GCC
create HelloShared.h:
/* * HelloShared.h */ #ifndef HELLOSHARED_H_ #define HELLOSHARED_H_ void helloShared(const char *name); #endif /* HELLOSHARED_H_ */
create HelloShared.c:
/*
* HelloShared.c
*/
#include <stdio.h>
void helloShared(const char *name) {
printf("helloShared %s!\n", name);
}
Build Project HelloShared.
create project HelloApp:
File->New->C Project
project name:HelloApp
Project type:Executable->Empty Project
Toolcains:Linux GCC
Properties for HelloApp:
C/C++ General-->Paths and Symbols:
Includes:/HelloShared
Libraries:HelloShared
LibraryPaths:/HelloShared/Debug
References:HelloShared
create main.c:
#include "HelloShared.h"
#include <stdio.h>
int main() {
helloShared("cj");
return 0;
}
Build Project HelloApp.
debug configurations-->Environment
LD_LIBRARY_PATH = ${workspace_loc:/HelloShared/Debug}
run main.c
helloShared cj!

本文介绍如何使用C语言创建共享库并将其应用于独立程序中。通过具体步骤演示了共享库项目的创建过程,包括编写头文件和源代码文件,并展示了如何在另一个项目中引用该共享库来调用其功能。

被折叠的 条评论
为什么被折叠?



