[reSIProcate] building shared libraries on AMD64
Byron Campen
bcampen at estacado.net
Fri Sep 22 16:09:40 CDT 2006
This slightly beefier patch seems to be working so far for me.
Index: build/Makefile.post
===================================================================
--- build/Makefile.post (revision 6598)
+++ build/Makefile.post (working copy)
@@ -83,7 +83,13 @@
DEPEND_TARGETS += $(foreach pkg,$(PACKAGES), $($(pkg)_TARGETS))
ifeq ($(BUILD_SHARED_LIBS),yes)
+
+ifeq ($(OSTYPE),Darwin)
+.dependlibs: $(patsubst %.a,%.dylib,$(DEPEND_FILES))
+else
.dependlibs: $(patsubst %.a,%.so,$(DEPEND_FILES))
+endif
+
else
.dependlibs: $(DEPEND_FILES)
endif
@@ -111,7 +117,12 @@
HWOBJS = $(patsubst %.cpp,$(OBJ)/%.o,$(patsubst %.c,$(OBJ)/%.o,$
(patsubst %.cxx,$(OBJ)/%.o,$(HWSRC))))
DEPENDENCIES = $(patsubst %.cpp,$(OBJ)/%.d,$(patsubst %.c,$(OBJ)/%.d,$
(patsubst %.cxx,$(OBJ)/%.d,$(ALLSRC))))
+ifeq ($(OSTYPE),Darwin)
+SHARED_LIB = $(patsubst %,$(OBJ)/%.dylib,$(strip $(TARGET_LIBRARY)))
+else
SHARED_LIB = $(patsubst %,$(OBJ)/%.so,$(strip $(TARGET_LIBRARY)))
+endif
+
STATIC_LIB = $(patsubst %,$(OBJ)/%.a,$(strip $(TARGET_LIBRARY)))
ifeq ($(BUILD_SHARED_LIBS),yes)
@@ -293,6 +304,12 @@
$(MKSHLIB) -o $@ $^
-@ mkdir -p $(ROOT)/lib.$(TARGET_NAME)
@ test -h $(ROOT)/lib.$(TARGET_NAME)/$(strip $
(TARGET_LIBRARY)).so || ln -s $(shell pwd)/$@ $(ROOT)/lib.$(TARGET_NAME)
+
+$(OBJ)/$(strip $(TARGET_LIBRARY)).dylib: $(OBJS) $(OTHERLIBS)
+ -@ test -f $@ && /bin/rm $@
+ $(MKSHLIB) -o $@ $^
+ -@ mkdir -p $(ROOT)/lib.$(TARGET_NAME)
+ @ test -h $(ROOT)/lib.$(TARGET_NAME)/$(strip $
(TARGET_LIBRARY)).dylib || ln -s $(shell pwd)/$@ $(ROOT)/lib.$
(TARGET_NAME)
endif
ifdef TARGET_BINARY
Index: build/Makefile.tools
===================================================================
--- build/Makefile.tools (revision 6598)
+++ build/Makefile.tools (working copy)
@@ -31,7 +31,14 @@
CC = gcc
CXX = g++
-MKSHLIB := $(CC) -fPIC -shared
+
+ifeq ($(OSTYPE),Darwin)
+MKSHLIB := $(CC) -fPIC -flat_namespace -undefined
suppress -dynamic -dynamic-lib
+LDFLAGS += -flat_namespace
+else
+MKSHLIB := $(CC) -fPIC -shared
+endif
+
DEP := $(CXX)
LINKER := $(CXX)
RANLIB = ranlib
@@ -43,6 +50,12 @@
LNDIR = $(shell pwd)/$(ROOT)/build/lndir.sh
CFLAGS += -Wall
CXXFLAGS += -Wall
+
+ifeq ($(BUILD_SHARED_LIBS),yes)
+CFLAGS += -fPIC
+CXXFLAGS += -fPIC
+endif
+
DFLAG_INTEGRATED = -MMD
DEBUG_FLAG = -g
COMPILE_SMALL_FLAG = -Os -fno-inline -fno-keep-static-consts
Best regards,
Byron Campen
> Well, this appears to break the shared library build on OS X.
> (Missing libstdc++ symbols) I am trying to fix this. (This will
> require .dylib support from the build system)
>
> Best regards,
> Byron Campen
>
>> Hrm, looks like the object files need to be compiled with -fPIC
>> too. I will try the following slightly different patch:
>>
>> Index: build/Makefile.tools
>> ===================================================================
>> --- build/Makefile.tools (revision 6598)
>> +++ build/Makefile.tools (working copy)
>> @@ -43,6 +43,12 @@
>> LNDIR = $(shell pwd)/$(ROOT)/build/lndir.sh
>> CFLAGS += -Wall
>> CXXFLAGS += -Wall
>> +
>> +ifeq ($(BUILD_SHARED_LIBS),yes)
>> +CFLAGS += -fPIC
>> +CXXFLAGS += -fPIC
>> +endif
>> +
>> DFLAG_INTEGRATED = -MMD
>> DEBUG_FLAG = -g
>> COMPILE_SMALL_FLAG = -Os -fno-inline -fno-keep-static-consts
>>
>> Best regards,
>> Byron Campen
>>
>>
>>> hi Byron
>>>
>>> here is the error when building rutil shared:
>>>
>>>
>>> gcc -fPIC -shared -o obj.debug.Linux.x86_64/librutil.so
>>> obj.debug.Linux.x86_64/AbstractFifo.o obj.debug.Linux.x86_64/
>>> BaseException.o obj.debug.Linux.x86_64/Coders.o
>>> obj.debug.Linux.x86_64/Condition.o obj.debug.Linux.x86_64/
>>> CountStream.o obj.debug.Linux.x86_64/Data.o
>>> obj.debug.Linux.x86_64/DataStream.o obj.debug.Linux.x86_64/
>>> DnsUtil.o obj.debug.Linux.x86_64/FileSystem.o
>>> obj.debug.Linux.x86_64/HeapInstanceCounter.o
>>> obj.debug.Linux.x86_64/Lock.o obj.debug.Linux.x86_64/Log.o
>>> obj.debug.Linux.x86_64/Logger.o obj.debug.Linux.x86_64/
>>> MD5Stream.o obj.debug.Linux.x86_64/Mutex.o obj.debug.Linux.x86_64/
>>> OpenSSLInit.o obj.debug.Linux.x86_64/ParseBuffer.o
>>> obj.debug.Linux.x86_64/Poll.o obj.debug.Linux.x86_64/RWMutex.o
>>> obj.debug.Linux.x86_64/Random.o obj.debug.Linux.x86_64/
>>> RecursiveMutex.o obj.debug.Linux.x86_64/SelectInterruptor.o
>>> obj.debug.Linux.x86_64/SHA1Stream.o obj.debug.Linux.x86_64/
>>> Socket.o obj.debug.Linux.x86_64/Subsystem.o
>>> obj.debug.Linux.x86_64/SysLogBuf.o obj.debug.Linux.x86_64/
>>> SysLogStream.o obj.debug.Linux.x86_64/ThreadIf.o
>>> obj.debug.Linux.x86_64/Timer.o obj.debug.Linux.x86_64/vmd5.o
>>> obj.debug.Linux.x86_64/dns/AresDns.o obj.debug.Linux.x86_64/dns/
>>> DnsAAAARecord.o obj.debug.Linux.x86_64/dns/DnsCnameRecord.o
>>> obj.debug.Linux.x86_64/dns/DnsHostRecord.o obj.debug.Linux.x86_64/
>>> dns/DnsNaptrRecord.o obj.debug.Linux.x86_64/dns/DnsSrvRecord.o
>>> obj.debug.Linux.x86_64/dns/DnsStub.o obj.debug.Linux.x86_64/dns/
>>> ExternalDnsFactory.o obj.debug.Linux.x86_64/dns/RRCache.o
>>> obj.debug.Linux.x86_64/dns/RRList.o obj.debug.Linux.x86_64/dns/
>>> RRVip.o obj.debug.Linux.x86_64/dns/QueryTypes.o
>>> obj.debug.Linux.x86_64/dns/RROverlay.o obj.debug.Linux.x86_64/
>>> stun/Stun.o obj.debug.Linux.x86_64/stun/Udp.o
>>> /usr/bin/ld: obj.debug.Linux.x86_64/AbstractFifo.o: relocation
>>> R_X86_64_32 against `a local symbol' can not be used when making
>>> a shared object; recompile with -fPIC
>>> obj.debug.Linux.x86_64/AbstractFifo.o: could not read symbols:
>>> Bad value
>>> collect2: ld returned 1 exit status
>>> make: *** [obj.debug.Linux.x86_64/librutil.so] Error 1
>>>
>>>
>>> the system is Ubuntu 6.06 AMD64, g++ v4.0.3
>>>
>>>
>>> my fix was to add the -fPIC compile flag:
>>> (you should verify if this is correct)
>>>
>>>
>>> --- build/Makefile.tools (revision 6599)
>>> +++ build/Makefile.tools (working copy)
>>> @@ -41,8 +41,8 @@
>>> DMANGLE =
>>> INSTALL = install
>>> LNDIR = $(shell pwd)/$(ROOT)/build/lndir.sh
>>> -CFLAGS += -Wall
>>> -CXXFLAGS += -Wall
>>> +CFLAGS += -Wall -fPIC
>>> +CXXFLAGS += -Wall -fPIC
>>> DFLAG_INTEGRATED = -MMD
>>> DEBUG_FLAG = -g
>>> COMPILE_SMALL_FLAG = -Os -fno-inline -fno-keep-static-consts
>>>
>>>
>>> /alfred
>>>
>>> Byron Campen wrote:
>>>> I see some logic in the build system that was meant to
>>>> handle this sort of thing, but it appears to not be working.
>>>> Could you send the link-line?
>>>> Best regards,
>>>> Byron Campen
>>>>> hi
>>>>>
>>>>> when building resiprocate with "Should the resip libraries be
>>>>> built
>>>>> shared?" set to "Yes", I got the following error:
>>>>>
>>>>>
>>>>> /usr/bin/ld: obj.debug.Linux.x86_64/AbstractFifo.o: relocation
>>>>> R_X86_64_32 against `a local symbol' can not be used when making a
>>>>> shared object; recompile with -fPIC
>>>>> obj.debug.Linux.x86_64/AbstractFifo.o: could not read symbols:
>>>>> Bad value
>>>>> collect2: ld returned 1 exit status
>>>>> make: *** [obj.debug.Linux.x86_64/librutil.so] Error 1
>>>>>
>>>>>
>>>>> adding the "-fPIC" option solved the problem, but I am not sure if
>>>>> this is the correct way to solve it.. patch below:
>>>>>
>>>>>
>>>>> Index: build/Makefile.tools
>>>>> ==================================================================
>>>>> =
>>>>> --- build/Makefile.tools (revision 6553)
>>>>> +++ build/Makefile.tools (working copy)
>>>>> @@ -41,8 +41,8 @@
>>>>> DMANGLE =
>>>>> INSTALL = install
>>>>> LNDIR = $(shell pwd)/$(ROOT)/build/lndir.sh
>>>>> -CFLAGS += -Wall
>>>>> -CXXFLAGS += -Wall
>>>>> +CFLAGS += -Wall -fPIC
>>>>> +CXXFLAGS += -Wall -fPIC
>>>>> DFLAG_INTEGRATED = -MMD
>>>>> DEBUG_FLAG = -g
>>>>> COMPILE_SMALL_FLAG = -Os -fno-inline -fno-keep-static-consts
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> resiprocate-devel mailing list
>>>>> resiprocate-devel at list.sipfoundry.org
>>>>> https://list.sipfoundry.org/mailman/listinfo/resiprocate-devel
>>>
>>
>> _______________________________________________
>> resiprocate-devel mailing list
>> resiprocate-devel at list.sipfoundry.org
>> https://list.sipfoundry.org/mailman/listinfo/resiprocate-devel
>
> _______________________________________________
> resiprocate-devel mailing list
> resiprocate-devel at list.sipfoundry.org
> https://list.sipfoundry.org/mailman/listinfo/resiprocate-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2369 bytes
Desc: not available
URL: <http://list.resiprocate.org/pipermail/resiprocate-devel/attachments/20060922/bd18def0/attachment.bin>
More information about the resiprocate-devel
mailing list