Operating System - HP-UX
1752568 Members
5442 Online
108788 Solutions
New Discussion юеВ

aCC compiler and libraries

 
Pratheesh
Advisor

aCC compiler and libraries

We are using message Queue libraries(libmqm) for linking to an executable, which is compiled by aCC compiler. Usually We will link the messageQ library as follows:

aCC -o main main.cc -L/tools/rp56/lib -lmqm .

Under /tools/rp56/lib, We have one shared library and one archive libary of the same name. ie; libmqm.sl and libmqm.a .

1) How can I make sure that while linking with -l option it will pick up archive ?
2) Is there any default setting like, it will always pick up shared one first?
3) If there is a default setting, What is the option for picking up the other one?

Can anybody throw some light on this ?

3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor

Re: aCC compiler and libraries

You can use the +A argument to aCC to instruct ACC that all -l references are archive libraries but if you want to use both archive and shared librararies then you need to pass the -a archive_shared option to the linker phase of aCC. -a archive_shared tell ld to look first for archived libraries but if not found use the shared version.

Man aCC, ld for details.
If it ain't broke, I can fix that.
curt larson_1
Honored Contributor

Re: aCC compiler and libraries

If both an archive and shared version of a particular library reside in the same directory, the linker links in the shared version by default. You can override this behavior with the -a linker option.
NOTE: You can use the +A option if you are using only archive libraries to create a completely archived executable.


The -a linker option tells the linker which type of library to use. The -a option is positional and applies to all subsequent libraries specified with the -l option until the end of the command line or until the next -a option is encountered. Pass the -a option to the linker with the -Wx,args option.

The following example directs the linker to use the archive version of the library libshape, followed by standard shared libraries if they exist; otherwise select archive versions.

aCC box.o sphere.o -Wl,-a,archive -lshape -Wl,-a,default
Mike Stroyan
Honored Contributor

Re: aCC compiler and libraries

You can also force archive for one library by using
-l:libmqrn.a
That can be less trouble-prone when most libraries should be using shared libraries.