From 1600cda4875b1917cc37b9c1456648d186066c1b Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 2 Jan 2023 22:25:48 +0200 Subject: [PATCH] Build shared libraries directly to a versioned name The MSVC linker does not have an equivalent to the GNU linker's soname option, so the build filename must match the one the library will be loaded with at runtime. --- plugins/gnu/mingwdlltool.cpp | 5 +---- source/lib/sharedlibrary.cpp | 32 ++++++++++++++------------------ 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/plugins/gnu/mingwdlltool.cpp b/plugins/gnu/mingwdlltool.cpp index e93edc3..f012800 100644 --- a/plugins/gnu/mingwdlltool.cpp +++ b/plugins/gnu/mingwdlltool.cpp @@ -94,10 +94,7 @@ Task *MingwDllTool::_run(const Target &target) argv.push_back(relative(exp->get_path(), work_dir).str()); argv.push_back("-D"); - if(shlib.get_install_filename().empty()) - argv.push_back(FS::basename(shlib.get_path())); - else - argv.push_back(shlib.get_install_filename()); + argv.push_back(FS::basename(shlib.get_path())); argv.push_back("-l"); argv.push_back(relative(imp->get_path(), work_dir).str()); diff --git a/source/lib/sharedlibrary.cpp b/source/lib/sharedlibrary.cpp index aae3663..bd8ee26 100644 --- a/source/lib/sharedlibrary.cpp +++ b/source/lib/sharedlibrary.cpp @@ -35,22 +35,6 @@ SharedLibrary::SharedLibrary(Builder &b, const Component &c, const vector(*component); if(bcomp.get_type()==BinaryComponent::MODULE) install_location /= package->get_name(); - else - { - const string &version = component->get_package().get_interface_version(); - if(!version.empty()) - { - const Architecture &arch = builder.get_current_arch(); - if(arch.get_system()=="windows") - soname = arch.create_filename(format("%s-%s", libname, version)); - else if(arch.get_system()=="darwin") - soname = arch.create_filename(format("%s.%s", libname, version)); - else - soname = format("%s.%s", arch.create_filename(libname), version); - - install_filename = soname; - } - } for(ObjectFile *o: objects) o->set_used_in_shared_library(true); @@ -63,8 +47,20 @@ string SharedLibrary::generate_filename(const Component &comp) return comp.get_name()+".dlm"; else { - const Architecture &arch = comp.get_package().get_builder().get_current_arch(); - return arch.create_filename(comp.get_name()); + const SourcePackage &pkg = comp.get_package(); + const Architecture &arch = pkg.get_builder().get_current_arch(); + const string &version = pkg.get_interface_version(); + if(!version.empty()) + { + if(arch.get_system()=="windows") + return arch.create_filename(format("%s-%s", comp.get_name(), version)); + else if(arch.get_system()=="darwin") + return arch.create_filename(format("%s.%s", comp.get_name(), version)); + else + return format("%s.%s", arch.create_filename(comp.get_name()), version); + } + else + return arch.create_filename(comp.get_name()); } } -- 2.45.2