最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

gcc - Using a shared library within static library used by 2nd shared library and other applications, Linux tools - Stack Overfl

programmeradmin1浏览0评论

Basic question: Can one specify, when building a static library (and ONLY when building the static library), that the static library needs to link with a shared object?

I'm working on a project that looks like this:

  • StaticLib
  • Application1 - links with StaticLib
  • SharedObject - links with StaticLib
  • Application2 - links with SharedObject

I only own StaticLib.

I'd like to add a dependency on a 3rd party SharedObject to the StaticLib. I know that the 3rd party SO exists on all the machines that my software is going to run on, which is good because I'm also restricted by licensing from distributing that 3rd party SO in anyway.

Just playing around, I can get it to work so long as I tell the linker at every application level that I need to link with the 3rd party SO. The problem is twofold: I don't own the build process for those applications AND I'm actually simplifying and there are a lot of applications and SOs that use my static library, some of which are completely outside of my and I don't know what they are.

As I said, I'm restricted by licensing from distributing the 3rd party SO, so the solutions I've seen that talk about how to fold the SO into a static library won't work for me; that would be distributing the 3rd party SO and I'm legally blocked from doing that.

Is there any way to make this work?

As a follow up, MOST of the uses of my static library will be via SharedObject. If there's a way to make this work such that I must modify the build process for the handful of applications that directly use StaticLibrary and and modify the build of SharedObject, but not have to modify the build of applications that use SharedObject, that'd be workable.

Basic question: Can one specify, when building a static library (and ONLY when building the static library), that the static library needs to link with a shared object?

I'm working on a project that looks like this:

  • StaticLib
  • Application1 - links with StaticLib
  • SharedObject - links with StaticLib
  • Application2 - links with SharedObject

I only own StaticLib.

I'd like to add a dependency on a 3rd party SharedObject to the StaticLib. I know that the 3rd party SO exists on all the machines that my software is going to run on, which is good because I'm also restricted by licensing from distributing that 3rd party SO in anyway.

Just playing around, I can get it to work so long as I tell the linker at every application level that I need to link with the 3rd party SO. The problem is twofold: I don't own the build process for those applications AND I'm actually simplifying and there are a lot of applications and SOs that use my static library, some of which are completely outside of my and I don't know what they are.

As I said, I'm restricted by licensing from distributing the 3rd party SO, so the solutions I've seen that talk about how to fold the SO into a static library won't work for me; that would be distributing the 3rd party SO and I'm legally blocked from doing that.

Is there any way to make this work?

As a follow up, MOST of the uses of my static library will be via SharedObject. If there's a way to make this work such that I must modify the build process for the handful of applications that directly use StaticLibrary and and modify the build of SharedObject, but not have to modify the build of applications that use SharedObject, that'd be workable.

Share edited Feb 12 at 14:31 Mike Kinghan 61.6k15 gold badges168 silver badges201 bronze badges asked Feb 10 at 19:19 Tim WilliamsTim Williams 134 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

A static library as input to the GNU linker is a simple archive of object files from which the linker will copy and statically link into the output image exactly those object files, if any, that provide the linkage with definitions for symbols that are already referred to in the linkage but so far lack definitions.

A static library contributes nothing whatsoever to the linkage but the 0 or more object files that are extracted from it.

So your question boils down to: Is there a way in which gcc can compile an object file that when input to a linkage will instruct the linker to find a specified shared libary and input it to the linkage?

There isn't.

High-level build system generators (autotools, cmake, meson, buck, etc.) will enable you to specify somehow that when a library A is in the linkage of a build target then so will be libraries B, C ..., in that order. The details vary. You might distribute such a build system.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论
ok 不同模板 switch ($forum['model']) { /*case '0': include _include(APP_PATH . 'view/htm/read.htm'); break;*/ default: include _include(theme_load('read', $fid)); break; } } break; case '10': // 主题外链 / thread external link http_location(htmlspecialchars_decode(trim($thread['description']))); break; case '11': // 单页 / single page $attachlist = array(); $imagelist = array(); $thread['filelist'] = array(); $threadlist = NULL; $thread['files'] > 0 and list($attachlist, $imagelist, $thread['filelist']) = well_attach_find_by_tid($tid); $data = data_read_cache($tid); empty($data) and message(-1, lang('data_malformation')); $tidlist = $forum['threads'] ? page_find_by_fid($fid, $page, $pagesize) : NULL; if ($tidlist) { $tidarr = arrlist_values($tidlist, 'tid'); $threadlist = well_thread_find($tidarr, $pagesize); // 按之前tidlist排序 $threadlist = array2_sort_key($threadlist, $tidlist, 'tid'); } $allowpost = forum_access_user($fid, $gid, 'allowpost'); $allowupdate = forum_access_mod($fid, $gid, 'allowupdate'); $allowdelete = forum_access_mod($fid, $gid, 'allowdelete'); $access = array('allowpost' => $allowpost, 'allowupdate' => $allowupdate, 'allowdelete' => $allowdelete); $header['title'] = $thread['subject']; $header['mobile_link'] = $thread['url']; $header['keywords'] = $thread['keyword'] ? $thread['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>