Mac 下命令行使用Cmake与PlistCpp开源库的使用

本文详细介绍了如何在Mac系统上安装CMake并在终端中使用,解决了cmake命令未找到的问题。此外,还提供了在iOS项目中使用PlistCpp开源库的方法,包括配置步骤和具体使用示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一. Mac 下安装Cmake,并在终端上使用Cmake,解决cmake命令command not found

1. cmake下载
选择对应的版本:

2. 在mac系统上直接安装,则有相应的UI界面的cmake可以使用
安装好gui界面后,进入目录/Applications/CMake.app/Contents/bin/cmake-gui   
找到cmake图标,右键显示包内容



3. 将cmake添加到终端,使得在终端也可以使用cmake
在终端输入命令:
sudo "/Applications/CMake.app/Contents/bin/cmake-gui" --install

这样就可以在终端使用cmake,而不会提示command not found之类的错误了。

二. IOS中使用PlistCpp开源库

1. PlistCpp开源库的github地址:
由于需要依赖mac下的boost,具体配置boost的方法参考上一篇博文:http://blog.youkuaiyun.com/waterbinbin/article/details/62438417

2. 配置PlistCpp
新建一个ios项目,其实不需要按照github上的说明来操作,只要添加相应到文件到项目即可使用



3.具体使用方法参考源码plistTests.cpp文件或者博客http://blog.youkuaiyun.com/c_singleboy/article/details/38677459

简单的demo使用如下:
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    Plist::dictionary_type dict;
    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"binaryExample1" ofType:@"plist"];
    const char* path = [plistPath UTF8String];
    Plist::readPlist(path, dict);
    for(Plist::dictionary_type::const_iterator it = dict.begin(); it != dict.end(); ++it)
    {
        cout<< "key: "<< it->first <<endl;
    }
    
    //读数组
    const Plist::array_type& plistArray = boost::any_cast<const Plist::array_type&>(dict.find("testArray")->second);
    cout << boost::any_cast<const int64_t&>(plistArray[0]) << endl;
    cout << boost::any_cast<const string&>(plistArray[1]).c_str() << endl;
    
    //读字典
    const Plist::dictionary_type& plistDic = boost::any_cast<const Plist::dictionary_type&>(dict.find("testDict")->second);
    Plist::dictionary_type::const_iterator it = plistDic.begin();
    cout << "key:" << it->first << endl;
    cout << boost::any_cast<const string&>(it->second) << endl;
    
    //读一个变量
    const Plist::Date& date = boost::any_cast<const Plist::Date&>(dict.find("testDate")->second);
    std::string strDate = date.timeAsXMLConvention();
    cout << boost::any_cast<const string&>(strDate) << endl;
    
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path1 = paths[0];
    NSString *filePath = [path1 stringByAppendingPathComponent:@"writeBinary.plist"];
    const char* filePath1 = [filePath UTF8String];
    
    //写数组1
    Plist::dictionary_type dic;
    
    dic.insert(make_pair("testArray1", plistArray));
    //Plist::writePlistBinary(filePath1, dic);
    
    //写数组2
    vector<boost::any> array(2);
    array[0] = 50;
    array[1] = string("mystring ok in array");
    cout << boost::any_cast<const int&>(array[0]) << endl;
    cout << boost::any_cast<const string&>(array[1]).c_str() << endl;
    dic["testArray2"] = array;
    Plist::writePlistBinary(filePath1, dic);
    
    Plist::dictionary_type dicR;
    Plist::readPlist(filePath1, dicR);
    //读数组
    const Plist::array_type& plistArrayR = boost::any_cast<const Plist::array_type&>(dicR.find("testArray2")->second);
    cout << boost::any_cast<const int64_t&>(plistArrayR[0]) << endl;
    cout << boost::any_cast<const string&>(plistArrayR[1]).c_str() << endl;
}


demo下载链接:

本博客参考文章:

http://blog.youkuaiyun.com/baiyu9821179/article/details/54632135

http://blog.youkuaiyun.com/yuanya/article/details/51098777

http://blog.youkuaiyun.com/c_singleboy/article/details/38677459

### 如何在Windows命令行使用CMake 为了能够在Windows命令行中顺利使用`cmake`,需先确认已正确安装CMake并将其路径加入环境变量。通常情况下,在完成安装向导中的所有步骤后,该操作会被自动执行。 #### 安装CMake于Windows平台 下载适用于Windows的CMake版本,并按照安装程序指示完成设置过程。确保勾选选项允许修改系统的PATH环境变量以便可以在任何地方调用`cmake.exe`[^1]。 #### 验证安装情况 打开一个新的命令提示符窗口(Command Prompt),输入如下指令来验证是否能正常访问CMake: ```cmd cmake --version ``` 如果显示出了具体的版本号,则说明配置无误;反之则可能需要手动调整环境变量或重新启动计算机使更改生效。 #### 使用基本语法构建项目 假设存在一个源码目录名为`my_project`以及目标输出位置为`build_directory`,那么可以采用下面的方式来进行编译工作: 创建用于存放生成文件的新文件夹: ```cmd mkdir build_directory cd build_directory ``` 通过指定父级路径下的根`CMakeLists.txt`初始化构建系统: ```cmd cmake .. ``` 可附加参数自定义行为,比如指明特定调试模式或是设定安装地址等特性: ```cmd cmake .. -DWITH_DEBUG=1 -DCMAKE_INSTALL_PREFIX=./output_path ``` 最后利用所选定的生成器开始实际制作流程: 对于MinGW Makefiles而言, ```cmd cmake --build . --config Release ``` 而对于Visual Studio解决方案来说则是, ```cmd cmake --build . --config Release --target INSTALL ``` 以上便是关于怎样在Windows环境下运用命令行界面操控CMake的大致介绍[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值