[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: library search test fails, please help
From: |
John Calcote |
Subject: |
RE: library search test fails, please help |
Date: |
Mon, 23 Feb 2009 10:35:11 -0700 |
The AC_CHECK_LIB macro doesn't even attempt to call the specified function.
In fact, it merely attempts to import it as if it were a global data item in
the library. The check code boils down to something like this:
int main() {
#ifdef __cplusplus
extern "C"
#endif
char <your_function_here>;
return 0;
}
This works fine because all you're trying to do is prove that you can link
to a library with the correct symbol, and you're not including any
library-specific header file in this test program, so the compiler won't
complain that the function is not really a global data item. It will instead
assume that you're using it correctly. The linker of course doesn't care
what type of object it is, as long as the symbol exists in the library.
One good reason for doing this is that it's not necessarily a good idea to
actually call an arbitrary function from an arbitrary library (from the
perspective of a generic macro definition) because there might be harmful
side effects (a disk file gets erased...or whatever).
You could accomplish the same thing in C++ by simply trying to access the
address of the desired function from within your test main.
Regards,
John
-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of Peter
Johansson
Sent: Monday, February 23, 2009 9:02 AM
To: Alejandro Marcos Aragón
Cc: Autoconf list
Subject: Re: library search test fails, please help
Hello,
[adding autoconf list again]
Alejandro Marcos Aragón wrote:
> Well, I tried to put the namespace as well, but the test failed.
>
>
I suppose you mean that you tried
AC_SEARCH_LIBS([cpputils::flip], [cpputils],,[AC_MSG_ERROR(library cpputils
not
found)])
which would result in test code:
char cpputils::flip ();
int
main ()
{
return cpputils::flip ();
;
return 0;
}
which is not what we desired. We would like something like (I'm not
certain of your exact signature):
namespace cpputils {
void flip (double);
}
int
main ()
{
using namespace cpputils;
flip (1.0);
;
return 0;
}
You could achieve this by rather calling AC_LINK_IFELSE as below
LIBS="$LIBS -lcpputils"
AC_MSG_CHECKING([for flip in cpputils])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
namespace cpputils {
void flip(double);
}
]],
[using namespace cpputils;
flip(1.0);])
],
[AC_MSG_RESULT([yes])],
[AC_MSG_RESULT([no])
AC_MSG_ERROR([library cpputils not found])
]
)
Hope that helps.
Peter
> aa
>
> On Sun, 2009-02-22 at 23:26 -0500, Peter Johansson wrote:
>
>> aaragon wrote:
>>
>>> address@hidden:~/Lib/lib$ nm -g libcpputils.so | grep flip |
c++filt
>>> 00003c20 T cpputils::flip(double)
>>>
>>>
>>>
>> Isn't the problem that flip(double) is in namespace cpputils?
>>
>> Peter
>>
>
>
--
Peter Johansson
svndigest maintainer, http://dev.thep.lu.se/svndigest
yat maintainer, http://dev.thep.lu.se/yat
_______________________________________________
Autoconf mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/autoconf
- Re: library search test fails, please help, (continued)
- Re: library search test fails, please help, Bob Friesenhahn, 2009/02/22
- Re: library search test fails, please help, aaragon, 2009/02/22
- Re: library search test fails, please help, Allan Caffee, 2009/02/22
- Re: library search test fails, please help, Keith Marshall, 2009/02/23
Re: library search test fails, please help, Duane Ellis, 2009/02/22
Re: library search test fails, please help, Peter O'Gorman, 2009/02/22
- Re: library search test fails, please help, aaragon, 2009/02/22
- Re: library search test fails, please help, Peter Johansson, 2009/02/22
- Message not available
- Re: library search test fails, please help, Peter Johansson, 2009/02/23
- RE: library search test fails, please help,
John Calcote <=
- Re: library search test fails, please help, aaragon, 2009/02/23
- Re: library search test fails, please help, aaragon, 2009/02/23
Re: library search test fails, please help, Keith Marshall, 2009/02/23
RE: library search test fails, please help, John Calcote, 2009/02/23
RE: library search test fails, please help, aaragon, 2009/02/23
RE: library search test fails, please help, Bob Friesenhahn, 2009/02/23
RE: library search test fails, please help, John Calcote, 2009/02/23
Re: library search test fails, please help, Ralf Wildenhues, 2009/02/28