I'm new to c++. Just started learning it 24 hours ago. Am running into a compile problem. Please, no one waste the effort telling me to google it. I've been researching it for quite a while with no joy. I got dev-c++ and a bit of winsock sample code. I've done nothing out of the ordinary. I could only assume that anyone else that downloaded this software and attempted this would meet with the same result. The problem lies with either the compiler or the source. I'm not sure which. Help greatly appreciated. Compiler output and source to follow. Compiler: Default compiler Executing g++.exe... g++.exe 'C:Documents and SettingsdMy Documentsctest.cpp' -o 'C:Documents and SettingsdMy umentsctest.exe' -I'C:Dev-Cpplibgccmingw323.4.2include' -I'C:Dev-Cppincludec++3.4.2backward' -I'C:Dev-Cppincludec++3.4.2mingw32' -I'C:Dev-Cppincludec++3.4.2' -I'C:Dev-Cppinclude' -L'C:Dev-Cpplib' C:DOCUME~1DLOCALS~1Temp/ccWSaaaa.o:test.cpp:(.text+0x46): undefined reference to `WSAStartup@8' C:DOCUME~1DLOCALS~1Temp/ccWSaaaa.o:test.cpp:(.text+0x80): undefined reference to `socket@12' C:DOCUME~1DLOCALS~1Temp/ccWSaaaa.o:test.cpp:(.text+0x97): undefined reference to `WSAGetLastError@0' C:DOCUME~1DLOCALS~1Temp/ccWSaaaa.o:test.cpp:(.text+0xac): undefined reference to `WSACleanup@0' C:DOCUME~1DLOCALS~1Temp/ccWSaaaa.o:test.cpp:(.text+0xd0): undefined reference to `inet_addr@4' C:DOCUME~1DLOCALS~1Temp/ccWSaaaa.o:test.cpp:(.text+0xe5): undefined reference to `htons@4' C:DOCUME~1DLOCALS~1Temp/ccWSaaaa.o:test.cpp:(.text+0x10f): undefined reference to `connect@12' C:DOCUME~1DLOCALS~1Temp/ccWSaaaa.o:test.cpp:(.text+0x128): undefined reference to `WSACleanup@0' C:DOCUME~1DLOCALS~1Temp/ccWSaaaa.o:test.cpp:(.text+0x1e5): undefined reference to `send@16' C:DOCUME~1DLOCALS~1Temp/ccWSaaaa.o:test.cpp:(.text+0x239): undefined reference to `recv@16' collect2: ld returned 1 exit status Execution terminated #include <stdio.h> #include 'winsock2.h' int main() { // Initialize Winsock. WSADATA wsaData; int iResult = WSAStartup( MAKEWORD(2,2), &wsaData ); if ( iResult != NO_ERROR ) printf('Error at WSAStartup()n'); // Create a socket. SOCKET m_socket; m_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); if ( m_socket INVALID_SOCKET ) { printf( 'Error at socket(): %ldn', WSAGetLastError() ); WSACleanup(); return 0; } // Connect to a server. sockaddr_in clientService; clientService.sin_family = AF_INET; clientService.sin_addr.s_addr = inet_addr( '127.0.0.1' ); clientService.sin_port = htons( 27015 ); if ( connect( m_socket, (SOCKADDR*) &clientService, sizeof(clientService) ) SOCKET_ERROR) { printf( 'Failed to connect.n' ); WSACleanup(); return 0; } // Send and receive data. int bytesSent; int bytesRecv = SOCKET_ERROR; char sendbuf[32] = 'Client: Sending data.'; char recvbuf[32] = '; bytesSent = send( m_socket, sendbuf, strlen(sendbuf), 0 ); printf( 'Bytes Sent: %ldn', bytesSent ); while( bytesRecv SOCKET_ERROR ) { bytesRecv = recv( m_socket, recvbuf, 32, 0 ); if ( bytesRecv 0 || bytesRecv WSAECONNRESET ) { printf( 'Connection Closed.n'); break; } if (bytesRecv < 0) return 0; printf( 'Bytes Recv: %ldn', bytesRecv ); } return 0; }
You haven't specified your environment. If Cygwin, have you installed the ioperm.sys driver? If Linux, have you read the man pages, saying.
Here, we are going to learn why an Error: Id returned 1 exit status (undefined reference to 'main') occurs and how to fixed in C programming language? A humble request Our website is made possible by displaying online advertisements to our visitors.
Undefined Reference To Printf Dev C Tutorial
Undefined Reference To Printf Dev C Software
C++ Undefined Reference To Method
Data races The array pointed by str is accessed, and the pointer pointed by endptr is modified (if not null). Exceptions (C) No-throw guarantee: this function never throws exceptions. If str does not point to a valid C-string, or if endptr does not point to a valid pointer object, it causes undefined behavior. See also atof Convert string to double (function ). I haven't written any c code in 3 months, so I'm little rusty. But today I opened an old project and tried to compile it and I got this error: Undefined reference to 'intro' Undefined reference to 'menu(int'. Aug 07, 2015 Undefined reference means the compiler can't find the definition of the function. Make sure that you are compiling and linking both main.cpp and Dog.cpp (if you use an IDE you should have all files in the same project).