Linux: c++ include librarys in /usr/local/lib



  • Hi,

    i want to use an icq library to make a small program to control the pc with messages using icq. So i need to use icq librarys. I found very good ones, but i dont want to use the source files directly with my project. I compiled the librarys and installed them to /usr/local/lib. Here i have the following files :

    libicq.a libicq.la libicq.so libicq.so.1 libicq.so.1.0.0

    They include all the important featues that are needed to communicate with icq.

    But how can i use them into my C or C++ program? It must be possible, because other programs written in c also include compiled systemlibrarys, but i didnt find anything about that searching google.
    The libs itselfs are written in C.

    Please help me 😃

    Thx, Alex



  • well do you compile and link at the command line or do you use an IDE ?
    If you use an IDE , which one ?
    otherwise just add the lib in you linking step.

    example :
    g++ filename.cpp -o objectname -licq
    or if you have already compiled your source into an object file , then do smth like this
    g++ filname.o -o objectname -licq

    (this are c++ examples but c goes the same way)

    //edit
    I hope thats what you asked for



  • Hi, thx for the response 🙂

    But the problem is, that i want to use the methods declared in the library, e.g connect_icq() or something like that.

    If i try it like you told me, he cant use any of the functions. I also have to include them in the .cpp file directly. Is there any way?

    Also if i compile it with -o libfile.so -licq he makes no executable. Also another question.. what does the -licq mean?

    Do i have to create a headerfile that referes to the library so that he knows the method?

    Alex



  • Yes you have to include the headerfiles in your sourcefile.
    But if you have compiled the icq-source files into a lib you have to use this lib during the linking process to bild the binary ( executable).

    example sourcefile:

    #include<icq.h>// i do not know the name of the file you have to include for your function but i hope you know it
    #include<whatever>
    [...]
    somewhere
    icq_connect(params);
    ---

    end of file.

    now you can compile this file. and after the compiling process you have to link the object to get the binary.
    You can do both steps in one with gcc (c++)
    
    g++ file.cpp -o binaryname -licq
    ^-----^-------------^--------^---
    |     |             |        |
    |     |             |     use the libicq.so(e.g.)form you lib path(e.g. /usr/lib)           |
    |     |             the name of your binary    
    |     the file that includes the icq.h or whatever the name is
    your compiler
    

    well use gcc file.c -o binaryname -licq if you have written C code.

    I hope the use of -licq has become clear.
    well, what is your error message? what happens if you compile or link the file?
    Error masseges are welcome 😉



  • thx.. i have overwritten the lib the first time, because i did g++ mytest.cpp -o libfile -licq 😉

    was a bit wrong, but now it works... i made it the standart way i knew it putting the lib in front of the -o, but also works in your way 🙂 but thx for the graphical advice 👍

    But as you already advised.. there is an error 😉

    ./licq: error while loading shared libraries: libicq.so.1: cannot open shared object file: No such file or directory

    (i called my binary licq now 🙂 )

    Why does he search for libicq.so.1? Why cant he find it because its like the libfile in the same folder in the same directory where the mytest.cpp is located.

    I hope you can help me again 🙂



  • alexb83 schrieb:

    Why does he search for libicq.so.1?

    he want to use the functions from the library 😉 (like connect_icq(); )

    alexb83 schrieb:

    Why cant he find it because its like the libfile in the same folder in the same directory where the mytest.cpp is located.

    the library must be in /usr/lib/ or /usr/local/lib

    alexb83 schrieb:

    (i called my binary licq now 🙂 )

    not a good idea



  • he found the functions i think... as i compiled it without -o and the .sofile only with the headerfile the error "undefined reference to connect_icq" occurs, but as i added the .so file the error was gone.

    they are in these folders (copied them to both) but it doesnt find them (i deleted them from my homefolder). I also tried -l

    I changed it to icqprog 😉



  • alexb83 schrieb:

    ./licq: error while loading shared libraries: libicq.so.1: cannot open shared object file: No such file or directory

    (i called my binary licq now 🙂 )

    Why does he search for libicq.so.1?

    Well when you linked with the switch -licq you told the linker in your system's default lib directory is a lib named libicq.so.1..
    well it looks it up and so it has to be in you lib directory.
    e.g this is /usr/lib/ or /usr/local/lib
    If your lib is in that directorx please also check the read permissions



  • rights are ok... i should work...

    also tried something like

    g++ -L/usr/local/lib/ mytest.cpp -o icqprog -l /usr/local/lib/libicq.so

    or

    g++ -L/usr/local/lib/ mytest.cpp -o icqprog -l libicq.so

    but always an error like:

    /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.6/../../../../i686-pc-linux-gnu/bin/ld: cannot find -l/usr/local/lib/libicq.so
    collect2: ld returned 1 exit status



  • Well, in my humble opinion you just need a readable libicq.so.1 within the /usr/local/lib
    directory and link it with
    gcc mytest.cpp -o icqprog -licq

    If that doesnt work i also dont know, because i am not gcc and linking pro .sry



  • i got it workin... didnt get it, that -llib adds icq.so automaticly...

    now it works... 🙂

    thx very much 👍


Anmelden zum Antworten