首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >误解cmake在图书馆中的作用

误解cmake在图书馆中的作用
EN

Ask Ubuntu用户
提问于 2015-04-27 17:33:37
回答 1查看 819关注 0票数 1

我一直在尝试包括这个炉子库,所以我实际上可以将这些头文件包含在我的简单程序中,这样我就可以计算出一些扑克手的股票。到目前为止还不太好,可能是因为我这辈子第一次遇到这种情况

好的,这就是说明

为了构建库,需要在所选择的平台上安装以下内容:

  • boost,版本1.46或更高
  • cmake,2.4版或更高版本
  • 颠覆,1.7版或更高版本

我知道了,还有git和GNU C++编译器。

接下来我要做的是:

代码语言:javascript
复制
git clone https://github.com/andrewprock/pokerstove.git
mkdir pokerstove/src/build
cd pokerstove/src/build
cmake ..
make

而且我无法执行这个命令行

girts@girts-ThinkPad-E520:~/pokerstove/src/build$ bin/ps

是的,tnx这个论坛的“我”(当然不是我真的)实际上让它发挥了作用。以下是我先前的问题:

问题1

问题2

不过,我还是能够用以下代码编译.cpp文件

代码语言:javascript
复制
#include <iostream>
#include <vector>
#include <boost/algorithm/string.hpp>
#include <boost/math/special_functions/binomial.hpp>
#include <boost/foreach.hpp>
#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>
#include <pokerstove/util/combinations.h>
#include <pokerstove/peval/Card.h>

int main(){

    std::cout << "Hello World!" << std::endl;
}

但另一方面,这不起作用

代码语言:javascript
复制
#include <iostream>
    #include <pokerstove/peval/CardSet.h>

    using pokerstove::CardSet;
    using pokerstove::Card;
    using pokerstove::Rank;
    using pokerstove::Suit;

    int main(void)
    {
        CardSet big_slick(Card(Rank('A'),Suit('s')),
                          Card(Rank('K'),Suit('s')));
        std::cout << big_slick.str() << std::endl;

        CardSet dead_mans_hand("AcAs8d8hJs");
        std::cout << dead_mans_hand.str() << std::endl;
    }

另外,为什么我们实际上必须执行

代码语言:javascript
复制
cmake ..
make

命令,如果

代码语言:javascript
复制
git clone https://github.com/andrewprock/pokerstove.git

已经创建了许多文件夹,包括所有.cpp和.h文件都在其中的文件夹。使用cmake和make,我只创建一些用于某种测试的.run文件,如果我运行它们,测试表明每件事情都工作得很好,但实际上,我不能说一切都正常。而且,不仅仅是这个CMakeLists.txt文件和指令不知道如何处理它们

总的来说,我只是不明白为什么不能只有普通的.cpp和.h文件,你可以下载,一切都会对每个人(在任何操作系统上)。为什么会有一个伟大的跨平台解决方案叫做cmake。它在我的问题上到底有什么用?我错过了一些大照片吗?

谢谢你阅读了所有这些!

编辑:在某些情况下,我必须包括

代码语言:javascript
复制
#include <gtest/gtest.h>

当然,编译器告诉我没有这样的目录,这是真的。但是这个cmake不是应该负责所有这个项目吗?这就是为什么我不明白为什么这是一个如此伟大的工具。

不会运行的大例子

代码语言:javascript
复制
#include <iostream>
#include <vector>
#include <string>
#include <boost/program_options.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/format.hpp>
#include <pokerstove/peval/PokerHandEvaluator.h>

using namespace std;
namespace po = boost::program_options;
using namespace pokerstove;

class EvalDriver
{
public:
    EvalDriver(const string& game, 
               const vector<string>& hands, 
               const string& board)
        : _peval(PokerHandEvaluator::alloc (game))
        , _hands(hands)
        , _board(board)
    {
    }

    void evaluate()
    {
        for (auto it=_hands.begin(); it!=_hands.end(); it++)
        {
            string& hand = *it;
            _results[hand] = _peval->evaluate(hand, _board);
        }
    }

