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"<<endl instead of a printf. It seemed that linking in the libstdc
++.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
Re: How to identify required libraries
coltrane wrote:[color=blue]
> 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"<<endl instead of a printf. It seemed that linking in the libstdc
> ++.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.
>[/color]
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
Re: How to identify required libraries
On Sep 12, 11:42 am, Tauno Voipio <tauno.voi...@INVALIDiki.fi> wrote:[color=blue]
> coltrane wrote:[color=green]
> > 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"<<endl instead of a printf. It seemed that linking in the libstdc
> > ++.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'[/color]
>[color=green]
> > 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.[/color]
>
> 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[/color]
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 <iostream>
int main(int argc, char ** argv){
std::cout << "hello" << endl;
}
Re: How to identify required libraries
On Sep 12, 11:42 am, Tauno Voipio <tauno.voi...@INVALIDiki.fi> wrote:[color=blue]
> coltrane wrote:[color=green]
> > 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"<<endl instead of a printf. It seemed that linking in the libstdc
> > ++.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'[/color]
>[color=green]
> > 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.[/color]
>
> 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[/color]
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
Re: How to identify required libraries
On Sep 12, 11:42 am, Tauno Voipio <tauno.voi...@INVALIDiki.fi> wrote:[color=blue]
> coltrane wrote:[color=green]
> > 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"<<endl instead of a printf. It seemed that linking in the libstdc
> > ++.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'[/color]
>[color=green]
> > 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.[/color]
>
> 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[/color]
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.
Re: How to identify required libraries
john coltrane wrote:[color=blue]
> On Sep 12, 11:42 am, Tauno Voipio <tauno.voi...@INVALIDiki.fi> wrote:[color=green]
>> coltrane wrote:[color=darkred]
>>> 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"<<endl instead of a printf. It seemed that linking in the libstdc
>>> ++.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.[/color]
>> 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[/color]
>
> 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.[/color]
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
Re: How to identify required libraries
1. Slight program bug -- it should be
#include <iostream>
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