ansi C 程序中的直方图函数:GSL 和/或其他?
如果我只想使用 Gnu Scientific Library (GSL) 中的 gsl_histogram.h
库,我可以将其从已安装 GSL 的现有计算机 (Mac OS Snow Leopard) 复制到另一台计算机 (Linux CentOS 5.7)没有安装 GSL,只是在我的 c 程序中使用 #include
语句?这行得通吗?
或者,即使我只需要这一个库,我是否必须在 Linux 机器上完整安装 GSL?
If I just want to use the gsl_histogram.h
library from Gnu Scientific Library (GSL), can I copy it from an existing machine (Mac OS Snow Leopard) that has GSL installed to a different machine (Linux CentOS 5.7) that doesn't have GSL installed, and just use an #include <gls_histogram.h>
statement in my c program? Would this work?
Or, do I have to go through the full install of GSL on the Linux box, even though I only need this one library?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅复制标头
gsl_histogram.h
是不够的。标头仅说明该库公开的接口。您还需要复制*.so
和*.a
文件等二进制文件,但很难判断要复制哪些文件。所以我认为你最好把它安装在你的机器上。这很简单,只需使用这个教程查找并安装 GSL 包。所以肯定有很多图书馆。但最特别的一个是 Gnuplot。使用它你甚至不需要编译代码,但是你确实需要阅读一些文档。但幸运的是,Stackoverflow 上已经有一个关于如何使用 Gnuplot 绘制直方图的问题: Histogram using gnuplot?值得注意的是,Gnuplot 实际上是非常强大的工具,因此投入时间阅读其文档肯定会有回报。
Just copying a header
gsl_histogram.h
is not enough. Header states merely the interface that is exposed by this library. You would need to copy also binaries like*.so
and*.a
files, but it's hard to tell which ones to copy. So I think the you'd better just install it on your machine. It's pretty easy, just use this tutorial to find and install GSL package.So there are surely a lot of libraries out there. However the particular one is Gnuplot. Using it you even do not need to compile the code, however you do need to read a bit of documentation. But luckily there is already a question about how to draw a histogram with Gnuplot on Stackoverflow: Histogram using gnuplot? It worth noting that Gnuplot is actually very powerful tool, so invested time into reading its documentation will certainly pay off.
您不能从操作系统复制库并期望它们不变地工作。
OS X 使用 Mach-O 对象文件格式,而现代 Linux 系统则使用 ELF 目标文件格式。通常的 ld.so(8) 链接器/加载器将不知道如何加载 Mach-O 格式的目标文件以供可执行文件执行。因此,您需要 Apple 提供的
ld.so(8)
——或者他们所谓的加载程序。 (已经有一段时间了。)此外,OS X 中的目标文件将与 Apple 提供的
libc
链接,并且需要 Apple 提供的库中的相应符号。您还需要在 Linux 系统上提供 Apple 提供的libc
。该 C 库将尝试使用 OS X 系统调用号和调用约定进行系统调用。我保证系统调用号已经改变,并且几乎可以肯定调用约定是不同的。Linux 内核的
binfmt_misc
通用对象加载器可用于教导内核如何加载不同的对象文件格式,而内核的personality(2)
系统调用可用于指导内核如何加载不同的对象文件格式。在不同的调用约定、系统调用号等之间进行选择,完成这项工作所需的工作量是巨大的:WINE 项目 一直致力于解决这个问题(但使用 Windows 格式 COFF 和支持库) )自 1993 年起。运行起来会更容易:
或者您选择的发行版上的任何等效项。如果您的发行版无法轻松使用该库,那么手动编译和安装该库仍然比尝试使 OS X 版本工作更容易。
You cannot copy libraries from OS and expect them to work unchanged.
OS X uses the Mach-O object file format while modern Linux systems use the ELF object file format. The usual
ld.so(8)
linker/loader will not know how to load the Mach-O format object files for your executable to execute. So you would need the Apple-providedld.so(8)
-- or whatever they call their loader. (It's been a while.)Furthermore, the object files from OS X will be linked against the Apple-supplied
libc
, and require the corresponding symbols from the Apple-supplied library. You would also need to provide the Apple-providedlibc
on the Linux system. This C library would try to make system calls using the OS X system call numbers and calling conventions. I guarantee the system call numbers have changed and almost certainly calling conventions are different.While the Linux kernel's
binfmt_misc
generic object loader can be used to teach the kernel how to load different object file formats, and the kernel'spersonality(2)
system call can be used to select between different calling conventions, system call numbers, and so on, the amount of work required to make this work is nothing short of immense: the WINE Project has been working on exactly this issue (but with the Windows format COFF and supporting libraries) since 1993.It would be easier to run:
or whatever the equivalent is on your distribution of choice. If your distribution does not make it easily available, it would still be easier to compile and install the library by hand rather than try to make the OS X version work.