You are not logged in.

1

Sunday, November 26th 2006, 1:46am

link against a .so library

i create a C++ project. there is a .cpp file uses some functions of a shared library, libbktrans.so.

i put the shared library ,libbktrans.so.0.0, and the library's .h file, BkTransLib.h, in /usr/local/lib.

to build this project, i need to link against the shared library.As the direction at http://www.kdevelop.org/mediawiki/index.…_.so_library.3F .But i got a problem:
i can't do this: "on the libraries ("compiler") tab add libs in the second box (link libraries outside of project). Just enter the lib name, without the lib prefix and the .a or .so or .la or what ever ending" because i couldn't find the text "link library outside of project" in the tab compiler.

i couldn't link the shared library so when i build, there are errors: "undefined reference to" function of the shared library.
i'm using Kdevelop 3.3.1(Using KDE 3.5.1-2.3 Red Hat).
is there anyone show me how to handle this ?

Thanks and regard

2

Sunday, November 26th 2006, 6:43am

RE: link against a .so library

hi !
i'm using Kdevelop 3.3.1(Using KDE 3.5.1-2.3 Red Hat).
i have 2 files demo.c and BkTransLib.h, 1 shared library libbktrans.so.0.0

// demo.c
#include "BkTransLib.h"
int main() {

if (BKInit()) printf("Start BkTransLib ok\n");
else {
printf("Start BkTransLib Fail\n");
return 0;
}
}

//"BkTransLib.h"
int BKInit();

and libbktrans.so.0.0 is a shared library contains function BKInit()

i put libbktrans.so.0.0 in /usr/local/lib, make two links here
ln -sf libbktrans.so.0.0 libbktrans.so.0
ln -sf libbktrans.so.0 libbktrans.so
now i create a C project with Automake Manager, add the two files into it and build the project. Of course, i get an error: "undefined reference to BKInit()".it's because i haven't not added my shared library into the project.
To fix this, i open Automake Manager and select the project line, right-click and select Options from the drop menu. Choose the Library tab, in the second box("Link library outside project(LDADD)"), add -lbktrans.

rebuild the project -->Success
execute program, i get
Start BkTransLib ok
Press Enter to continue!
well, perfect !

Now i modify demo.c to create demo.cpp
//demo.cpp
#include "BkTransLib.h"
#include <qwhatsthis.h>

int main() {

if (BKInit()) qWarning( "Start BkTransLib ok\n" );
else {
qWarning("Start BkTransLib Fail\n");
return 0;
}
}
then i create a C++ project (C++ --> KDE --> Simple KDE Application), add demo.cpp and BkTransLib.h into it. Once again i get the error "undefined reference...". so i do the same as the C project. unluckily, the error does not disappear.

i don't know why, i even follow the direction of FAQ at http://www.kdevelop.org/mediawiki/index.…_.so_library.3F
1. add -lbktrans in "link libraries outside of project" like above
2. add -L/usr/local/lib to the LDFLAGS in Project->Project Options...->Configure Options->Linker Flags(LDFLAGS)
3. add -I/usr/local/lib to the "Directories outside of project" in the tab Include
rebuild but nothing changes.

Please tell me what.

Thank you.

3

Monday, November 27th 2006, 5:50pm

RE: link against a .so library

hi !
perhaps, the shared library can't link into a C++ project.(this is my very stupid idea !)
because i was successful to link against a simple shared library(at http://tldp.org/HOWTO/Program-Library-HO…e-examples.html) to both C and C++ project.
does anyone have a better idea ?
Regards
nhatkhang

4

Tuesday, November 28th 2006, 4:01am

hi
i got the solution
for the C++ project, i need to edit the .h file (BkTransLib.h).
i added extern "C" {all the functions}; into it,
thanks you all