Results 1 to 10 of 10

Thread: shared library problem

  1. #1
    Join Date
    Nov 2006
    Posts
    12
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Angry shared library problem

    I put my shared library,libbktrans.so.0.0, in /usr/local/lib. Here, I make two links:
    ln -sf libbktrans.so.0.0 libbktrans.so.0
    ln -sf libbktrans.so.0 libbktrans.so
    Then declare preloading this library:
    export LD_PRELOAD=/usr/local/lib/libbktrans.so.0

    i have demo.c to test. So it contains functions declared in shared lib.
    //demo.c
    #include BkTransLib.h//interfaces of functions in shared lib.
    .......

    I compile demo.c:
    gcc -Wall -g -c demo.c -o demo.o
    Create program demo:
    gcc -g -o demo demo.o -L. -lbktrans
    Execute the program
    LD_LIBRARY_PATH="." ./demo

    result---> perfect.

    Now i create a C project by KDevelop with Automake. I add demo.c and BkTransLib.h into my project. But I can not build this project. because of errors. those errors are "undefined reference" to the functions in shared lib.

    I know i missed something in telling the project to link my shared lib. But i don't know how.
    Please tell me what.
    Thank you so much.

  2. #2
    Join Date
    Nov 2006
    Posts
    12
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Wink Re: shared library problem

    hi !
    i got the sulution.
    To the C project, i add my library in Automake Manager:
    -->right click on "Program in bin" --> Options --> Libraries tab --> -lbktrans. and now the project can link to the shared library.

    but to execute the application, i must specify the path to the shared library:
    -->Project --> Options --> Run Option --> add "LD_LIBRARY_PATH" with the value /usr/local/lib

    To the C++ project, the solution can find in the FAQ at http://www.kdevelop.org/mediawiki/in...#Libraries_FAQ

    Thank you.

  3. #3
    Join Date
    Nov 2006
    Posts
    12
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Question Re: shared library problem

    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/in....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

  4. #4
    Join Date
    Nov 2006
    Posts
    12
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Arrow Re: shared library problem

    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/in....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.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: shared library problem

    Quote Originally Posted by nhatkhang View Post
    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
    Try adding "-L/usr/local/lib -lbktrans" to "link libraries outside of project", make sure that /usr/local/lib is in /etc/ld.so.conf and rerun ldconfig.

  6. #6
    Join Date
    Nov 2006
    Posts
    12
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: shared library problem

    hi
    i tried, but nothing changed

    perhaps, the shared library libbktrans.so can't link into a C++ project.(this is my very stupid idea !)
    because i was successful to link against a simple shared library to both C and C++ project.
    does anyone have a better idea ?
    Regards
    nhatkhang

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: shared library problem

    Quote Originally Posted by nhatkhang View Post
    because i was successful to link against a simple shared library to both C and C++ project.
    But was it libbktrans.so or some other library? Maybe you forgot to add extern "C"?

  8. #8
    Join Date
    Nov 2006
    Posts
    12
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: shared library problem

    hi
    i only built successfully with libbktrans.so on C project, but not C++ project

    i followed the directions and example at http://tldp.org/HOWTO/Program-Librar...-examples.html to make a simple shared library, and i could handle both C and C++ project.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: shared library problem

    Quote Originally Posted by nhatkhang View Post
    i followed the directions and example at http://tldp.org/HOWTO/Program-Librar...-examples.html to make a simple shared library,
    I hope you didn't forgot about section 5.8. from that howto.

  10. #10
    Join Date
    Nov 2006
    Posts
    12
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: shared library problem

    hi !
    i got the solution. you're the number one
    thank you

    nhatkhang

Similar Threads

  1. Interesting little Segfault w/r to signal/slot connection
    By Hydragyrum in forum Qt Programming
    Replies: 24
    Last Post: 12th September 2006, 20:22
  2. Shared lib template broken under linux ???
    By fullmetalcoder in forum Qt Programming
    Replies: 9
    Last Post: 26th April 2006, 21:05
  3. I got two problems when I used static compiled library of QT4
    By qintm in forum Installation and Deployment
    Replies: 8
    Last Post: 20th April 2006, 09:52
  4. id3lib library problem
    By acix in forum General Programming
    Replies: 2
    Last Post: 11th April 2006, 13:46
  5. Replies: 16
    Last Post: 7th March 2006, 16:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.