Question

The following code compiles and runs in Linux (CentOS 6.5)

#include <iostream>
#include <stdlib.h>

int main()
{
  long sysval = sysconf(_SC_NPROCESSORS_ONLN);
  std::cout << "Num processors = " << sysval << std::endl;
}

However, after installing MinGW + MSYS and attempting to compile this on a Windows box I get:

error: '_SC_NPROCESSORS_ONLN' was not declared in this scope
error: 'sysconf' was not declared in this scope

The steps I followed to intall MinGW and MSYS are:

  1. Download the following packages for MSYS and MinGW-get:

  2. Download MinGW package for your platform:

  3. Extract the MinGW package to C:\MinGW

  4. Extract the MSYS package to C:\MSYS\

  5. Extract the MinGW-get package to the same directory as the the MinGW directory (C:\MinGW) used in Step 2 above.

  6. Open an MSYS command prompt (run MSYS.bat from the directory where the MSYS package was extracted) and run the post-install configuration script by typing the following command:

    /postinstall/pi.sh

    Answer "yes" to all questions and provide the full path to the directory where the MinGW package was extracted when prompted for the location of MinGW.

  7. Run the following command to finalize the configuration of MSYS and MinGW:

    mingw-get install mingw32-autotools

I have also tried this and gotten similar errors when downloading the latest MinGW installer from here and using the interactive install GUI.

Does MinGW not come with the stblib.h C++ library? If it does, does the MinGW implementation not define this commonly used c++ function? Any help would be much appreciated.

Was it helpful?

Solution

(stdlib.h is more C than C++, but both can use it.)

MinGW is for compiling Windows programs for running on Windows; sysconf is POSIX (despite being in stdlib.h, a file defined by the C standard; it's a bit confusing), which Windows (and therefore MinGW) can't understand. (Linux understands POSIX, as does Mac OS X and the BSDs.)

If your goal is to count the processors, use dwNumberOfProcessors in SYSTEM_INFO. If your goal is to run POSIX programs on Windows, you want Cygwin, not MinGW.

(Better two months late than never, I guess.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top