    string str() const
    {
        string ret;
        for (auto it=_hands.begin(); it!=_hands.end(); it++)
        {
            const string& hand = *it;
            ret += boost::str(boost::format("%10s: %s\n") 
                              % hand 
                              % _results.at(hand).str());
        }
        return ret;
    }

private:
    boost::shared_ptr<PokerHandEvaluator> _peval;
    vector<string> _hands;
    string _board;
    map<string,PokerHandEvaluation> _results;
};

int main (int argc, char ** argv)
{
    string extendedHelp = "\n"
        "   For the --game option, one of the follwing games may be specified.\n"
        "     h     hold'em\n"
        "     o     omaha/8\n"
        "     O     omaha high\n"
        "     r     razz\n"
        "     s     stud\n"
        "     e     stud/8\n"
        "     q     stud high/low no qualifier\n"
        "     d     draw high\n"
        "     l     lowball (A-5)\n"
        "     k     Kansas City lowball (2-7)\n"
        "     b     badugi\n"
        "     3     three-card poker\n"
        "\n"
        "   examples:\n"
        "       ps-eval acas\n"
        "       ps-eval AcAs Kh4d --board 5c8s9h\n"
        "       ps-eval AcAs Kh4d --board 5c8s9h\n"
        "       ps-eval --game l 7c5c4c3c2c\n"
        "       ps-eval --game k 7c5c4c3c2c\n"
        "       ps-eval --game kansas-city-lowball 7c5c4c3c2c\n"
        "\n"
        ;

    try 
    {
        // set up the program options, handle the help case, and extract the values
        po::options_description desc("Allowed options");
        desc.add_options()
            ("help,?",    "produce help message")
            ("game,g",    po::value<string>()->default_value("h"), "game to use for evaluation")
            ("board,b",   po::value<string>()->default_value(""),  "community cards for he/o/o8")
            ("hand,h",    po::value< vector<string> >(),           "a hand for evaluation")
            ("quiet,q",   "produce no output")
            ;

        po::positional_options_description p;
        p.add("hand", -1);
        po::variables_map vm;
        po::store (po::command_line_parser(argc, argv)
                   .style(po::command_line_style::unix_style)
                   .options(desc)
                   .positional(p)
                   .run(), vm);
        po::notify (vm);

        // check for help
        if (vm.count("help") || argc == 1)
        {
            cout << desc << extendedHelp << endl;
            return 1;
        }

        // extract the options
        EvalDriver driver(vm["game"].as<string>(),
                          vm["hand"].as< vector<string> >(),
                          vm["board"].as<string>());
        driver.evaluate();
        if (vm.count("quiet") == 0)
            cout << driver.str();
    }
    catch(std::exception& e) 
    {
        cerr << "-- caught exception--\n" << e.what() << "\n";
        return 1;
    }
    catch(...) 
    {
        cerr << "Exception of unknown type!\n";
        return 1;
    }
    return 0;
}
EN

回答 1

Ask Ubuntu用户

发布于 2015-04-27 18:39:19

有困难是不足为奇的。作者还没有提供安装脚本。

因此,我们必须手动指定标头和库位置:

代码语言:javascript
复制
g++ -o programma ggg.cpp -I/home/girts/pokerstove/src/lib -l{peval,penum} -L/home/girts/pokerstove/src/build/lib/pokerstove/{peval,penum}

在ggg.cpp的代码中有一个错误,我认为:不能用这样的两张卡片创建CardSet。

编译的示例:

代码语言:javascript
复制
#include <iostream>
#include <pokerstove/peval/CardSet.h>
#include <pokerstove/peval/Card.h>

using pokerstove::CardSet;
using pokerstove::Card;
using pokerstove::Rank;
using pokerstove::Suit;

int main(void)
{
    CardSet big_slick(Card(Rank('A'),Suit('s')));
    std::cout << big_slick.str() << std::endl;

    CardSet dead_mans_hand("AcAs8d8hJs");
    std::cout << dead_mans_hand.str() << std::endl;
}
票数 2
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/614925

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档