none
SUA + Visual Studio + pthreads RRS feed

  • Question

  • Hi,

    I cannot compile this code under SUA:

    #include <unistd.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <pthread.h>
    void * thread_function(void *arg) {
         printf("thread_function started. Arg was %s\n", (char *)arg);
         // pause for 3 seconds
         sleep(3);
         // exit and  return a message to another thread
         // that may be waiting for us to finish
         pthread_exit ("thread one all done");
    }
    int main() {
         int res;
         pthread_t a_thread;
         void *thread_result;
         // create a thread that starts to run     ‘thread_function’
         pthread_create (&a_thread, NULL,
         thread_function, (void*)"thread one");
         printf("Waiting for thread to finish...\n");
         // now wait for new thread to finish
         // and get any returned message in ‘thread_result’
         pthread_join(a_thread, &thread_result);
         printf("Thread joined, it returned %s\n", (char *)thread_result);
         exit(0);
    }
    I'm running on Windows 7 Ultimate x64 with Visual Studio 2008 and 2010 and I have installed:
    - Windows Subsystem for UNIX
    - Utilities and SDK for Subsystem for UNIX-based Applications in Microsoft Windows 7 and Windows Server 2008 R2
    Include directories property of Visual Studio project is set to "C:\Windows\SUA\usr\include"

    What I have to configure in order to compile and run (and possibly debug) pthreads programs in Visual Studio 2010 (or 2008)?

    Sunday, March 28, 2010 9:55 PM

Answers

  • Hello

    Visual C++ is using the cl.exe to compile C++ code by default.

    As I said in my last reply, the Subsystem for UNIX-based Applications Software Development Kit (SDK) supports Microsoft Visual C++, version 5.0 or later, but we need to use the cc and c89 compiler drivers.

    Please check the "Help for Subsystem for UNIX-based Applications" which is installed with SUA.

    Regards,
    Rong-Chun Zhang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, April 12, 2010 10:23 AM

All replies

  • Hello

    When you say it cannot be compiled, what is the error message?

    >What I have to configure in order to compile and run (and possibly debug) pthreads programs in Visual Studio 2010 (or 2008)?

    Please take a look at the following article.

    Compiling a C program on Subsystem for Unix-based Applications (SUA) & Interix
    http://www.suacommunity.com/r_compiling.aspx

    Regards,
    Rong-Chun Zhang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, March 29, 2010 12:03 PM
  • There are steps how to compile a program using command line. Is possible to configure Visual Studio to do that as well?
    Monday, March 29, 2010 8:36 PM
  • Hello

    Please take a look at C:\Windows\SUA\docs\Releasenotes.htm, seems Visual C++ 2005 is the only supported version.

    "For this release, Microsoft Visual Studio 2005 is the only supported version of VS. (8.x and newer). Using other versions of Visual Studio with this product can result in unexpected behavior."

    Regards,
    Rong-Chun Zhang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, March 30, 2010 12:39 PM
  • Hello,

    May I know the situation on your side?

    Regards,
    Rong-Chun Zhang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, April 2, 2010 6:20 AM
  • In VS2005 build fails due to error in unistd.h. I added "C:\Windows\SUA\usr\include" into VC++ Directories Include files and "C:\Windows\SUA\usr\lib" into Library files. Additional references search paths also contains this two folders.

    Saturday, April 3, 2010 4:40 PM
  • Hello

    Please check the "Help for Subsystem for UNIX-based Applications" which is installed with SUA.

    "Subsystem for UNIX-based Applications overview" -> "Porting applications to the Subsystem for UNIX-based Applications" -> "Compatibility issues" -> "Microsoft compilers":

    "The Subsystem for UNIX-based Applications Software Development Kit (SDK) supports Microsoft Visual C++, version 5.0 or later, through the cc and c89 compiler drivers. The cc(1) and c89(1) utilities are interfaces to the compiler and linker programs in Visual C++ (Cl.exe and Link.exe, respectively)."

    Seems we cannot use the cl.exe directly to compile the SUA applications, we will need to use cc, which is a wrapper of cl.exe, to compile the application.

    Regards,
    Rong-Chun Zhang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, April 5, 2010 10:27 AM
  • Hello

    May I know the situation on your side?

    Regards,
    Rong-Chun Zhang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, April 9, 2010 11:57 AM
  • I don't know how to configure VS2005 to use cl.exe. Much easier for me is install Ubuntu into Virtual Box and configure a shared folder. Then write code in VS2010 and compile it from console using g++ on Linux. Do you know about step-by-step guide how to compile code above in Visual Studio?
    Monday, April 12, 2010 9:36 AM
  • Hello

    Visual C++ is using the cl.exe to compile C++ code by default.

    As I said in my last reply, the Subsystem for UNIX-based Applications Software Development Kit (SDK) supports Microsoft Visual C++, version 5.0 or later, but we need to use the cc and c89 compiler drivers.

    Please check the "Help for Subsystem for UNIX-based Applications" which is installed with SUA.

    Regards,
    Rong-Chun Zhang
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, April 12, 2010 10:23 AM