MSVis-Studio C++ libraries and linker errors

This is a discussion on MSVis-Studio C++ libraries and linker errors within the Windows Programming forums, part of the Platform Specific Boards category; I am trying to link a program made of about 30 files, all in the same directory (a few use ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    8

    MSVis-Studio C++ libraries and linker errors

    I am trying to link a program made of about 30 files,
    all in the same directory (a few use MFC classes) on
    Microsoft Visual C++.
    There appear to be some conflicts between libraries
    I have set the link option to "Debug Multi-threaded DLL".
    And I need the "msvcrtd.lib" I have tried typing
    "/nodefaultlib:...." for most of the other libraries in the
    linker options text box but that just produces evern more
    linker errors of the same type (LNK 2005, LNK4098,
    LNK2001)

    Below is the Linker Output:

    --------------------Configuration: Sync_Gener - Win32 Debug--------------------
    Linking...
    MSVCRTD.lib(MSVCRTD.dll) : error LNK2005: _exit already defined in libc.lib(crt0dat.obj)
    nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in libc.lib(new.obj)
    nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in libc.lib(delete.obj)
    libc.lib(atox.obj) : error LNK2005: _atoi already defined in MSVCRTD.lib(MSVCRTD.dll)
    LINK : warning LNK4098: defaultlib "MSVCRTD" conflicts with use of other libs; use /NODEFAULTLIB:library
    MessageTrans.obj : error LNK2001: unresolved external symbol __imp__recvfrom@24
    MessageTrans.obj : error LNK2001: unresolved external symbol __imp__WSASetLastError@4
    MessageTrans.obj : error LNK2001: unresolved external symbol __imp__gethostbyname@4
    MessageTrans.obj : error LNK2001: unresolved external symbol __imp__gethostname@8
    MessageTrans.obj : error LNK2001: unresolved external symbol __imp__bind@12
    MessageTrans.obj : error LNK2001: unresolved external symbol __imp__htons@4
    MessageTrans.obj : error LNK2001: unresolved external symbol __imp__socket@12
    MessageTrans.obj : error LNK2001: unresolved external symbol __imp__WSAStartup@8
    MessageTrans.obj : error LNK2001: unresolved external symbol __imp__sendto@24
    MessageTrans.obj : error LNK2001: unresolved external symbol __imp__closesocket@4
    Debug/Sync_Gener.exe : fatal error LNK1120: 10 unresolved externals
    Error executing link.exe.

    Sync_Gener.exe - 15 error(s), 1 warning(s)


    what could be going wrong?

  2. #2
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    So you're not linking with the Winsock library?
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    8

    linking with the winsock library?

    The correct path to the winsock library("WSock32.lib" )
    is shown in the
    Tools/Options/Library Directories options box.

    and The program does use winsock.

    the linker should be able to find it, right?


    (obviously, I never tried to get the linker to Ignore WSock32.lib
    I woudln't want that)
    Last edited by kellydj; 03-08-2002 at 08:43 AM.

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    If you are using winsock you still need to explicitly include it in your project...I think its in Project->options->Link (or something).....and then add it along with the other libs

    But then if you are using the MFC CSocket class I dont think you need it

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    8

    re: winsock

    Winsock IS explicitly included in my files.

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    The current header for WinSock is winsock2.h and the library you need to link to is ws2_32.lib.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    8

    Re: win2_32.lib

    I've included that in my libraries, but I'm still getting
    linker warnings such as this:

    nafxcwd.lib(afxmem.obj) : warning LNK4006: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in libc.lib(new.obj); second definition ignored

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789

    Re: Re: win2_32.lib

    Originally posted by kellydj
    I've included that in my libraries, but I'm still getting
    linker warnings such as this:

    nafxcwd.lib(afxmem.obj) : warning LNK4006: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in libc.lib(new.obj); second definition ignored

    You could try ommit the LIBC.lib from your linker's library list....Its probably the lesser of both libraries....I dont know if this will work but try;

    Project->Settings->Link

    Choose Category->Input->Ignore Libraries and add LIBC.lib....

    Then see if it will link without errors.....

  9. #9
    Registered User
    Join Date
    Feb 2002
    Posts
    8

    ignore LIBC.lib

    I ignored LIBC.lib and got this :

    ________________________

    nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in MSVCRTD.lib(MSVCRTD.dll)
    nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) already defined in msvcprtd.lib(delop_s.obj)
    nafxcwd.lib(timecore.obj) : error LNK2001: unresolved external symbol __mbctype
    nafxcwd.lib(apphelp.obj) : error LNK2001: unresolved external symbol __mbctype
    nafxcwd.lib(filelist.obj) : error LNK2001: unresolved external symbol __mbctype
    nafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv
    nafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argc
    Debug/Sync_Gener.exe : fatal error LNK1120: 3 unresolved externals
    Error executing link.exe.

    Sync_Gener.exe - 8 error(s), 0 warning(s)
    _________________________

    apparently it needs LIBC.lib to resolve these symbols, or some
    other library??

  10. #10
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Hmm...and I suppose you need nafxcwd.lib for the MFC objects....

    Weird thing....you use nafxcwd.lib and the last 'd' signifies the debug library........but LIBC.lib is used and not the corresponding LIBCD.lib......

    Dont know if this is a problem?

    Sorry I cant really offer any more.....but if you find the answer, please post it

  11. #11
    Registered User
    Join Date
    Feb 2002
    Posts
    8

    Mfc42.lib

    I added Mfc42.lib to my list of library linker options
    (I also removed _DEBUG definition option from settings
    and got rid of any libraries ending in "d" on the list)

    and now it links sucessfully.

    apparently I was missing Mfc42.lib or any equivalent to it,
    and/or there was an incompatibility between debug
    and non-debug libraries being linked-to .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linker errors in VC++ 2005
    By C+/- in forum C++ Programming
    Replies: 0
    Last Post: 05-18-2007, 07:42 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 01:59 PM
  4. Compile with *.lib
    By Kelvin in forum C++ Programming
    Replies: 1
    Last Post: 07-23-2002, 06:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21