如何在 Windows 上安装 C 软件包
我必须使用 LU 分解来将简单模型拟合到 C 中的某些数据(模拟)。我需要做的一个示例是 此处:
但是,我遇到了一个更基本的问题:如何在 C 中安装包并在代码中调用它们?
我是 C 新手,我习惯了 R。但是我有这个任务来做一些关于矩阵求逆、LU 分解的测试,教授建议使用 Lapack 来完成简单的事情(因此,我不需要自己编写代码LU分解等)。但我不知道如何安装该包并在我的代码中调用它,以便使用LAPACK的功能。
我有一个 Windows 7 64 位,我正在使用编译器代码块 8.02
感谢您的帮助。
I have to use LU decompostion to fit a simple model to some data (simulated) in C. An example of what I need to do is here:
However, I'm stuck with a more basic problem: how do I install packages in C and call them in my code?
I'm new in C and I'm used to R. But I have this assingment to do some tests about Matrix inversion, LU decomposision and the professor suggested using Lapack to easy things (thus, I don't need to code myself the LU decomposition etc.). But I don't know how to install the package and call it in my code, in order to use the functions of LAPACK.
I have a windows 7 64 bits and I'm using compiler Code Blocks 8.02
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通常,您不会从这个意义上“安装”C 库。通常,在 Windows 中,您有三种类型的文件。头文件(通常以 .h 结尾)、动态库、.dll,很可能还有一些链接器文件(通常为 .lib、.a 或其他文件)。链接器和编译器需要能够在某处找到这些文件。通常,您设置包含目录路径和库目录路径。
例如,假设您下载了一个名为 foo 的库,并将其解压到 C:\foo。
该文件夹中包含
libfoo.a
、foo.dll
和foo.h
。在 Code::Blocks 中,您必须将包含目录路径指向C:\foo
并将库路径指向C:\foo
,以便链接器和编译器知道在哪里查找对于这些文件。由于您要链接 foo 库,因此您还必须在链接器命令行中设置-lfoo
或类似的内容。这是 GCC 语法,但我认为 Code::Blocks 无论如何在幕后使用 GCC 编译器。在 C 代码中,您只需
#include
,编译器就会为您找到它。Normally you don't "install" C libraries in that sense. Normally, in Windows you have three types of files. The header files, typically ending in .h, the dynamic library, .dll, and most likely some linker files (typically, .lib, .a or something). The linker and compiler will need to be able to find these files somewhere. Normally you set the include directory paths, and library directory paths.
E.g. Let's say you downloaded a library called foo, and you extract it to C:\foo.
In that folder,
libfoo.a
,foo.dll
andfoo.h
reside. In Code::Blocks you will have to point include directory path toC:\foo
and library path toC:\foo
so that the linker and compiler know where to look for these files. Since you're linking against the foo library, you will also have to set-lfoo
or something similiar in linker command line. This is GCC syntax, but I think Code::Blocks uses GCC compiler behind the scenes anyways.In the C code you can just
#include <foo.h>
and the compiler will find it for you.您需要安装该库,它实际上可能为此提供一个工具。检查他们的文档(例如,其分布式源中的文件
INSTALL
或README
)。如果库仅使用标头,您可能只需要将其标头复制到系统上的某个目录,但他们的构建系统可能能够为您做到这一点。完成此操作后,您将告诉 IDE 在哪里查找源代码以及库是否仅使用标头来链接实际的库文件。请参阅 Code::Blocks Wiki 中的文档了解如何执行此操作针对一些示例案例完成并适应您的库。
You need to install that library and it might actually supply a tool for that. Check their documentation (e.g. a file
INSTALL
orREADME
in their distributed sources). If the library uses only headers you might only need to copy it's headers to some directory on your system, but their buildsystem might be able to do that for you.Once that is done you would tell your IDE on where to look for the sources and if the library uses not just headers to link against the actual library file. See the documentation in the Code::Blocks Wiki on how this is done for some example cases and adapt for your library.
根据您的情况,最简单的方法是安装 Cygwin。您可以使用 setup.exe 安装程序来安装 GCC 和 LAPACK 库。当您想要使用 LAPACK 库时,您需要将 -llapack 选项添加到 GCC 命令行中。
The simplest thing to do in your situation is to install Cygwin. You can use the setup.exe installer to install the GCC and the LAPACK libraries. When you want to use the LAPACK library, you will add the -llapack option to your GCC command line.