How to identify required libraries - Linux

This is a discussion on How to identify required libraries - Linux ; I am just starting to program in a linux environment and I am having trouble identifying what libraries I need to link against. First I tried a simple hello world written in C. I didn't specify a lib and the ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: How to identify required libraries

  1. How to identify required libraries

    I am just starting to program in a linux environment and I am having
    trouble identifying what libraries I need to link against. First I
    tried a simple hello world written in C. I didn't specify a lib and
    the app compiled, linked, and ran fine.
    I next tried to create a hello world using stl, ie cout<< "hello
    world"< ++.a lib would work but I received a stream of errors. This is just a
    sample:
    /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    function `d_demangle':
    (.text+0x4145): undefined reference to `strlen'
    /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    function `d_demangle':
    (.text+0x4272): undefined reference to `malloc'
    /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    function `d_demangle':
    (.text+0x433a): undefined reference to `malloc'
    /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    function `d_demangle':
    (.text+0x4397): undefined reference to `strcat'
    /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    function `d_demangle':
    (.text+0x43e7): undefined reference to `__stack_chk_fail_local'
    /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    function `__cxa_demangle':
    (.text+0x449a): undefined reference to `strlen'
    /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    function `__cxa_demangle':
    (.text+0x44ad): undefined reference to `strcpy'
    /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    function `__cxa_demangle':
    (.text+0x44b8): undefined reference to `free'
    /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    function `__cxa_demangle':
    (.text+0x44e4): undefined reference to `free'

    so 2 questions, first what additional library do I need to get stl
    based apps to link and second how do I identify libraries I need for
    other apps?
    An example would be writing an app that uses sockets and threading.
    How do I find the libraries that provide the required functionality.

    thanks for the help

    john

  2. Re: How to identify required libraries

    coltrane wrote:
    > I am just starting to program in a linux environment and I am having
    > trouble identifying what libraries I need to link against. First I
    > tried a simple hello world written in C. I didn't specify a lib and
    > the app compiled, linked, and ran fine.
    > I next tried to create a hello world using stl, ie cout<< "hello
    > world"< > ++.a lib would work but I received a stream of errors. This is just a
    > sample:
    > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > function `d_demangle':
    > (.text+0x4145): undefined reference to `strlen'
    > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > function `d_demangle':
    > (.text+0x4272): undefined reference to `malloc'
    > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > function `d_demangle':
    > (.text+0x433a): undefined reference to `malloc'
    > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > function `d_demangle':
    > (.text+0x4397): undefined reference to `strcat'
    > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > function `d_demangle':
    > (.text+0x43e7): undefined reference to `__stack_chk_fail_local'
    > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > function `__cxa_demangle':
    > (.text+0x449a): undefined reference to `strlen'
    > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > function `__cxa_demangle':
    > (.text+0x44ad): undefined reference to `strcpy'
    > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > function `__cxa_demangle':
    > (.text+0x44b8): undefined reference to `free'
    > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > function `__cxa_demangle':
    > (.text+0x44e4): undefined reference to `free'
    >
    > so 2 questions, first what additional library do I need to get stl
    > based apps to link and second how do I identify libraries I need for
    > other apps?
    > An example would be writing an app that uses sockets and threading.
    > How do I find the libraries that provide the required functionality.
    >


    What was the command line used to link the object files together?

    Please do not use ld directly, use the C/C++ compiler driver instead,
    so the standard libraries get linked in by default.

    --

    Tauno Voipio
    tauno voipio (at) iki fi


  3. Re: How to identify required libraries

    On Sep 12, 11:42 am, Tauno Voipio wrote:
    > coltrane wrote:
    > > I am just starting to program in a linux environment and I am having
    > > trouble identifying what libraries I need to link against. First I
    > > tried a simple hello world written in C. I didn't specify a lib and
    > > the app compiled, linked, and ran fine.
    > > I next tried to create a hello world using stl, ie cout<< "hello
    > > world"< > > ++.a lib would work but I received a stream of errors. This is just a
    > > sample:
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `d_demangle':
    > > (.text+0x4145): undefined reference to `strlen'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `d_demangle':
    > > (.text+0x4272): undefined reference to `malloc'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `d_demangle':
    > > (.text+0x433a): undefined reference to `malloc'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `d_demangle':
    > > (.text+0x4397): undefined reference to `strcat'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `d_demangle':
    > > (.text+0x43e7): undefined reference to `__stack_chk_fail_local'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `__cxa_demangle':
    > > (.text+0x449a): undefined reference to `strlen'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `__cxa_demangle':
    > > (.text+0x44ad): undefined reference to `strcpy'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `__cxa_demangle':
    > > (.text+0x44b8): undefined reference to `free'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `__cxa_demangle':
    > > (.text+0x44e4): undefined reference to `free'

    >
    > > so 2 questions, first what additional library do I need to get stl
    > > based apps to link and second how do I identify libraries I need for
    > > other apps?
    > > An example would be writing an app that uses sockets and threading.
    > > How do I find the libraries that provide the required functionality.

    >
    > What was the command line used to link the object files together?
    >
    > Please do not use ld directly, use the C/C++ compiler driver instead,
    > so the standard libraries get linked in by default.
    >
    > --
    >
    > Tauno Voipio
    > tauno voipio (at) iki fi


    I used

    gcc -c hello.cpp -o hello.o
    ld hello.o /usr/lib/gcc/i386-redhat-linux/libstdc++.a -o hello

    the app was very simple:

    #include
    int main(int argc, char ** argv){
    std::cout << "hello" << endl;
    }


  4. Re: How to identify required libraries

    On Sep 12, 11:42 am, Tauno Voipio wrote:
    > coltrane wrote:
    > > I am just starting to program in a linux environment and I am having
    > > trouble identifying what libraries I need to link against. First I
    > > tried a simple hello world written in C. I didn't specify a lib and
    > > the app compiled, linked, and ran fine.
    > > I next tried to create a hello world using stl, ie cout<< "hello
    > > world"< > > ++.a lib would work but I received a stream of errors. This is just a
    > > sample:
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `d_demangle':
    > > (.text+0x4145): undefined reference to `strlen'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `d_demangle':
    > > (.text+0x4272): undefined reference to `malloc'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `d_demangle':
    > > (.text+0x433a): undefined reference to `malloc'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `d_demangle':
    > > (.text+0x4397): undefined reference to `strcat'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `d_demangle':
    > > (.text+0x43e7): undefined reference to `__stack_chk_fail_local'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `__cxa_demangle':
    > > (.text+0x449a): undefined reference to `strlen'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `__cxa_demangle':
    > > (.text+0x44ad): undefined reference to `strcpy'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `__cxa_demangle':
    > > (.text+0x44b8): undefined reference to `free'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `__cxa_demangle':
    > > (.text+0x44e4): undefined reference to `free'

    >
    > > so 2 questions, first what additional library do I need to get stl
    > > based apps to link and second how do I identify libraries I need for
    > > other apps?
    > > An example would be writing an app that uses sockets and threading.
    > > How do I find the libraries that provide the required functionality.

    >
    > What was the command line used to link the object files together?
    >
    > Please do not use ld directly, use the C/C++ compiler driver instead,
    > so the standard libraries get linked in by default.
    >
    > --
    >
    > Tauno Voipio
    > tauno voipio (at) iki fi


    okay so I tried:

    gcc hello.cpp /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a -o
    hello

    and that worked.

    I am still curious and would like to know what combination of
    libraries I would need.

    thanks again

  5. Re: How to identify required libraries

    On Sep 12, 11:42 am, Tauno Voipio wrote:
    > coltrane wrote:
    > > I am just starting to program in a linux environment and I am having
    > > trouble identifying what libraries I need to link against. First I
    > > tried a simple hello world written in C. I didn't specify a lib and
    > > the app compiled, linked, and ran fine.
    > > I next tried to create a hello world using stl, ie cout<< "hello
    > > world"< > > ++.a lib would work but I received a stream of errors. This is just a
    > > sample:
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `d_demangle':
    > > (.text+0x4145): undefined reference to `strlen'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `d_demangle':
    > > (.text+0x4272): undefined reference to `malloc'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `d_demangle':
    > > (.text+0x433a): undefined reference to `malloc'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `d_demangle':
    > > (.text+0x4397): undefined reference to `strcat'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `d_demangle':
    > > (.text+0x43e7): undefined reference to `__stack_chk_fail_local'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `__cxa_demangle':
    > > (.text+0x449a): undefined reference to `strlen'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `__cxa_demangle':
    > > (.text+0x44ad): undefined reference to `strcpy'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `__cxa_demangle':
    > > (.text+0x44b8): undefined reference to `free'
    > > /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    > > function `__cxa_demangle':
    > > (.text+0x44e4): undefined reference to `free'

    >
    > > so 2 questions, first what additional library do I need to get stl
    > > based apps to link and second how do I identify libraries I need for
    > > other apps?
    > > An example would be writing an app that uses sockets and threading.
    > > How do I find the libraries that provide the required functionality.

    >
    > What was the command line used to link the object files together?
    >
    > Please do not use ld directly, use the C/C++ compiler driver instead,
    > so the standard libraries get linked in by default.
    >
    > --
    >
    > Tauno Voipio
    > tauno voipio (at) iki fi


    it seems that if I run the compile with the "-v" option this will tell
    me everything that was "sucked in" to compile and link.

  6. Re: How to identify required libraries

    john coltrane wrote:
    > On Sep 12, 11:42 am, Tauno Voipio wrote:
    >> coltrane wrote:
    >>> I am just starting to program in a linux environment and I am having
    >>> trouble identifying what libraries I need to link against. First I
    >>> tried a simple hello world written in C. I didn't specify a lib and
    >>> the app compiled, linked, and ran fine.
    >>> I next tried to create a hello world using stl, ie cout<< "hello
    >>> world"< >>> ++.a lib would work but I received a stream of errors. This is just a
    >>> sample:
    >>> /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    >>> function `d_demangle':
    >>> (.text+0x4145): undefined reference to `strlen'
    >>> /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    >>> function `d_demangle':
    >>> (.text+0x4272): undefined reference to `malloc'
    >>> /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    >>> function `d_demangle':
    >>> (.text+0x433a): undefined reference to `malloc'
    >>> /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    >>> function `d_demangle':
    >>> (.text+0x4397): undefined reference to `strcat'
    >>> /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    >>> function `d_demangle':
    >>> (.text+0x43e7): undefined reference to `__stack_chk_fail_local'
    >>> /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    >>> function `__cxa_demangle':
    >>> (.text+0x449a): undefined reference to `strlen'
    >>> /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    >>> function `__cxa_demangle':
    >>> (.text+0x44ad): undefined reference to `strcpy'
    >>> /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    >>> function `__cxa_demangle':
    >>> (.text+0x44b8): undefined reference to `free'
    >>> /usr/lib/gcc/i386-redhat-linux/4.1.2/libstdc++.a(cp-demangle.o): In
    >>> function `__cxa_demangle':
    >>> (.text+0x44e4): undefined reference to `free'
    >>> so 2 questions, first what additional library do I need to get stl
    >>> based apps to link and second how do I identify libraries I need for
    >>> other apps?
    >>> An example would be writing an app that uses sockets and threading.
    >>> How do I find the libraries that provide the required functionality.

    >> What was the command line used to link the object files together?
    >>
    >> Please do not use ld directly, use the C/C++ compiler driver instead,
    >> so the standard libraries get linked in by default.
    >>
    >> --
    >>
    >> Tauno Voipio
    >> tauno voipio (at) iki fi

    >
    > it seems that if I run the compile with the "-v" option this will tell
    > me everything that was "sucked in" to compile and link.



    Woud you please read the compiling and linking
    instructions next time. Linking the compiler and
    standard runtime libraries expilicitly will either
    work or fail mysteriously. The proper collection
    of libraries is built-in into the GCC driver program,
    use it.

    Please use gcc for C code and g++ for C++ code.

    If you're interested what's really picked in, add

    -Wl,-Map=myfile.map

    to the compiler command line.

    --

    Tauno Voipio
    tauno voipio (at) iki fi

  7. Re: How to identify required libraries

    1. Slight program bug -- it should be

    #include
    int main(int argc, char ** argv){
    std::cout << "hello" << std::endl; //need namespace on endl
    }

    2. Compile and link it with

    g++ -o hello hello.cpp

+ Reply to Thread