DLL(DEF,LIB等)的C ++链接器选项 [英] C++ linker options for DLL (DEF, LIB, etc)

查看:245
本文介绍了DLL(DEF,LIB等)的C ++链接器选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了编写可解压RAR文件的程序,我下载了一个库。 ( http://www.rarlab.com/rar/UnRARDLL.exe )这个为我提供unrar.dll , unrar.h ,unrar.lib 和 UnRDLL.def 。我已经复制了C示例代码,并尝试使用Dev-Cpp和Eclipse进行编译。

I have downloaded a library for the purposes of writing a program that can uncompress a RAR file. (http://www.rarlab.com/rar/UnRARDLL.exe) This supplies me with unrar.dll, unrar.h, unrar.lib and UnRDLL.def. I have copied the C example code and have tried compiling it with both Dev-Cpp and Eclipse.

我没有使用DLL的经验,所以我不知道如何处理以下链接器错误:

I don't have much experience using DLLs, so I don't know how to deal with the following linker errors:


UnRDLL.o(.text + 0x151):UnRDLL.c:未定义的引用 RAROpenArchiveEx @ 4'
UnRDLL.o(.text + 0x1c0):UnRDLL.c:未定义引用
RARSetCallback @ 12'
UnRDLL.o(.text + 0x1e2):UnRDLL.c:未定义引用 RARReadHeader @ 8'
UnRDLL.o(.text + 0x2b9):UnRDLL.c:未定义的引用
RARProcessFile @ 16'
UnRDLL.o(.text + 0x2fe):UnRDLL。 c:未定义引用 RARCloseArchive @ 4'
UnRDLL.o(.text + 0x366):UnRDLL.c:未定义引用
RAROpenArchiveEx @ 4'
UnRDLL.o(.text + 0x3d6):UnRDLL.c:未定义的引用 RARSetCallback @ 12'
UnRDLL.o(.text + 0x41c):UnRDLL.c:未定义引用
RARReadHeaderEx @ 8'
UnRDLL.o(.text + 0x4c2):UnRDLL.c:未定义的引用 RARProcessFile @ 16'
UnRDLL.o(。 text + 0x4fa):UnRDLL.c:und精心引用
RARCloseArchive @ 4'

UnRDLL.o(.text+0x151):UnRDLL.c: undefined reference to RAROpenArchiveEx@4' UnRDLL.o(.text+0x1c0):UnRDLL.c: undefined reference toRARSetCallback@12' UnRDLL.o(.text+0x1e2):UnRDLL.c: undefined reference to RARReadHeader@8' UnRDLL.o(.text+0x2b9):UnRDLL.c: undefined reference toRARProcessFile@16' UnRDLL.o(.text+0x2fe):UnRDLL.c: undefined reference to RARCloseArchive@4' UnRDLL.o(.text+0x366):UnRDLL.c: undefined reference toRAROpenArchiveEx@4' UnRDLL.o(.text+0x3d6):UnRDLL.c: undefined reference to RARSetCallback@12' UnRDLL.o(.text+0x41c):UnRDLL.c: undefined reference toRARReadHeaderEx@8' UnRDLL.o(.text+0x4c2):UnRDLL.c: undefined reference to RARProcessFile@16' UnRDLL.o(.text+0x4fa):UnRDLL.c: undefined reference toRARCloseArchive@4'

Google建议添加 - def UnRDLL.def -lunrar 到链接器选项,并将.lib文件复制到Dev-Cpp \lib目录。你可以向我解释一下我在做错什么吗?

Google suggested adding --def UnRDLL.def and -lunrar to the linker options and also copying the .lib file to the Dev-Cpp\lib directory.

如果可能,请告诉我在源代码目录中需要哪些文件,库中需要什么,需要添加到项目中以及需要哪些链接器选项,以及我完全错过的任何其他内容。

Can you please explain to me what I'm doing wrong? If possible, tell me what files need to be in the source code directory, what needs to be with libraries, what needs to be added to the project and what linker options there need to be, as well as anything else I've totally missed.

编辑:我不知道为什么,但是我只是手动地重新编辑所有的设置,如上所述,现在它的工作原理。感谢您的帮助。

推荐答案

我建议使用 Visual Studio Express (从Microsoft提供的链接免费提供)来编译和链接您的程序。我认为这比你提到的其他工具要简单得多,虽然这只是我个人的意见。

I recommend using Visual Studio Express (freely available from Microsoft at the provided link) to compile and link your program. I think it's a bit simpler in this instance than the other tools that you mentioned, although that's just my personal opinion.

我建议使用类似于你的项目的布局:

I recommend using a layout similar to this for your project:


\myproject
  \src
  \include
\thirdparty
  \bin
  \lib
  \include

您的C / C ++源文件将生活在 myproject\src ,您的头文件将生活在 myproject\include 之下。您下载的图书馆文件现在位于 thirdparty 下:该DLL属于 bin 。 lib 文件和 .def 文件属于 lib ,库的头文件属于包含

Your C/C++ source files will live under myproject\src and your header files will live under myproject\include. The library files that you downloaded live under thirdparty: the DLL belongs in bin, the .lib file and .def file belong in lib, and the library's header files belong in include.

接下来,您需要在Visual Studio Express中配置项目。在项目属性中,在链接器 - >常规下,将 \thirdparty\lib 添加到其他库目录。在链接器 - >输入下,将 unrar.lib 添加到附加依赖关系。这告诉Visual Studio Express您的第三方库的名称和位置,以便它可以将其链接到您的主要应用程序。

Next, you need to configure your project in Visual Studio Express. In your project properties, under Linker -> General, add \thirdparty\lib to Additional Library Directories. Under Linker -> Input, add unrar.lib to Additional Dependencies. This tells Visual Studio Express the name and location of your thirdparty library, so that it can link it into your main application.

运行程序时,您需要将 unrar.dll 复制到项目的输出目录,以便您的程序可以加载它。

When running your program, you'll need to copy unrar.dll to your project's output directory so your program can load it.

这应该可以帮助您去...

This should help you to get going...

这篇关于DLL(DEF,LIB等)的C ++链接器选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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