I have one C program which contains a function call.
I have been given some .so and .h files.
I want to know how to compile and link the c program with .so files.
I tried following:
$ gcc My_program.c libCommon.so
My_program.c: In function �main�:
My_program.c:11: warning: parameter names (without types) in function declaration
/usr/bin/ld:libCommon.so: file format not recognized; treating as linker script
/usr/bin/ld:libCommon.so:1: syntax error
collect2: ld returned 1 exit status
$
Thanks in advance
Well, that's not normally the way you'd link-in a shared library (you'd normally use "-L. -lCommon" instead of just "libCommon.so") but there's no reason it shouldn't work.
Could you post the output of the following commands:
here is the output:
$ gcc -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.1 20061011 (Red Hat 4.1.1-30)
$ file libCommon.so
libCommon.so: ASCII text, with no line terminators
I found that .so file is ascii its contents are:
$ cat libCommon.so
libCommon.so.1.0.0
now i tried following:
$ gcc My_program.c libCommon.so.1.0.0
My_program.c: In function �main�:
My_program.c:13: warning: parameter names (without types) in function declaration
libCommon.so.1.0.0: undefined reference to `dlsym'
libCommon.so.1.0.0: undefined reference to `dlopen'
libCommon.so.1.0.0: undefined reference to `dlclose'
collect2: ld returned 1 exit status
$ gcc My_program.c -llibCommon.so.1.0.0
My_program.c: In function �main�:
My_program.c:13: warning: parameter names (without types) in function declaration
/usr/bin/ld: cannot find -llibCommon.so.1.0.0
collect2: ld returned 1 exit status
$ gcc My_program.c -l libCommon.so.1.0.0
My_program.c: In function �main�:
My_program.c:13: warning: parameter names (without types) in function declaration
/usr/bin/ld: cannot find -llibCommon.so.1.0.0
collect2: ld returned 1 exit status
$ gcc My_program.c -lCommon.so.1.0.0
My_program.c: In function �main�:
My_program.c:13: warning: parameter names (without types) in function declaration
/usr/bin/ld: cannot find -lCommon.so.1.0.0
collect2: ld returned 1 exit status
Thanks in advance
Try:
gcc My_program.c libCommon.so.1.0.0 -ldl
(the -ldl links in libdl.so, which is what you want for dlopen() etc.)