Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

Windows Library Header Troubles

I've been writing a client side socket in C++ from a tutorial, and I haven't quite gotten my head around some of it yet. I've included many windows library headers, but none of them appear to be recognized by the compiler. It begins flagging every identifier in these libraries as undefined and even some of the ones I have created myself. The editor recognizes the code as completely correct, and tells me there are no issues, but the compiler throws over a hundred errors, most all linked to an undeclared identifier.

Some examples of supposedly undeclared identifiers include WSADATA, send(), and some of the most basic functions and classes from these headers. I included the header files windows.h, iostream, winsock2.h, ws2tcpip.h, and fstream. I initialized the socket libraries with "#pragma comment(lib, "Ws_32.lib")". Whatever help you can give is much appreciated.
Try to include winsock2.h before windows.h
And also compile with -lws2_32 parameter.
(Jun 13, 2019 12:58 PM)lynxmk Wrote:  And also compile with -lws2_32 parameter.

He already did pragma comment (lib,"ws232");
(Jun 13, 2019 12:58 PM)lynxmk Wrote:  And also compile with -lws2_32 parameter.

How would I add a parameter to Visual Studio? I probably shouldn't be using a platform like that, but it's the only one I'm comfortable with at the moment.


(Jun 13, 2019 12:49 PM)binbus Wrote:  Try to include winsock2.h before windows.h

The fact that this eliminated so many error messages doesn't seem right to me. That is that something so trivial would matter so much.
(Jun 13, 2019 04:32 PM)asterisk Wrote:  How would I add a parameter to Visual Studio? I probably shouldn't be using a platform like that, but it's the only one I'm comfortable with at the moment.



The fact that this eliminated so many error messages doesn't seem right to me. That is that something so trivial would matter so much.

yes, try winsock2.h before windows.h, if you are having linker issues, yeah, you might try and add ws2_32.lib from your solution->properties->linker->input
(Jun 13, 2019 04:32 PM)asterisk Wrote:  How would I add a parameter to Visual Studio? I probably shouldn't be using a platform like that, but it's the only one I'm comfortable with at the moment.

He didn't know what he was talking about, don't listen to him. That command line linker option isn't even for the MS compiler.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
(Jun 13, 2019 12:46 PM)asterisk Wrote:  I've been writing a client side socket in C++ from a tutorial, and I haven't quite gotten my head around some of it yet. I've included many windows library headers, but none of them appear to be recognized by the compiler. It begins flagging every identifier in these libraries as undefined and even some of the ones I have created myself. The editor recognizes the code as completely correct, and tells me there are no issues, but the compiler throws over a hundred errors, most all linked to an undeclared identifier.

Some examples of supposedly undeclared identifiers include WSADATA, send(), and some of the most basic functions and classes from these headers. I included the header files windows.h, iostream, winsock2.h, ws2tcpip.h, and fstream. I initialized the socket libraries with "#pragma comment(lib, "Ws_32.lib")". Whatever help you can give is much appreciated.

Post your errors.

You probably need to link the library with the functions.
Is there any such thing as a woman of honor, and sincerity?

https://www.PutItOnMute.com/

4K HDR, WDR time-lapsed truck driving videos!


Possibly Related Threads...
Thread / Author Replies Views Last Post
by CH1PDec 26, 2023 01:41 PM 0 113 Dec 26, 2023 01:41 PM
Last Post: CH1P
[Shell] by ɩᴄᴀʀᴜȿ ᴌוᴠᴇѕ™Mar 15, 2023 08:33 AM 1 169 Mar 15, 2023 08:33 AM
Last Post: Aekras1a
[Shell] by Emre_Jan 12, 2021 11:16 PM 0 141 Jan 12, 2021 11:16 PM
Last Post: Emre_