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 8510389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:41:26+00:00 2026-06-11T03:41:26+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 Library and 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 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.

UPD:

The answer for the 3rd question -> #pragma comment(lib, "xxx.lib") equivalent under Linux?

  • 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:41:28+00:00Added an answer on June 11, 2026 at 3:41 am
    1. It seems to me that you’ve added the -lws2_32 switch to the C/C++ compiler options. When netbeans invokes the compiler, it passes on the -c switch and it’ll ignore the linker options, such as -l. In the linker options section, Netbeans has an apropriate place to add external libraries. Or you can add the -l as an extra option to the linker. That might solve the problem.

    2. *.lib files are used by the Microsoft toolchain (cl.exe) and lib*.a are used by GNU toolchain (that’s the piece of adivse you’ve found). If you’re going to use Cygwin, you’ll need the lib*.a files. In this context, having Microsoft SDK won’t help you at all. Also, if you need a file that only exists in .lib format, you can convert to.a` with a tool called reimp.

    Hope this helps.

    • 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.