Thread: compiler/linker flags in VS2008

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    230

    compiler/linker flags in VS2008

    Hi,
    I have some source that won't compile without a passing a flag to both the compiler and the linker. I was previously using Dev-C++ but I want to use MS VS2008 now and it won't work

    In Dev-C++, all I had to do was go to Tools>Compiler Options and add the command -lws2_32 to both text boxes (one each for the compiler and the linker). All worked fine...

    Now with VC++ 2008, this is what I tried:
    Go to Project>(Project Name) Properties
    Then go to Configuration Properties>C/C++>Command Line and added the command -lws2_32
    In the same window, go to Configuration Properties>Linker>Command Line and added the same command, -lws2_32

    However, doing this did not fix the problem I get these warnings when compiling and linking:
    Code:
    cl : Command line warning D9002 : ignoring unknown option '-lws2_32'
    ...
    LINK : warning LNK4044: unrecognized option '/lws2_32'; ignored
    Of course, do to these two errors, I get tons of others. I prefer using VC++ 2008 a lot over Dev-C++, but I can't get it to work...

    Is there a way to fix this???

    EDIT: I forgot to mention that I'm configuring and using the same build configuration, Debug.
    I might not be a pro, but I'm usually right

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    But what the heck is "-lws2_32"?
    Compiler options and linker options are different for each compiler/linker. You can't just expect it to work with all. Not to mention Microsoft uses the standard "/" prefix, and not "-".

    Perhaps if you mentioned what command line it was or what errors you get, we can help more.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    230
    Well, that's the problem...
    I don't even know what that is. All I know is that it fixes errors like these:
    Code:
    keymail.obj : error LNK2019: unresolved external symbol _closesocket@4 referenced in function _MailIt
    keymail.obj : error LNK2019: unresolved external symbol _send@16 referenced in function _MailIt
    keymail.obj : error LNK2019: unresolved external symbol _recv@16 referenced in function _MailIt
    keymail.obj : error LNK2019: unresolved external symbol _connect@12 referenced in function _MailIt
    keymail.obj : error LNK2019: unresolved external symbol _socket@12 referenced in function _MailIt
    keymail.obj : error LNK2019: unresolved external symbol _htons@4 referenced in function _MailIt
    keymail.obj : error LNK2019: unresolved external symbol _gethostbyname@4 referenced in function _MailIt
    keymail.obj : error LNK2019: unresolved external symbol _WSACleanup@0 referenced in function _MailIt
    keymail.obj : error LNK2019: unresolved external symbol _WSAStartup@8 referenced in function _MailIt
    somehow it tells the compiler/linker where to find the references of these... constants I guess??? I didn't write this function myself and I can't really find these words in the source either

    Sorry, but I don't know much about this myself... But I think it has something to do with Windows Sockets.
    I don't mind posting the source of the function if you want.
    I might not be a pro, but I'm usually right

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Under project options -> linker- > input, add Ws2_32.lib. Then it should compile smoothly.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    this option tells the linker link the winsock library

    in VS - open project settings, go to Linker options and in the input libraries list add ws2_32.lib
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    230
    Thanks vart. It worked
    I might not be a pro, but I'm usually right

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. obtaining which combination of flags are being set
    By stanlvw in forum C++ Programming
    Replies: 4
    Last Post: 07-16-2008, 02:43 AM
  2. Cannot get interface flags: Invalid argument
    By nasim751 in forum C Programming
    Replies: 3
    Last Post: 04-14-2008, 02:29 AM
  3. Using 'flags'
    By cyreon in forum C++ Programming
    Replies: 11
    Last Post: 01-28-2008, 04:21 PM
  4. Bit Flags
    By Padawan in forum C Programming
    Replies: 15
    Last Post: 03-30-2004, 10:38 PM
  5. Flags, the ambiguity of
    By Jeremy G in forum C++ Programming
    Replies: 1
    Last Post: 01-25-2003, 11:41 PM