顯示具有 macintosh 標籤的文章。 顯示所有文章
顯示具有 macintosh 標籤的文章。 顯示所有文章

2016年8月29日 星期一

How to build Qt 4.8 Libraries for OS X: a Rough Note


     I have done the work for a long time, this is a rough note for the purpose: build Qt libraries on/for Mac.

    零.  You need to download the Old mac SDK. however, the download location in Apple's website is difficult to be found.  In here, I give a link where is straightforward to download the OS X SDKs.:
https://github.com/phracker/MacOSX-SDKs

After download the SDKs,  I put them in the root directory (/).

   一. Download  Qt 4.8 everywhere. The latest and final 4.8 version is 4.8.7, but for my case, I used 4.8.5 and 4.8.6. I do not sure if the 4.8.7 could pass the compilation though my configuration successfully.


 二.  My configuration applying Qt 4.8 + Mac is :


 ./configure   --prefix=$PWD/built \

                -platform macx-g++ \

                -sdk /Developer/SDKs/MacOSX10.5.sdk \

                -arch x86 \

                -no-avx -no-sse4.1 -no-sse4.2 \

                -opensource  -release \

                -no-stl -no-webkit -no-qt3support -no-phonon-backend -no-phonon

The parameters are:

-arch x86: the lbraries would be built in 32 bit.

 -platform macx-g++ : use gcc for this compilation, if you adopt clang ( macx-llvm), there would occur duplicate  function body error.

                
 -sdk /Developer/SDKs/MacOSX10.5.sdk :  Set OSX 10.5 SDK as target SDK.

  
-no-avx -no-sse4.1 -no-sse4.2

      disable some cpu instructions, to avoid crash in some old machines.




-no-stl -no-webkit -no-qt3support -no-phonon-backend -no-phonon

      Disable some middleware which is not be installed in this mach machinese, those middleware are like quicktime, mysqrl driver and so forth. If you do not add those parameters, it might incur compilation error for the necessary libraries could not been found.


2015年3月29日 星期日

Connect to a Specified Wifi Router in Macintosh, by Objective C


     Similar to the other article of mine: In here, I post the code which could connect to target wifi router. The Xcode project be set as : Base SDK is 10.7, and  OSX deployment SDK as 10.5. The code depends on the frame work CoreWLAN.framework of 10.7 (it exists in /Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks by default , if you have installed 10.7 SDK), you should add it to your Xcode project. The could running in OS X 10.8 and 10.9  without any wrong(both 32 and 64 bit).

    If you do not install 10.7 SDK, to set the environment, it is necessary to download  OS X 10.7 SDK. you could download it from here ( need apple id). Refer to the article in stack overflow, SDKs of OS X are bundled with  each version of Xcode (10.5 -> 3.1, 10.6 ->3.2, 10.7 ->4.3, 10.8 -> 5.1, 10.9 -> 6.0, respectively). In here, you should download Xcode 4.3, extract the 10.7 SDK to your computer.



The code is in objective-C, but the function call is C-style, for C/C++ calling compatible.


#import <CoreWLAN/CoreWLAN.h>


int ConnectToTargetWifiSSID(char *pSSIDName, char *pPassword)
{
    @autoreleasepool {
        if(NULL == pSSIDName)
            return -1;
        
        NSString *ssidName = [ [NSString alloc] initWithUTF8String : pSSIDName ];
        //NSLog(@"%@", ssidName);
        
        
        CWInterface *currentInterface = [CWInterface interface];
        
        if( [ssidName isEqualToString: [currentInterface ssid]])
        {
            printf("current is %s\n", pSSIDName);
            return 1;
        }/*if*/
        
        if( NO== currentInterface.powerOn)
        {
            printf("wireless card has been turn off\n");
            return -1;
        }/*if */
        
        NSArray *networks = [[currentInterface scanForNetworksWithName:nil error:nil] allObjects];
        
        if(0 == [networks count])
        {
            printf("no available wifi ap\n");
            return -2;
        }/*if */
        
        printf("available wifi ssid name:\n");
        for(int i = 0; i< [networks count]; i++){
            printf("%s \n", [[[networks objectAtIndex:i] ssid] cStringUsingEncoding:NSUTF8StringEncoding]);
        }/*for*/
        
       
        int iii;
        iii = -1;
     
        
        for(int i = 0; i< [networks count]; i++){
            if([ ssidName isEqualToString: [[networks objectAtIndex:i] ssid] ])
            {
                iii = i;
                break;
            }/*if*/
        }/*for*/

        if(-1 == iii)
        {
            printf("no available wifi ssid name marches %s\n", pSSIDName);
            return -3;
        }/*if*/
        
        NSString *password;
        
        if(NULL == pPassword)
            password = [ [NSString alloc] initWithFormat:@"%@",@"    "];
        else
            password = [ [NSString alloc] initWithUTF8String : pPassword];
        
        //NSLog(@"%@", password);
        
        CWNetwork * network = [networks objectAtIndex:iii];
        
        BOOL isSuccess;
        
        isSuccess = [currentInterface associateToNetwork:network password:password error:nil];
       
        if(NO == isSuccess)
            return -6;
        
    }/*@autoreleasepool*/
    
    return 0;
}/*ConnectToTargetWifiSSID*/