Question

I am just working on a simple client and server program in c. I have realized that in order to use sockets I have to link the winsock libary file with a pragma: #pragma comment(lib, "Ws2_32.lib"). I was wondering if there is another why to do it without using the pragma instruction. Thanks a lot in advance.

Was it helpful?

Solution

You can add library directly in project.

Follow the steps.

Step 1: Go to project settings in linker option in Additional dependency add your library name like Settings->linker->Additional dependency : add your library name.

Step 2: Settings->linker->Additional Library Dependency : add your library .lib path.(Ignore if it is a system library)

Step 3: Settings->C/C++->Additional Include Directory : Add your library header file path.(Ignore if it is a system library)

In your case as WS2_32.lib is a system library, you just need to go with step 1 only.

Now run your project. It will work.

OTHER TIPS

Set the linker option. In fact, that #pragma is just linker switch..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top