【发布时间】:2013-01-04 02:27:45
【问题描述】:
我有一个.cpp 文件:htonstest.cpp。我使用g++ 编译它:
$ g++ -o test htonstest.cpp
它有效,程序./test 也有效。
但是,当我使用automake编译时,出现编译错误:
htonstest.cpp: In function ‘int main()’:
htonstest.cpp:6: error:expected id-expression before ‘(’ token.
我的操作系统是CentOS,gcc的版本是4.1.2 20080704,autoconf的版本是2.59,automake的版本是1.9.6。
复制:
$ 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;
}
配置.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; -
@JohnTortugo:不错的猜测,但没有。
-
什么资源告诉你使用
::ntohs? -
zh,好问题,我也不知道。我认为只有一个原因:(旧代码):-)。
-
@LightnessRacesinOrbit :这是从 Windows 移植的一些代码,而不仅仅是一些“旧代码”。据我所知,"::ntohs" 在 Windows 中是正确的。
标签: c++ linux autoconf automake