如何寫shared library 或是static library

請問如何在QNX IDE中作shared Library或是static library
以下我的code,說我未定義,不知如何debug

follow is my code:
" shared.c " - It is my shared library

#include <stdio.h>
void fun1(void )
{
printf(“welcome to shared library\n” );

}

int fun2(int a , int b )
{
printf(“a+b=%d\n”,(a+b) );

return (a+b);
}

my main code:
#include <stdio.h>
int main( void )
{
int sum;

fun1();
sum=fun2(2,6);
printf(“sum=%d\n”,sum);

return EXIT_SUCCESS;
}

but there are some error when I build it.

*** [C:/QNX630/workex/get-local_time/x86/o/get-local_time] Error 1
*** [C:/QNX630/workex/get-local_time/x86/o-g/get-local_time_g] Error get-local_time.o * In function main': undefined reference to fun1’
get-local_time.o * undefined reference to fun1' undefined reference to fun2’
undefined reference to fun1' undefined reference to fun2’

shared library 和static library的最大差別是如何,可以解說一下嗎?

$gcc -fpic -c shared.c
$ gcc -shared -o libshared.so shared.o
$ gcc hello.c libshared.so
$ ./a.out

If I use the comm on the command line , the shared library is normal.
But I want to use QNX IDE to make and debug the shared library.
I don’t have idea. Help!
難道IDE沒有這個功能嗎?

你要开两个project。

shared.c一个,定义它为 shared library.
hello.c 另一个,定义它为 application.

在hello这个project的properties里,找到 “linker”,而后把category设成extra libraries。在下面追加 shared。这样每次Build Hello这个project时,它就会自动链接shared了。

另外,在定义Hello的执行(Run As…)时,也要在"download"里面追加 shared这个Project,这样在执行Hello时,IDE会同时自动加载libshared.so

It is normal!
thanx All !

Use the -l c option

code:

typedef int (*foofunc)( int );
funcptr temp;

/*Gain access to an executable object file */
/*shared library path → “/root/shared_lib/libsharecreat.so” */
handle = dlopen("/root/shared_lib/libsharecreat.so" ,RTLD_NOW );
if(handle == NULL)
{
printf(“link library open failed\n”);
exit(0);
}

/Get the address of a symbol in a shared object-function 1/
/* “TestFM” is function 1’s name*/
brain = (foofunc) dlsym( handle, “TestFM” );
if(brain == NULL)
{
printf(“link library open failed\n”);
exit(0);
}
printf(“temp is=%d\n”,(*brain)(10));