[CDRIVER-141] C driver building problems Created: 21/May/12  Updated: 19/Oct/16  Resolved: 25/May/12

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: 0.5.2, 0.6
Fix Version/s: 0.6

Type: Bug Priority: Major - P3
Reporter: Pawel Assignee: Kyle Banker
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Oracle Linux 6, x64, standard packages only



 Description   

There seems to be a bit of a mess with SConstruct and Makefile.

I'm gonna bundle all of my observations together, sorry, I don't know how to quite sort them out.

1) Building with Makefile is broken. See, the produced .so file(s) have no actual exported symbols in them.

[vps@druid]~/ws/EF/mongo-c-driver$ make
cc -o src/bson.o -c -std=c99 -pedantic  -O3 -Wall -ggdb  -D_POSIX_SOURCE -DMONGO_HAVE_STDINT src/bson.c
cc -o src/encoding.o -c -std=c99 -pedantic  -O3 -Wall -ggdb  -D_POSIX_SOURCE -DMONGO_HAVE_STDINT src/encoding.c
cc -o src/gridfs.o -c -std=c99 -pedantic  -O3 -Wall -ggdb  -D_POSIX_SOURCE -DMONGO_HAVE_STDINT src/gridfs.c
cc -o src/md5.o -c -std=c99 -pedantic  -O3 -Wall -ggdb  -D_POSIX_SOURCE -DMONGO_HAVE_STDINT src/md5.c
cc -o src/mongo.o -c -std=c99 -pedantic  -O3 -Wall -ggdb  -D_POSIX_SOURCE -DMONGO_HAVE_STDINT src/mongo.c
cc -o src/numbers.o -c -std=c99 -pedantic  -O3 -Wall -ggdb  -D_POSIX_SOURCE -DMONGO_HAVE_STDINT src/numbers.c
cc -o src/env_posix.o -c -std=c99 -pedantic  -O3 -Wall -ggdb  -D_POSIX_SOURCE -DMONGO_HAVE_STDINT src/env_posix.c
cc -shared -Wl,-soname,libmongoc.so.0.5 -o libmongoc.so 
cc -shared -Wl,-soname,libbson.so.0.5 -o libbson.so 
ar -rs libmongoc.a src/bson.o src/encoding.o src/gridfs.o src/md5.o src/mongo.o src/numbers.o src/env_posix.o
ar: creating libmongoc.a
ar -rs libbson.a src/bson.o src/numbers.o src/encoding.o
ar: creating libbson.a
[vps@druid]~/ws/EF/mongo-c-driver$ nm libmongoc.so | grep mongo
[vps@druid]~/ws/EF/mongo-c-driver$ 

That's because (a) the object files are not listed in the linkage command, and (b), object files are not compile with relocatable symbols.

This diff should take care of that problem:

diff --git a/Makefile b/Makefile
index 99c9dd8..c7bdfda 100644
--- a/Makefile
+++ b/Makefile
@@ -136,14 +136,17 @@ md5.o: src/md5.c src/md5.h
 mongo.o: src/mongo.c src/mongo.h src/bson.h src/md5.h src/env.h
 numbers.o: src/numbers.c
 
-$(MONGO_DYLIBNAME): $(MONGO_OBJECTS)
-       $(MONGO_DYLIB_MAKE_CMD)
+DYN_MONGO_OBJECTS=$(foreach i,$(MONGO_OBJECTS),$(i)s)
+DYN_BSON_OBJECTS=$(foreach i,$(MONGO_OBJECTS),$(i)s)
+
+$(MONGO_DYLIBNAME): $(DYN_MONGO_OBJECTS)
+       $(MONGO_DYLIB_MAKE_CMD) $^
 
 $(MONGO_STLIBNAME): $(MONGO_OBJECTS)
        $(AR) -rs $@ $(MONGO_OBJECTS)
 
-$(BSON_DYLIBNAME): $(BSON_OBJECTS)
-       $(BSON_DYLIB_MAKE_CMD)
+$(BSON_DYLIBNAME): $(DYN_BSON_OBJECTS)
+       $(BSON_DYLIB_MAKE_CMD) $^
 
 $(BSON_STLIBNAME): $(BSON_OBJECTS)
        $(AR) -rs $@ $(BSON_OBJECTS)
@@ -170,7 +173,7 @@ docs:
        python docs/buildscripts/docs.py
 
 clean:
-       rm -rf $(MONGO_DYLIBNAME) $(MONGO_STLIBNAME) $(BSON_DYLIBNAME) $(BSON_STLIBNAME) src/*.o test/*_test
+       rm -rf $(MONGO_DYLIBNAME) $(MONGO_STLIBNAME) $(BSON_DYLIBNAME) $(BSON_STLIBNAME) src/*.o src/*.os test/*_test
 
 deps:
        $(CC) -MM -DMONGO_HAVE_STDINT src/*.c
@@ -184,4 +187,10 @@ deps:
 %.o: %.c
        $(CC) -o $@ -c $(ALL_CFLAGS) $<
 
+
+%.os: %.c
+       $(CC) -o $@ -c $(ALL_CFLAGS) $(DYN_FLAGS) $<
+
+%.os: DYN_FLAGS :=  -fPIC -DMONGO_DLL_BUILD
+
 .PHONY: clean docs

Ok, now, though Makefile doesn't build right, SCons doesn't install right.
I never had any dealings with SCons before this project, so I don't know how to quite address this, but the two things to address are:

(1) Creating shared library - installing .so is not enough, because soname is set to libsome-so.ver, the dynamic linker will insist on looking for that exact file during execution. The links must be installed properly.
(2) Specifying where to install:

for installing via Makefile, you can at least do:

sudo INSTALL_INCLUDE_PATH=/usr/local/mongo-0.6/include INSTALL_LIBRARY_PATH=/usr/local/mongo-0.6/lib make install

but with SCons, there is no indication on how to specify where the installation should be done.

Thanks, Pawel.



 Comments   
Comment by auto [ 25/May/12 ]

Author:

{u'login': u'banker', u'name': u'Kyle Banker', u'email': u'kylebanker@gmail.com'}

Message: CDRIVER-141 custom install and include paths for SCons
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/dba16666e36a6a555852d0fb3f59b6ff02f55dfd

Comment by auto [ 25/May/12 ]

Author:

{u'login': u'banker', u'name': u'Kyle Banker', u'email': u'kylebanker@gmail.com'}

Message: CDRIVER-141 fix build and install for shared libs
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/5681a8a324bffe702a6c275473a3fe5c59f966c9

Generated at Wed Feb 07 21:08:34 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.