• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            mooyee's blog

            C++博客 首頁 新隨筆 聯系 聚合 管理
              3 Posts :: 2 Stories :: 1 Comments :: 0 Trackbacks
            有網友問到,他在鏈接的時候,產生一堆錯誤

            我們還是先看他的代碼吧.
            ?1//?acetest2.cpp?:?Defines?the?entry?point?for?the?console?application.
            ?2//
            ?3
            ?4//?client.cpp
            ?5
            ?6#include?"ace/OS_main.h"
            ?7#include?"ace/OS_NS_string.h"
            ?8#include?"ace/OS_NS_sys_socket.h"
            ?9#include?"ace/OS_NS_unistd.h"
            10#include?"ace/OS_NS_stdlib.h"
            11#include?"ace/OS_NS_stdio.h"
            12#include?"ace/OS_NS_netdb.h"
            13#include?"ace/Default_Constants.h"
            14
            15ACE_RCSID(SOCK_SAP,?client,?"client.cpp,v?4.10?2005/01/21?02:19:20?ossama?Exp")
            16
            17/*?BSD?socket?client?*/
            18
            19int
            20ACE_TMAIN?(int?argc,?ACE_TCHAR?*argv[])
            21{
            22??//?Initialize?WinSock?DLL?on?Win32
            23??ACE_OS::socket_init?(ACE_WSOCK_VERSION);
            24
            25??struct?sockaddr_in?saddr;
            26??struct?hostent?*hp;
            27??const?ACE_TCHAR?*host?=?argc?>?1???argv[1]?:?ACE_DEFAULT_SERVER_HOST;
            28??u_short?port_num?=
            29????htons?(argc?>?2???ACE_OS::atoi?(argv[2])?:?ACE_DEFAULT_SERVER_PORT);
            30??int?sockbufsize?=?argc?>?3???ACE_OS::atoi?(argv[3])?:?0;
            31??char?buf[BUFSIZ];
            32??ACE_HANDLE?s_handle;
            33??int?w_bytes;
            34??int?r_bytes;
            35??int?n;
            36
            37??//?Create?a?local?endpoint?of?communication.
            38??if?((s_handle?=?ACE_OS::socket?(PF_INET,?SOCK_STREAM,?0))?==?ACE_INVALID_HANDLE)
            39????ACE_OS::perror?(ACE_TEXT("socket")),?ACE_OS::exit?(1);
            40
            41??//?If?a?sockbufsize?was?specified,?set?it?for?both?send?and?receive.
            42??if?(sockbufsize?>?0)
            43??{
            44????if?(ACE_OS::setsockopt?(s_handle,?SOL_SOCKET,?SO_SNDBUF,
            45??????(const?char?*)?&sockbufsize,
            46??????sizeof?(sockbufsize))?!=?0)
            47??????ACE_OS::perror?(ACE_TEXT("SO_SNDBUF")),?ACE_OS::exit?(1);
            48????if?(ACE_OS::setsockopt?(s_handle,?SOL_SOCKET,?SO_RCVBUF,
            49??????(const?char?*)?&sockbufsize,
            50??????sizeof?(sockbufsize))?!=?0)
            51??????ACE_OS::perror?(ACE_TEXT("SO_RCVBUF")),?ACE_OS::exit?(1);
            52??}

            53
            54??//?Determine?IP?address?of?the?server.
            55??if?((hp?=?ACE_OS::gethostbyname?(ACE_TEXT_ALWAYS_CHAR(host)))?==?0)
            56????ACE_OS::perror?(ACE_TEXT("gethostbyname")),?ACE_OS::exit?(1);
            57
            58??//?Set?up?the?address?information?to?contact?the?server.
            59??ACE_OS::memset?((void?*)?&saddr,?0,?sizeof?saddr);
            60??saddr.sin_family?=?AF_INET;
            61??saddr.sin_port?=?port_num;
            62??ACE_OS::memcpy?(&saddr.sin_addr,?hp->h_addr,?hp->h_length);
            63
            64??//?Establish?connection?with?remote?server.
            65??if?(ACE_OS::connect?(s_handle,
            66????reinterpret_cast<sockaddr?*>?(&saddr),
            67????sizeof?saddr)?==?-1)
            68????ACE_OS::perror?(ACE_TEXT("connect")),?ACE_OS::exit?(1);
            69
            70??//?Send?data?to?server?(correctly?handles?"incomplete?writes"?due?to
            71??//?flow?control).
            72
            73??while?((r_bytes?=?ACE_OS::read?(ACE_STDIN,?buf,?sizeof?buf))?>?0)
            74????for?(w_bytes?=?0;?w_bytes?<?r_bytes;?w_bytes?+=?n)
            75??????if?((n?=?ACE_OS::send?(s_handle,?buf?+?w_bytes,
            76????????r_bytes?-?w_bytes))?<?0)
            77????????ACE_OS::perror?(ACE_TEXT("write")),?ACE_OS::exit?(1);
            78
            79??if?(ACE_OS::recv?(s_handle,?buf,?1)?==?1)
            80????ACE_OS::write?(ACE_STDOUT,?buf,?1);
            81
            82??//?Explicitly?close?the?connection.
            83??if?(ACE_OS::closesocket?(s_handle)?==?-1)
            84????ACE_OS::perror?(ACE_TEXT("close")),?ACE_OS::exit?(1);
            85??return?0;
            86}

            87
            88
            89

            直接編譯,產生如下錯誤
            ------?Build?started:?Project:?acetest2,?Configuration:?Debug?Win32?------

            Compiling
            acetest2.cpp
            Linking
            acetest2.obj?:?error?LNK2019:?unresolved?external?symbol?
            "__declspec(dllimport)?int?__cdecl?ace_os_main_i(class?ACE_Main_Base?&,int,char?*?*?const)"?(__imp_?ace_os_main_i@@YAHAAVACE_Main_Base@@HQAPAD@Z)?referenced?in?function?_main
            acetest2.obj?:?error?LNK2019:?unresolved?external?symbol?
            "__declspec(dllimport)?public:?__thiscall?ACE_Main_Base::ACE_Main_Base(void)"?(__imp_??0ACE_Main_Base@@QAE@XZ)?referenced?in?function?"public:?__thiscall?ACE_Main::ACE_Main(void)"?(??0ACE_Main@@QAE@XZ)
            acetest2.obj?:?error?LNK2019:?unresolved?external?symbol?
            "__declspec(dllimport)?int?__cdecl?ACE_OS::closesocket(void?*)"?(__imp_?closesocket@ACE_OS@@YAHPAX@Z)?referenced?in?function?"int?__cdecl?ace_main_i(int,char?*?*?const)"?(?ace_main_i@@YAHHQAPAD@Z)
            acetest2.obj?:?error?LNK2019:?unresolved?external?symbol?
            "__declspec(dllimport)?int?__cdecl?ACE_OS::write(void?*,void?const?*,unsigned?int)"?(__imp_?write@ACE_OS@@YAHPAXPBXI@Z)?referenced?in?function?"int?__cdecl?ace_main_i(int,char?*?*?const)"?(?ace_main_i@@YAHHQAPAD@Z)
            acetest2.obj?:?error?LNK2019:?unresolved?external?symbol?
            "__declspec(dllimport)?int?__cdecl?ACE_OS::recv(void?*,char?*,unsigned?int,int)"?(__imp_?recv@ACE_OS@@YAHPAXPADIH@Z)?referenced?in?function?"int?__cdecl?ace_main_i(int,char?*?*?const)"?(?ace_main_i@@YAHHQAPAD@Z)
            acetest2.obj?:?error?LNK2019:?unresolved?external?symbol?
            "__declspec(dllimport)?int?__cdecl?ACE_OS::send(void?*,char?const?*,unsigned?int,int)"?(__imp_?send@ACE_OS@@YAHPAXPBDIH@Z)?referenced?in?function?"int?__cdecl?ace_main_i(int,char?*?*?const)"?(?ace_main_i@@YAHHQAPAD@Z)
            acetest2.obj?:?error?LNK2019:?unresolved?external?symbol?
            "__declspec(dllimport)?int?__cdecl?ACE_OS::read(void?*,void?*,unsigned?int)"?(__imp_?read@ACE_OS@@YAHPAX0I@Z)?referenced?in?function?"int?__cdecl?ace_main_i(int,char?*?*?const)"?(?ace_main_i@@YAHHQAPAD@Z)
            acetest2.obj?:?error?LNK2019:?unresolved?external?symbol?
            "__declspec(dllimport)?int?__cdecl?ACE_OS::connect(void?*,struct?sockaddr?*,int)"?(__imp_?connect@ACE_OS@@YAHPAXPAUsockaddr@@H@Z)?referenced?in?function?"int?__cdecl?ace_main_i(int,char?*?*?const)"?(?ace_main_i@@YAHHQAPAD@Z)
            acetest2.obj?:?error?LNK2019:?unresolved?external?symbol?
            "__declspec(dllimport)?void?*?__cdecl?ACE_OS::memcpy(void?*,void?const?*,unsigned?int)"?(__imp_?memcpy@ACE_OS@@YAPAXPAXPBXI@Z)?referenced?in?function?"int?__cdecl?ace_main_i(int,char?*?*?const)"?(?ace_main_i@@YAHHQAPAD@Z)
            acetest2.obj?:?error?LNK2019:?unresolved?external?symbol?
            "__declspec(dllimport)?void?*?__cdecl?ACE_OS::memset(void?*,int,unsigned?int)"?(__imp_?memset@ACE_OS@@YAPAXPAXHI@Z)?referenced?in?function?"int?__cdecl?ace_main_i(int,char?*?*?const)"?(?ace_main_i@@YAHHQAPAD@Z)
            acetest2.obj?:?error?LNK2019:?unresolved?external?symbol?
            "__declspec(dllimport)?struct?hostent?*?__cdecl?ACE_OS::gethostbyname(char?const?*)"?(__imp_?gethostbyname@ACE_OS@@YAPAUhostent@@PBD@Z)?referenced?in?function?"int?__cdecl?ace_main_i(int,char?*?*?const)"?(?ace_main_i@@YAHHQAPAD@Z)
            acetest2.obj?:?error?LNK2019:?unresolved?external?symbol?
            "__declspec(dllimport)?int?__cdecl?ACE_OS::setsockopt(void?*,int,int,char?const?*,int)"?(__imp_?setsockopt@ACE_OS@@YAHPAXHHPBDH@Z)?referenced?in?function?"int?__cdecl?ace_main_i(int,char?*?*?const)"?(?ace_main_i@@YAHHQAPAD@Z)
            acetest2.obj?:?error?LNK2019:?unresolved?external?symbol?
            "__declspec(dllimport)?void?__cdecl?ACE_OS::exit(int)"?(__imp_?exit@ACE_OS@@YAXH@Z)?referenced?in?function?"int?__cdecl?ace_main_i(int,char?*?*?const)"?(?ace_main_i@@YAHHQAPAD@Z)
            acetest2.obj?:?error?LNK2019:?unresolved?external?symbol?
            "__declspec(dllimport)?void?__cdecl?ACE_OS::perror(char?const?*)"?(__imp_?perror@ACE_OS@@YAXPBD@Z)?referenced?in?function?"int?__cdecl?ace_main_i(int,char?*?*?const)"?(?ace_main_i@@YAHHQAPAD@Z)
            acetest2.obj?:?error?LNK2019:?unresolved?external?symbol?
            "__declspec(dllimport)?void?*?__cdecl?ACE_OS::socket(int,int,int)"?(__imp_?socket@ACE_OS@@YAPAXHHH@Z)?referenced?in?function?"int?__cdecl?ace_main_i(int,char?*?*?const)"?(?ace_main_i@@YAHHQAPAD@Z)
            acetest2.obj?:?error?LNK2019:?unresolved?external?symbol?
            "__declspec(dllimport)?int?__cdecl?ACE_OS::atoi(char?const?*)"?(__imp_?atoi@ACE_OS@@YAHPBD@Z)?referenced?in?function?"int?__cdecl?ace_main_i(int,char?*?*?const)"?(?ace_main_i@@YAHHQAPAD@Z)
            acetest2.obj?:?error?LNK2019:?unresolved?external?symbol?
            "__declspec(dllimport)?int?__cdecl?ACE_OS::socket_init(int,int)"?(__imp_?socket_init@ACE_OS@@YAHHH@Z)?referenced?in?function?"int?__cdecl?ace_main_i(int,char?*?*?const)"?(?ace_main_i@@YAHHQAPAD@Z)
            Debug
            /acetest2.exe?:?fatal?error?LNK1120:?17?unresolved?externals

            解決方法,是正確的鏈接ace(x).lib
            其中, release版對應的是ace.lib,debug對應的是aced.lib
            同時,還要確保編輯器能正確找到ace(x).lib的位置.

            簡單的辦法是加入下面的代碼
            #ifdef?_DEBUG
            #pragma??comment?(lib,
            "aced.lib")
            #else
            #pragma??comment?(lib,
            "ace.lib")
            #endif


            ?

            posted on 2006-03-29 09:49 stone 閱讀(2763) 評論(0)  編輯 收藏 引用 所屬分類: 網絡編程, ACE
            99精品国产99久久久久久97 | 亚洲中文字幕久久精品无码APP | 午夜精品久久久久久影视777 | 热re99久久精品国99热| 精品久久久无码21p发布| 人妻无码αv中文字幕久久琪琪布| 色综合久久久久久久久五月| 国产精品久久永久免费| 精品久久人人做人人爽综合| 亚洲精品午夜国产VA久久成人| 久久99精品国产麻豆| 四虎久久影院| 久久这里只有精品首页| 久久精品极品盛宴观看| 青青青青久久精品国产h| 久久精品国产免费观看三人同眠| 久久w5ww成w人免费| 亚洲国产天堂久久久久久| 国产精品美女久久久m| 伊人久久亚洲综合影院| 久久91亚洲人成电影网站| 无码人妻久久一区二区三区免费| 国产精品成人久久久久久久| 日产精品99久久久久久| 久久久久久久久66精品片| 久久99精品九九九久久婷婷| 99久久综合狠狠综合久久止| 久久无码国产专区精品| 欧美一级久久久久久久大| 精品国产91久久久久久久| 久久精品一本到99热免费| yy6080久久| 久久久午夜精品福利内容| 久久久久国产一区二区| 亚洲综合精品香蕉久久网97 | 国产精品一区二区久久精品无码| 久久不见久久见免费视频7| 久久亚洲私人国产精品| 亚洲级αV无码毛片久久精品| 亚洲伊人久久综合中文成人网| 久久国产高清一区二区三区|