Add -Wl,--soname=libns3.so to link flags to allow dlopen hacks
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Mon, 18 May 2009 11:06:26 +0100
changeset 4446 56b16bcd3afc
parent 4445 cca2582a0cb1
child 4447 0b42685f6b78
Add -Wl,--soname=libns3.so to link flags to allow dlopen hacks Mathieu's explanation: """ In python, I want to load the ns3 python bindings without having to install libns3.so in /usr and without having to configure LD_LIBRARY_PATH. So, I need to dlopen (RTLD_GLOBAL) libns3.so before doing imp.find_module ('ns3') to ensure that python finds the libns3.so library. To do the dlopen, I need to give a full path to libns3.so but, if you do this without a soname, the dynamic loader does not know about libns3.so: it knows only about /foo/bar/libns3.so. """
wscript
--- a/wscript	Thu May 14 10:21:38 2009 +0200
+++ b/wscript	Mon May 18 11:06:26 2009 +0100
@@ -255,13 +255,18 @@
             env.append_value("LINKFLAGS", "-Wl,--enable-runtime-pseudo-reloc")
         elif sys.platform == 'cygwin':
             env.append_value("LINKFLAGS", "-Wl,--enable-auto-import")
+
         cxx, = env['CXX']
+
         p = subprocess.Popen([cxx, '-print-file-name=libstdc++.so'], stdout=subprocess.PIPE)
         libstdcxx_location = os.path.dirname(p.stdout.read().strip())
         p.wait()
         if libstdcxx_location:
             conf.env.append_value('NS3_MODULE_PATH', libstdcxx_location)
 
+        if conf.check_compilation_flag('-Wl,--soname=foo'):
+            env['WL_SONAME_SUPPORTED'] = True
+
     conf.sub_config('src')
     conf.sub_config('utils')
     conf.sub_config('bindings/python')
@@ -480,11 +485,15 @@
     ## Create a single ns3 library containing all enabled modules
     if env['ENABLE_STATIC_NS3']:
         lib = bld.new_task_gen('cxx', 'staticlib')
+        lib.name = 'ns3'
+        lib.target = 'ns3'
     else:
         lib = bld.new_task_gen('cxx', 'shlib')
+        lib.name = 'ns3'
+        lib.target = 'ns3'
+        if lib.env['CXX_NAME'] == 'gcc' and env['WL_SONAME_SUPPORTED']:
+            lib.env.append_value('LINKFLAGS', '-Wl,--soname=%s' % ccroot.get_target_name(lib))
 
-    lib.name = 'ns3'
-    lib.target = 'ns3'
     if env['NS3_ENABLED_MODULES']:
         lib.add_objects = list(modules)
         env['NS3_ENABLED_MODULES'] = list(modules)