diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 17:43:19 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 17:43:19 +0000 |
commit | 0292059f4a16434600564cfa3f0ad2309a508a54 (patch) | |
tree | d95953cd53011917c4df679b96aedca39401b54f /doc/html/ksquirrel-libs-olibs1.html | |
download | libksquirrel-0292059f4a16434600564cfa3f0ad2309a508a54.tar.gz libksquirrel-0292059f4a16434600564cfa3f0ad2309a508a54.zip |
Added libksquirrel for KDE3
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/libraries/libksquirrel@1095624 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'doc/html/ksquirrel-libs-olibs1.html')
-rw-r--r-- | doc/html/ksquirrel-libs-olibs1.html | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/doc/html/ksquirrel-libs-olibs1.html b/doc/html/ksquirrel-libs-olibs1.html new file mode 100644 index 0000000..1965e7d --- /dev/null +++ b/doc/html/ksquirrel-libs-olibs1.html @@ -0,0 +1,129 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> +<html> +<head> + <title>KSquirrel: development</title> + + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name='Author' content='Baryshev Dmitry/Krasu'> + + <link rel="stylesheet" href="styles.css" type="text/css"> +</head> +<body> + +<ul> +<li>First, write regular C program (without main()): +<br><br> +<table cellpadding="2" cellspacing="2" width="70%" align="center"> + <tbody> + <tr> + <td valign="top" bgcolor="#CCCCCC"> + + <pre> + const char* fmt_info() + { + return "It is really cool format!"; + } + </pre> + </td> + </tr> + </tbody> +</table> +<br><br> +<li>Compile it +<br><br> +<table cellpadding="2" cellspacing="2" width="70%" align="center"> + <tbody> + <tr> + <td valign="top" bgcolor="#CCCCCC"> + + <pre> + # gcc -O2 -fPIC -c module.c + # gcc -shared -o module.so module.o + </pre> + </td> + </tr> + </tbody> +</table> +<br><br> +<li>Let's write a simple test +<br><br> +<table cellpadding="2" cellspacing="2" width="70%" align="center"> + <tbody> + <tr> + <td valign="top" bgcolor="#CCCCCC"> + + <pre> + #include <unistd.h> + #include <string.h> + #include <errno.h> + #include <dlfcn.h> + + #define PATH_LENGTH 256 + + int main(int argc, char * argv[]) + { + char path[PATH_LENGTH], *msg = NULL; + const char* (*fmt)(); + void *module; + + getcwd(path, PATH_LENGTH); + strcat(path, "/"); + strcat(path, "module.so"); + + /* Load module */ + module = dlopen(path, RTLD_NOW); + + /* Error ! */ + if(!module) + { + msg = dlerror(); + + if(msg != NULL) + { + dlclose(module); + exit(1); + } + } + + /* Try to resolve function "fmt_info()" */ + fmt = dlsym(module, "fmt_info"); + + msg = dlerror(); + + if(msg != NULL) + { + perror(msg); + dlclose(module); + exit(1); + } + + /* call fmt_info() through a pointer*/ + printf("%s\n", fmt()); + + /* close module */ + if(dlclose(module)) + { + perror("error"); + exit(1); + } + + return 0; + } + + # gcc -o test main.c -ldl + # ./test + It is really cool format! + # + + </pre> + </td> + </tr> + </tbody> +</table> +<br><br> +<li>That's all! :) Our test program has just loaded <u>module.so</u> and called <u>fmt_info()</u>, located in it. It is very simple, isn't ? +<br><br> +</ul> + +</body> +</html> |