I have a .cpp
file: htonstest.cpp
. I use g++
to compile it:
$ g++ -o test htonstest.cpp
It works, and the program ./test
works too.
But, when I use automake to compile it, has a compile error:
htonstest.cpp: In function ‘int main()’:
htonstest.cpp:6: error:expected id-expression before ‘(’ token.
My OS is CentOS, gcc's version is 4.1.2 20080704, autoconf's version is 2.59, automake's version is 1.9.6.
To reproduce:
$ aclocal
$ autoheader
$ autoconf
$ automake -a
$ ./configure
$ make
ntohstest.cpp:
#include <netinet/in.h>
#include <iostream>
int main()
{
short a = ::ntohs(3);
std::cout << a << std::endl;
std::cin.get();
return 0;
}
configure.ac:
AC_PREREQ(2.59)
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_CONFIG_SRCDIR([htonstest.cpp])
AC_CONFIG_HEADER([config.h])
AM_INIT_AUTOMAKE([foreign])
# Checks for programs.
AC_PROG_CXX
# Checks for libraries.
# Checks for header files.
# AC_CHECK_HEADERS([netinet/in.h])
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CONFIG_FILES(Makefile)
AC_OUTPUT
Makefile.am:
bin_PROGRAMS=main
main_SOURCES=htonstest.cpp
using namespace std;
– Taiwan::ntohs
? – Planogamete::
. It just introduces portability issues, like this one. Whoever used it first and told their friends to do the same needs a slap in the face. – Planogamete