如何在 configure.in 中测试 C++ 库的可用性? [英] How to test a C++ library usability in configure.in?

查看:49
本文介绍了如何在 configure.in 中测试 C++ 库的可用性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 GNU/Linux 上从事 C++ 项目,我正在寻找一种方法来使用 Autotools 测试 IBM Informix 库的存在性和可用性 - 即,编辑 configure.in.我没有使用 Autotools 的经验,所以基本上我是从项目的 configure.in et al. 脚本中获取并复制和更改我觉得需要的地方改变了.IOW,我一直在改编 configure.in 中的现有文本.

I'm working on a C++ project on GNU/Linux and I'm looking for a way to test the existence and usability of IBM Informix's library with the Autotools - namely, editing a configure.in. I don't have experience with Autotools, so basically I'm picking up from the project's configure.in et al. scripts and copying&changing where I feel needs to be changed. IOW, I've been adapting from the existing text in configure.in.

到目前为止,我已经成功地使用了 configure.in 中的 AC_CHECK_LIB 来测试某个库是否存在并且可用.但这似乎只适用于具有函数的库,而不适用于例如类.即,在测试 Informix 的 libifc++.so 库时失败:

So far I've been using successfully the AC_CHECK_LIB in configure.in to test whether a certain library both exists and is usable. But this only seems to work with libraries with functions, not e.g. classes. Namely, this fails when testing Informix's libifc++.so library:

AC_CHECK_LIB(ifc++, ITString, 
        INFORMIX_LIB="-L$INFORMIX_LIB_LOCATION/c++ -lifc++ -L$INFORMIX_LIB_LOCATION -L$INFORMIX_LIB_LOCATION/dmi -L$INFORMIX_LIB_LOCATION/esql -lifdmi -lifsql -lifasf -lifgen -lifos -lifgls -lifglx $INFORMIX_LIB_LOCATION/esql/checkapi.o -lm -ldl -lcrypt -lnsl",
        echo "* WARNING: libifc++.so not found!"
        INFORMIX_INC=""
        INFORMIX_LIB=""
)

我也尝试过使用其他组合,例如 ITString::ITString

I've also tried using other combinations, like ITString::ITString, etc.

我还没有在 Informix 的 API 中找到纯"函数(即没有在 C++ 类中上下文的函数).所以我希望有一种方法可以在这种情况下使用 AC_CHECK_LIB,或者还有另一个 autoconf/configure.in命令"用于这个特定的用途.

I haven't found a "pure" function in Informix's API (i.e., one that isn't contexted in a C++ class). So I'm hoping that either there's a way to use AC_CHECK_LIB in this context, or there's another autoconf/configure.in "command" for this specific use.

提前感谢您的反馈.

推荐答案

可能有一种更简洁的方法来实现这一点,但我认为您的问题是 C++ 方法被破坏"以允许有关该方法的附加信息(参数 & 返回类型等)进行编码.例如;方法 int A::foo(void) 将被修改为类似 __ZN1A3fooEv 的东西.

There might be a cleaner way of achieving this, but I think your problem is that C++ methods get "mangled" to allow additional information about the method (argument & return types etc) to be encoded. For example; the method int A::foo(void) will get mangled to something like __ZN1A3fooEv.

所以你需要在库中找到一个方法的重整名称.您可以通过使用 nm 命令来做到这一点类 Unix 操作系统:

So you need to find the mangled name of a method in the library. You can do this by using the nm command on Unix-like OSs:

$ nm libifc++.so | grep ITString

值得一提的是,确切的重整格式因不同的编译器而异;因此,通过在您的 configure.in 中嵌入某个编译器的损坏符号,它可能无法在其他平台上运行 - YMMV.

It's worth mentioning that the exact mangling format varies across different compilers; and so by embedding a certain compiler's mangled symbol in your configure.in it may not work on other platforms - YMMV.

注意:您可以使用 c++filt 实用程序,用于将名称分解回人类可读的形式;所以对于我之前给出的例子:

Note: you can use the c++filt utility to demangle a name back to it's human-readable form; so for the example I gave previously:

$ c++filt __ZN1A3fooEv
A::foo()

请参阅维基百科上的C++ 中的名称修改,了解更多信息.

See Name Mangling in C++ on Wikipedia for more information.

这篇关于如何在 configure.in 中测试 C++ 库的可用性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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