CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Mar 2005
    Posts
    11

    fatal error LNK1120: 2 unresolved externals

    hi i m new in vc++ enviroment i have an problem arrived
    i have a code of udpdump which capture a packet from network and show but it is in dot c extension class i have rewrite this code in vc soo i made object of class udpdump and use in my another program
    but it had 2 error when i make a header files and source file for this class can anyone help me i required a urgent response

    the error which occur when i compile the code r

    1-- UdpDum1.obj : error LNK2001: unresolved external symbol "struct pcap * __cdecl pcap_open(char const *,int,int,int,struct pcap_rmtauth *,char *)" (?pcap_open@@YAPAUpcap@@PBDHHHPAUpcap_rmtauth@@PAD@Z)

    2--UdpDum1.obj : error LNK2001: unresolved external symbol "int __cdecl pcap_findalldevs_ex(char *,struct pcap_rmtauth *,struct pcap_if * *,char *)" (?pcap_findalldevs_ex@@YAHPADPAUpcap_rmtauth@@PAPAUpcap_if@@0@Z)

    3--Debug/TestPacketCapturing.exe : fatal error LNK1120: 2 unresolved externals

    will any body tell me the reason and solution of that error ???

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: fatal error LNK1120: 2 unresolved externals

    Those are not compiler errors, those are linker errors.

    Simply, the linker is trying to find these functions ( pcap_open, pcap_findalldevs_ex) and the linker can't find them.

    1) Where are these functions located? Are they in another library? If so, you need to add the library to your project.

    2) Are these functions in another source file? If so, you need to add those source files to your project.

    3) Are these 'C' functions and not C++ functions? If so, then you need to change the declaration of the functions to "extern 'C'", since the C++ compiler has mangled the names of the functions to different names in the object file, and the linker is looking for the mangled name instead of the straight 'C' name of the function.

    So you have three things to check, and the problem is one or more of the above.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; August 9th, 2005 at 05:44 AM.

  3. #3
    Join Date
    Mar 2005
    Posts
    11

    Re: fatal error LNK1120: 2 unresolved externals

    these functions is in other header files i add these files in my project but i think u r might b these function in c soo plz will u tell me how i use extern keyword in the function header file buz i have just header file there not the definition of that function
    int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **alldevs, char *errbuf);
    above is the difinition of function soo i write
    extern'C' int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **alldevs, char *errbuf);
    but it also give error soo plz will u guide me the right way i m really thankful to u
    regards
    s ali mehdi

  4. #4
    Join Date
    Jan 2004
    Posts
    206

    Re: fatal error LNK1120: 2 unresolved externals

    Hi samedhi,

    I have sent you a reply on how to resolve the linker errors. Have u received it?

  5. #5
    Join Date
    Oct 2007
    Posts
    1

    Re: fatal error LNK1120: 2 unresolved externals

    Hi,
    I am new to vc++ enviroment .

    The errors which occured when i build the code are

    capture_ten_pack.obj : error LNK2001: unresolved external symbol _pcap_open_live
    capture_ten_pack.obj : error LNK2001: unresolved external symbol _pcap_lookupdev
    Debug/capture_ten_pack.exe : fatal error LNK1120: 3 unresolved externals
    Error executing link.exe.

    capture_ten_pack.exe - 4 error(s), 0 warning(s)

    I would appriciate anybody who make this code will work.

    10Q

  6. #6
    Join Date
    Nov 2010
    Posts
    1

    Cool Re: fatal error LNK1120: 2 unresolved externals

    I had a similiar error. check your constructors if you ahve defined any. Mine worked when I just commented out my constructors, but hten again there was nothing my constructors were doing anyway so it didnt impact me.

  7. #7
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: fatal error LNK1120: 2 unresolved externals

    Maybe you should check the date of a thread before you post.

  8. #8
    Join Date
    Jan 2011
    Posts
    1

    Unhappy fatal error LNK1120: 2 unresolved externals

    Greetings to the day.

    I work now for the first time with the xercesc-library .iam using xerces 3.1.1.when i use this xerces alone i didnot find any errors, but if i use this along with delta3D i get the following errors.I already checked envoronment variables.Thanks in Advance


    : fatal error LNK1120: 2 unresolved externals

    : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class xercesc_3_1:OMImplementation * __cdecl xercesc_3_1:OMImplementationRegistry::getDOMImplementation(unsigned short const *)" (__imp_?getDOMImplementation@DOMImplementationRegistry@xercesc_3_1@@SAPAVDOMImplementation@2@PBG@Z) referenced in function "public: virtual void __thiscall clientSite::PostFrame(double)" (?PostFrame@clientSite@@UAEXN@Z)

    : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static unsigned short * __cdecl xercesc_3_1::XMLString::transcode(char const * const,class xercesc_3_1::MemoryManager * const)" (__imp_?transcode@XMLString@xercesc_3_1@@SAPAGQBDQAVMemoryManager@2@@Z) referenced in function "public: virtual void __thiscall clientSite::PostFrame(double)" (?PostFrame@clientSite@@UAEXN@Z)
    debug\trial2.exe : fatal error LNK1120: 2 unresolved externals

  9. #9
    Join Date
    Apr 2012
    Posts
    2

    Re: fatal error LNK1120: 2 unresolved externals

    ok, so, im using Visual C++ 2008 Express Edition and i'm trying to include other header files (such as IntBinaryTree.h), i understand that i actually have to 1. create the header file. 2. save it in the project folder along side the .cpp file. and 3.(?) well.. for (3) ive tried several things.. tools>options>project&solutions>vc++ directories > include files > and setting it to the path of where my header files will be saved.. which is i guess.. ../..visual studio/projects.. ive also tried... idk ive tried a lot of stuff and its aggravating me. Here are my error messages:

    Error 1: error LNK2019: unresolved external symbol "public: void __thiscall IntBinaryTree::insertNode(int)" (?insertNode@IntBinaryTree@@QAEXH@Z) referenced in function _wmain Program 20-1 Binary Tree's.obj

    Error2: error LNK2019: unresolved external symbol "private: void __thiscall IntBinaryTree:estroySubTree(struct IntBinaryTree::TreeNode *)" (?destroySubTree@IntBinaryTree@@AAEXPAUTreeNode@1@@Z) referenced in function "public: __thiscall IntBinaryTree::~IntBinaryTree(void)" (??1IntBinaryTree@@QAE@XZ) Program 20-1 Binary Tree's.obj

    Error3: fatal error LNK1120: 2 unresolved externals C:\Users\Chris\Documents\Visual Studio 2008\Projects\Program 20-1 Binary Tree's\Debug\Program 20-1 Binary Tree's.exe



    let me ask it this way..
    how do i add additional header files (other than ones that come with the download of visual studio 2008 Express Edition) ??

  10. #10
    Join Date
    Apr 2012
    Posts
    2

    Re: fatal error LNK1120: 2 unresolved externals

    wow just realizing the dates on the posts.

  11. #11
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: fatal error LNK1120: 2 unresolved externals

    Quote Originally Posted by Eric225 View Post
    wow just realizing the dates on the posts. [...]
    Well, though in deed digging up old threads like this one is not really appreciated, the fact that you posted in it is an indication that users (not just you, of course) sometimes are looking for answers in them. So, for you as well as others who may come across that thread later on, here's a proposed solution to your problem:

    It sounds like you did store the source files you created in the right place, and in this case you usually don't need to do any manual configuration about the include directories. Your description of the problem, though, suggests that you may not actually have made them part of the project. That would be done automatically if you'd have created them using the "Add new item" button (right next to the "New project" button, at least in my VC++ 2010). If you already have the files but forgot to add them to the project, you may use "Add existing item" instead. You can tell whether files are part of the project by looking at the Solution Explorer: If they show up there, they're part of the project.

    Not adding new files to the project actually isn't really an uncommon mistake, BTW...
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured