Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8508031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:02:29+00:00 2026-06-11T03:02:29+00:00

I use NetBeans, Windows and Cygwin with G++ compiler. I’m examining Windows Sockets 2.

  • 0

I use NetBeans, Windows and Cygwin with G++ compiler.

I’m examining Windows Sockets 2. I do everything that is written in MS manual. I have a code (mostly from this manual):

#include <winsock2.h>
#include <ws2tcpip.h>

#include <cstdlib>
#include <iostream>

#pragma comment(lib, "Ws2_32.lib")

int main() {

  WSADATA wsaData;

  int iResult;

  // Initialize Winsock
  iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
  if (iResult != 0) {
     printf("WSAStartup failed: %d\n", iResult);
     return 1;
  }
  else cout << "Initialization OK.";

  return 0;
}

And I have a problem when I try to run the project:

undefined reference to `_WSAStartup@8'

I understand that Ws2_32.lib is missing. This is because I do not have Windows SDK installed. But before installing it I want to try out tools that Cygwin offers. It has all the w32api header files, I have them in:

C:\cygwin\usr\include\w32api

And it has some w32api almost .lib files in the directory:

C:\cygwin\lib\w32api

But all these lib files are different, they have .a extension and a little bit different name, like:

libws2_32.a  // in Cygwin
   vs.
ws2_32.lib   // in Windows  

When I use Cygwin terminal to create an .exe file, everything works fine. The commands I input are:

cd C:\\c++\\myProgram           // go to the dir
g++ myProgram.cpp -lws2_32      // compile using -l option to link libws2_32.a

And after it I get a.exe file. I run it and it works:

./a.exe    // Initialization OK.

But as I said I use NetBeans. And if I try to run the project from NB ([F6] button) I always have this error undefined reference to ‘_WSAStartup@8’.

I’ve tried already everything I could find on NB forums. I’ve tried to link libws2_32.a to my project this way. I go to:

File -> Project Properties -> Linker -> Libraries

And there are three options:

Add Library...
Add Library File...
Add Option...

I’ve tried them all. I’ve tried to link both just Add Library... and Add Library File.... I’ve also tried to add such an option in the Add Option... button:

Add Option... -> Other option ->    // and I input here "-lws2_32"

But whatever I do I can’t run the project from NB, I get error undefined reference to ‘_WSAStartup@8’.

So it seems that it is not a problem (error) in the code. It seems that the problem is with NB, with its possibility to link libraries. Or I do wrong steps to attach them to the project.

So my questions are:

1) What do I do wrong? How may I run the project right from NB? I didn’t try to install Windows SDK, I want to try with Cygwin tools as it has such kind of tools.

2) What is the difference between Windows .lib files and Cygwin .a files? Is it better to install Windows SDK and just forget about those .a files? Everything I could find so far about them on Cygwin site is this:

The import library is a regular UNIX-like .a library, but it only
contains the tiny bit of information needed to tell the OS how your
program interacts with (“imports”) the dll. This information is linked
into your .exe. This is also generated by dlltool.

3) Is it possible to use #pragma comment(lib, "libws2_32.a") to link .a files? I’ve tried but didn’t get success results.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:02:31+00:00Added an answer on June 11, 2026 at 3:02 am

    1) What do I do wrong? How may I run the project right from NB? I didn’t try to install Windows SDK, I want to try with Cygwin tools as it has such kind of tools.

    Try this: http://forums.netbeans.org/ptopic44959.html

    2) What is the difference between Windows .lib files and Cygwin .a files? Is it better to install Windows SDK and just forget about those .a files?

    Both of these files in this particular case are called “import libraries”. Import libraries are basically a file containing a list of valid functions, so that when you link your exe, the linker knows that those functions will exist in some particular DLL. So when you link to wsock32.lib or ws2_32.lib, the linker now knows that these functions will exist in wsock32.dll and ws2_32.dll. Thus, it will not complain. Now, the .lib import library format is Microsoft’s format. GCC/unix/linux/mingw/cygwin etc. have a different format, and the extension for that format is .a. Now, cygwin/mingw etc. provide a ws2_32.a so that when using cygwin/mingw/gcc, the linker can read the import library in the correct format. cygwin/mingw/gcc will simply not understand the .lib. Microsoft provides the .lib files in their SDK, but I am not sure how this will help in this case. (Though the SDK is definitely useful, because it provides lots of header files and DLLs for other useful things you might need, but the import libraries are useless, because gcc/mingw/cygwin will not understand them; unless you use a converter tool, like the one mentioned in your duplicate question).

    3) Is it possible to use #pragma comment(lib, “libws2_32.a”) to link .a files? I’ve tried but didn’t get success results.

    No, the #pragma linking comments are an MSVC specific (ugly IMO) extension. Use the linker options in the menus.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use NetBeans, Windows and Cygwin with g++ compiler. I'm examining Windows Sockets 2.
i have installed the cygwin package for my netbeans IDE. I can use that
Question simple and quick: I have started to use Netbeans to write some code
I mostly use Eclipse but have mentionned Netbeans on my cv. Are there any
I'm trying to use NetBeans to compile C code and have the following versions
I use netbeans on windows platform to write my code and then I commit
In NetBeans 6.9 in windows version I use CygWin for C++ programming.I can compile
I use Netbeans for development and have been doing my Mercurial operations on the
I want to use the jetty httpclient (in netbeans) but have the least number
I am using GNU/Linux (Ubuntu + Gnome). I have been using netbeans on windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.