473,385 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Socket Programming

11
I have just started to work in socket programming.. I am getting these errors:
"undefined reference to `__imp_socket'"
"ld returned 1 exit status"
my compiler is dev c++ 5.6.1
here is my code


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <conio.h>    
  3. #include <winsock2.h>
  4. using namespace std;
  5. int main()
  6. {
  7.     int descriptor;
  8.  
  9.     if ((descriptor = socket(AF_INET, SOCK_STREAM, 0)) < 0) 
  10.     {
  11.         cout << "cannot create socket";
  12.         return 0;
  13.     }
  14.  
  15.     cout << "created socket: descriptor= " << descriptor;
  16.     return 0;
  17. }
Feb 15 '14 #1

✓ answered by weaknessforcats

Your code compiles and links using Visual Studio.NET 2008. All I did was go to project properties and add the name Ws2_32.lib as linker input but not the path.

Visual Studio has a linker property named Additional Library Directories and it is there you add all possible paths to all possible libraries for your project.

I didn't have to mess with additional paths paths since Ws2_32.lib was already in a standard directory. I only mentioned additional paths in case your machine is set up different from mine.

This Ws2_32.lib is not a real library but instead is a stub used to load the winsock dll and fetch your proc address.

6 5753
weaknessforcats
9,208 Expert Mod 8TB
You need to link with Ws2_32.lib.

Be sure this .lib is in the list of linker dependencies.
Feb 15 '14 #2
MrError
11
and how can i do that.!!!
Feb 15 '14 #3
MrError
11
i went to
project->project options->parameters->add library
and then browse
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib
and added Ws2_32.lib... but still getting the error :(
Feb 15 '14 #4
weaknessforcats
9,208 Expert Mod 8TB
Your code compiles and links using Visual Studio.NET 2008. All I did was go to project properties and add the name Ws2_32.lib as linker input but not the path.

Visual Studio has a linker property named Additional Library Directories and it is there you add all possible paths to all possible libraries for your project.

I didn't have to mess with additional paths paths since Ws2_32.lib was already in a standard directory. I only mentioned additional paths in case your machine is set up different from mine.

This Ws2_32.lib is not a real library but instead is a stub used to load the winsock dll and fetch your proc address.
Feb 16 '14 #5
MrError
11
My linking problem is resolved.. thanks to you.. but now i am having another problem..
why my code is not creating the socket... the descriptor is always -1..!!
Here is the code.

Expand|Select|Wrap|Line Numbers
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <conio.h>    
  4. #include <winsock2.h>
  5. using namespace std;
  6. int main()
  7. {
  8.     int descriptor;
  9.  
  10.     if ((descriptor = socket(PF_INET, SOCK_STREAM, 0)) == -1);
  11.     {
  12.         cout << "cannot create socket";
  13.         _getch();
  14.         return 0;
  15.     }
  16.     cout << "created socket: descriptor= " << descriptor;
  17.     _getch();
  18.     return 0;
  19. }
Feb 16 '14 #6
MrError
11
oh man...
i am too dumb.. the traditional mistake.. ";"
anyway.. thanks for your help.. i appreciate that.. :)
Feb 16 '14 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Rob | last post by:
Hello, I've got a huge problem with async sockets. I've created a networked virtual environment, using async socket programming. The problem I face occurs when I close the listener socket. It...
2
by: Jean-Philippe Guyon | last post by:
Hello, I am trying to compile a class that uses socket using the Visual C++ ..NET compiler. I get the following error: ------ Build started: Project: infCommon, Configuration: Release Win32...
4
by: Ted | last post by:
Hi all, I am trying to learn C socket programming and I have a small program which is a UP client. The problem is, when I run the program, I get a runtime error - "Invalid Argument" - from a...
2
by: chellappa | last post by:
Hi Every body!, i did a small Chat program in Linux C Socket Programm ... I am using stdout/stdin i did in single machinee i will work properly..but i want to run in differnet machine..i tried...
5
by: John Sheppard | last post by:
Hi all, I am not sure that I am posting this in the right group but here it goes anyway. I am new to socket programming and I have been searching on the internet to the questions I am about to pose...
1
by: John Sheppard | last post by:
Thanks to everyone that responded to my previous Socket Programming question. Now I have run into some behavior that I don't quite understand. Programming environment. VS.NET 2003, C#, Windows...
9
by: Michael Lindsey | last post by:
I need to write a server app to send images to client GUIs that are outside of the server's domain. The client will have the file system path to the image but can not access the file system. I am...
4
by: Marco Meoni | last post by:
Hi. I read the Gordon McMillan's "Socket Programming Howto". I tried to use the example in this howto but this doesn't work. The code is class mysocket: '''classe solamente dimostrativa -...
8
by: =?Utf-8?B?Sm9obg==?= | last post by:
Hi all, I am new to .net technologies. ASP.NET supports socket programming like send/receive in c or c++? I am developing web-site application in asp.net and code behind is Visual C#. In...
1
by: phpuser123 | last post by:
I just started socket programming in java.I read a few tutorial and came up with the following script import java.net.*; public class socket { /** * @param args */ public static...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.