Gcc Compile and link
Rupert Wood
me@rupey.net
Tue Apr 2 02:33:00 GMT 2002
Chris Simon wrote:
> When compiling and linking a program i got the result that
> the linker (LD) I face the problem that LD cannot find the
> libraries needed.
:
> gcc xml1.cc -l/libgcc.a -l/libxalan-c1_3.a -l/libxerces-c1_6_0.a
If you're compiling C++, you should use the compiler driver 'g++'
instead - although this won't make any difference if there's no link
step.
If you want to link path/libSomething.a, you have two choices:
g++ <...> path/libSomething.a
or g++ <...> -L path -lSomething
The '-l' flag assumes prefix 'lib' and suffix '.a' (or prefers '.so'
where available unless you specify '-static' - I think!) and uses the
library search paths specified with '-L', from the LIB environment
variable or built in to gcc.
You shouldn't have to explicitly link libgcc; it should do that
automatically.
So, fingers crossed, the command line you want is:
g++ xml1.cc -lxalan-c1_3 -lxerces-c1_6_0
which will generate output executable with the default name 'a.out'. To
specify another name, use the '-o' flag.
Hope that helps!
Rupert.
More information about the Gcc-help
mailing list