|  | 
 
| 代码如下: 6 #include <stdlib.h>
 7 #include <stdio.h>
 8 #include <iostream.h>
 9 #include <string>
 10
 11
 12 #define A_MEGABYTE (1024*1024)
 13
 14 using namespace ACE_OS;
 15
 16 int ACE_TMAIN(int argc, ACE_TCHAR* argv[])
 17 {
 18         ::printf("Hello World.\ntest program------------->\n");
 19
 20         char *some_memory;
 21         int megabyte = A_MEGABYTE;
 22         int exit_code = EXIT_FAILURE;
 23
 24         some_memory = (char *) ::malloc(megabyte);
 25         if (some_memory != NULL) {
 26                 ::sprintf(some_memory,"HELLO WORLD again haha~\n");
 27                 ::printf("%s",some_memory);
 28                 exit_code = EXIT_SUCCESS;
 29         }
 30         //ACE_DEBUG((LM_DEBUG,ACE_TEXT("NOW,ACE BEGIN ----> hello world.\nHave you see?\n")));
 31         const char * p = some_memory;
 32         ACE_OS::printf(p);
 33         std::string tmp = "teste string dsa dkh hfdks";
 34         cout <<tmp.c_str()<<endl;
 35         int nlen = ACE_OS::strlen(some_memory);
 36         cout << "nlen="<< nlen << endl;
 37         ::exit(exit_code);
 38         return 0;
 39 }
 很简单的一段.
 以前一直在win32平台下,现在跑到Linux平台做开发,一个很奇怪的问题,gcc -v:
 [...]$ gcc -v
 Reading specs from /usr/lib/gcc/x86_64-redhat-linux/3.4.6/specs
 Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=x86_64-redhat-linux
 Thread model: posix
 gcc version 3.4.6 20060404 (Red Hat 3.4.6-10)
 
 make 后的提示:
 .obj/hlwd.o(.text+0x7c): In function `main':
 /home/work/ACE/mtp4p/hlwd.cpp:32: undefined reference to `ACE_OS::printf(char const*, ...)'
 collect2: ld returned 1 exit status
 make: *** [hlwd] 错误 1
 -----------------------------------
 编译器把 const char * p 认成 char const* ,可是我觉得 const char* 和char const* 是一样的.
 我把32行的 ACE_OS去掉,就会提示:
 hlwd.cpp:32: error: call of overloaded `printf(const char*&)' is ambiguous
 /usr/include/stdio.h:329: note: candidates are: int printf(const char*, ...)
 /home/work/ACE/ACE_wrappers/ace/OS_NS_stdio.h:429: note:                 int ACE_OS::printf(const char*, ...)
 有两个 printf ,而参数类型是 : ACE_OS::printf(const char*, ...),看源码也是这样申明的,是正确的,但是为什么把前缀:ACE_OS::加上指定域后,编译器把就认成`ACE_OS::printf(char const*, ...)' ,char const *,就编译不过了.
 | 
 |