强制静态链接链接到

强制静态链接链接到

本文介绍了强制静态链接链接到 Xcode 目标的库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Xcode 目标链接到 hdf5 库(使用 Link Binary with Libraries 构建阶段).libhdf5 是使用 MacPorts 安装的,因此/opt/local/lib 包含库的动态 (.dylib) 和静态 (.a) 版本.

My Xcode target links against hdf5 library (using the Link Binary with Libraries build phase). libhdf5 is installed using MacPorts, thus /opt/local/lib contains both the dynamic (.dylib) and static (.a) versions of the library.

构建的文本输出显示,正如预期的那样,在构建的链接步骤中有一个 -lhdf5.然而,gcc 似乎采用了动态链接库而不是静态链接库.有什么方法可以强制 gcc(通过编译器开关或通过 Xcode)与 libhdf5.a 静态链接?

The text output from the build shows that there is, as expected, a -lhdf5 in the linking step of the build. gcc seems to take the dynamic linked library over the static, however. Is there any way to force gcc (via a compiler switch or via Xcode) to statically link with libhdf5.a?

我找到的唯一解决方案是将 libhdf5.a 复制到项目(或其他)目录并链接到该副本,从而避免在同一位置拥有动态和静态版本.

The only solution I've found is to copy libhdf5.a to the project (or other) directory and link against that copy, thus avoiding having dynamic and static versions in the same location.

推荐答案

回应您对 Eduard Wirch 回答的评论:如果您将 -lhdf5 替换为 -l/full,您也可以仅控制这个库的静态链接/path/to/libhdf5.a

In reaction to your comment on Eduard Wirch' answer: you can also control static linking for this one library only, if you replace -lhdf5 by -l/full/path/to/libhdf5.a

这篇关于强制静态链接链接到 Xcode 目标的库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 07:18