Makefile/linker question

I have been googling around and either my google foo is weak today or there isn't a clear cut answer to my question out there.

I've got a few libraries that I link with when compiling my code and it looks something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
XLIBS		+= `pkg-config glibmm-2.4 --libs`

INCLUDES	+= -I../../Interfaces/myinterfaces
INCLUDES	+= -I../../Components/mylib
INCLUDES	+= -I../../Components/myotherlib
INCLUDES	+= -I../../Components/vpxlib

VPATH		+= ../../../../builds/latest/$(CFG)/libs

LIBS		+= -lmylib
LIBS		+= -lmyotherlib
LIBS		+= -lboost_thread
LIBS		+= -lboost_system
LIBS		+= -lvpx
LIBS		+= -lrt

FILES 		+= Globals.cpp
FILES 		+= MNDNetworkSettingsDlg.cpp
FILES 		+= MTDNetworkDevice.cpp

OBJECTS		= $(patsubst %.cpp,$(CFG)/%.o,$(FILES))

OUTDIR		= ../../../../builds/latest/$(CFG)/
TARGET		= $(OUTDIR)/dev_networkdevice.so

CTARGETS	+= $(DIRRES)/dev_networkdevice.mrf

.PHONY: clean all banner

all: depends target

clean:
	@-rm -f *.gch $(CFG)/* $(TARGET) $(CTARGETS)

target: banner $(TARGET) $(CTARGETS)

$(TARGET): $(OBJECTS) $(LIBS)
	@mkdir -p $(OUTDIR)
	$(CXX) -shared -fPIC -g -Wl,--version-script=networkdevice.ver,-z,defs -o $@ -pthread $^ $(XLIBS) */


(Sorry for the weird c++ style comment error there...)

I've omitted a few minor details, let me know if I need to explain anything or give more sample code.


Anyway, my question is this: When I link with $(LIBS), the linker (or GNU Make or something...) translates -lmylib and -lmyotherlib to /pathtolib/libmylib.a and /pathtolib/libmyotherlib.a which is good, these are static libraries that I want to link with. There is no libmylib.so or libmyotherlib.so file in that directory (or anywhere else). Now I want to link with libboost_system.a, libboost_thread.a, libvpx.a and librt.a, but the folders where those libraries are located contain both libboost_system.a and libboost_system.so (same with the other libraries) and for some reason specifying -lboost_system always picks the .so file over the .a file.

I want -lboost_system to pick the .a file instead of the .so file without having to specify /usr/lib/libboost_system.a. Is that possible??

Please let me know if I'm being unclear or if you have any questions.

Any ideas, thoughts or input is welcome!

Thank you.
Last edited on
Try this option:
  -static
           Do not link against shared libraries.  [...]
           You  may  use  this  option  multiple times on the command line: it
           affects library searching for -l options  which  follow  it.
Thanks for the suggestion Cubbi. I've tried that, and I've also tried specifying the -Bstatic option for the linker.

The problem I'm seeing is that somewhere between lines 15 and 39 of the code I provided -lboost_thread (for example) gets translated to /usr/lib/libboost_thread.so. Clearly I don't know much about Makefiles and I've been googling around all day trying to figure out how that happens.

TL;DR Something translates -lboost_thread to /usr/lib/libboost_thread.so, I want whatever that thing is to translate it to /usr/lib/libboost_thread.a. Is there an elegant way to do that??
BBBBBBUUUuuuuuUUUuUuUuuMMMMmmMmmPPPPpppPp
$ make --just-print
Topic archived. No new replies allowed.