在Windows -R和-rpath交换机链接 [英] Linking with -R and -rpath switches on Windows

查看:658
本文介绍了在Windows -R和-rpath交换机链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I,M用gcc编译器(MinGW的)在Windows XP.I生成的DLL库 libdir.dll 比我试图建立一个使用该库的程序。结果
我不想把这些.dll文件系统或System32文件夹中,也不路径PATH变量设置为它,我想要的就是给这些信息的程序本身。结果
我知道有一个 -R -rpath 切换可用的,所以我跟他们中的一个会链接它。

I,m using gcc compiler(MinGW) on Windows XP.I created a .dll library libdir.dll than I tried to build a program that is using that library.
I don't want to put that .dll file into System or System32 folder nor to set path to it in PATH variable, what i want is to give that information to the program itself.
I know there is a -R and -rpath switches available so i was gonna link it with one of them.

首先-rpath:结果
  的gcc -L /路径/要/ lib中的 -Wl,-rpath, /路径/要/ lib中的 main.o中-Ldir -o PROG

First -rpath:
gcc -L/path/to/lib -Wl,-rpath,/path/to/lib main.o -ldir -o prog

比-R:结果
  的gcc -L /路径/要/ lib中的 -Wl,-R, /路径/要/ lib中的 main.o中-Ldir -o PROG

Than -R:
gcc -L/path/to/lib -Wl,-R,/path/to/lib main.o -ldir -o prog

这成功链接到 PROG 但是当我启动程序的Windows打印的消息,它无法找到 libdir.dll 。结果
所以我的问题是什么地方出了错,甚至当我使用适当的开关为何路径 libdir.dll 不是在运行时知道的?

This links successfully into prog but when i start the program Windows prints message that it cannot find libdir.dll.
So my question is what went wrong, why path to libdir.dll is not known in runtime even when I'm using appropriate switches?

让我们说我有PROG1和PROG2每个都包含自己的libdir.dll的副本,他们都开始在该library.What同时装载code运行在内存中的情况是有两个副本加载或连接器计算出有一个副本,并使用这两个程序?结果
第二个问题是关于图书馆如何加载(任何操作系统).Does链接器总是加载整个存储库或者只需要部分?例如,如果程序引用函数富()这是在图书馆,做链接映射到内存中只有函数或整个库首?

Let's say i have prog1 and prog2 each containing their own copy of libdir.dll and both of them start to run at the same time loading code in the library.What happens in memory is there a two copies loaded or linker figures out that there is a copy and uses that for both programs?
Second question is about how libraries are loaded(any OS).Does linkers always load entire library or just parts needed?For example if program references function foo() which is in the library, does linker maps into memory only that function or entire library first?

推荐答案

有只有两个真正的选择:把DLL在同一文件夹中的EXE或把它在为EXE的工作目录。后者是没有太多的选择,因为你必须创建一个快捷方式,使其从包含EXE的目录默认工作目录不同。

There are only two real alternatives: put the DLL in the same folder as the EXE or put it in the working directory for the EXE. The latter being not much of an option since you'd have to create a shortcut to make the default working directory different from the directory that contains the EXE.

不把DLL在同一目录下,如果你想分享与其他应用程序的DLL中的EXE才有意义。为了避免不可避免的DLL地狱这会导致,你需要的DLL存储在并排端缓存。该工具你需要创建清单,并在EXE嵌入它,你就需要部署DLL到目标机安装程序可能很难与你的工具链来用。这是很少反正做。

Not putting the DLL in the same directory as the EXE only makes sense if you want to share the DLL with other applications. To avoid the inevitable DLL hell this causes, you'd need to store the DLL in the side-by-side cache. The tooling you need to create the manifest and embed it in the EXE and the installer you'd need to deploy the DLL to the target machine are probably hard to come by with your tool chain. It is very rarely done anyway.

这篇关于在Windows -R和-rpath交换机链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