如何在configure.in中测试C ++库的可用性? [英] How to test a C++ library usability in configure.in?
问题描述
我正在GNU/Linux上的C ++项目上工作,我正在寻找一种方法来使用Autotools测试IBM Informix库的存在和可用性-即编辑configure.in
.我没有使用Autotools的经验,因此基本上我是从项目的configure.in
等人脚本中学习的,并复制和更改需要更改的位置. 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
来测试某个库是否既存在又可用.但这似乎只适用于具有 function 功能的库,而不适用于类.即,这在测试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
"command"可以用于这种特定用途.
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
.
因此,您需要在库中找到方法的错误名称.您可以通过在类似Unix的操作系统上使用 nm
命令来做到这一点:
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.
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()
有关更多信息,请参见Wikipedia上的使用C ++的名称处理.
See Name Mangling in C++ on Wikipedia for more information.
这篇关于如何在configure.in中测试C ++库的可用性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!