简体   繁体   中英

How can i say visual studio to link a library with my project?

I want to write network program in with visual studio, i write this little programm

#include<iostream>
#include <winsock.h>

int main()
{
WSADATA wsaData; // if this doesn't work
//WSAData wsaData; // then try this instead
// MAKEWORD(1,1) for Winsock 1.1, MAKEWORD(2,0) for Winsock 2.0:
if (WSAStartup(MAKEWORD(2,0), &wsaData) != 0)
{
    std::cout << "error" << std::endl;
    exit(1);
}
WSACleanup();

return 0;
}

but there is link errors, in beej's guide seys that i should link with wsock32.lib library, but i don't know visual studio good, can anyone help me?

Add the wsock32.lib to the text field in Project Properties -> Linker -> Input -> Additional Dependencies

Check Project Properties -> Linker -> Command Line to verify that it's added to the command line.

Alternatively, drag and drop your lib file into your project in Visual Studio - it should get linked automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM