poco入门

源码按照poco。然后看README,进行安装。

 ./configure

make

make install

#include "Poco/ActiveMethod.h"
#include "Poco/ActiveResult.h"
#include <utility>
#include <iostream>

using Poco::ActiveMethod;
using Poco::ActiveResult;

class ActiveAdder
{
public:
    ActiveAdder(): add(this, &ActiveAdder::addImpl)
    {
    }
    ActiveMethod<int, std::pair<int, int>, ActiveAdder> add;
private:
    int addImpl(const std::pair<int, int>& args)
    {
        return args.first + args.second;
    }
};

int main(int argc, char** argv)
{
    ActiveAdder adder;
    ActiveResult<int> sum = adder.add(std::make_pair(1, 2));
    // do other things
    sum.wait();
    std::cout << sum.data() << std::endl;
    return 0;
}

makefile

SRC = $(wildcard ./*.cpp)

CC = g++

REFLAGS = -O2 -g

CFLAGS =  -I/usr/local/include

EXEC = ./bin/test

LDFLAGS =  -L/usr/local/lib \
    -Wl,-rpath,/usr/local/lib/

LIBS = -lPocoUtil -lPocoXML -lPocoNet -lPocoFoundation   -lpthread -lrt -ldl

REL_OBJS = $(SRC:%.cpp=%.o)

all: $(REL_OBJS)
    make bin;
    $(CC) $(LDFLAGS) $(RELFLAGS) $^ $(LIBS) -o $(EXEC) 
%.o:%.cpp
    $(CC) -c $(CFLAGS) $(RELFLAGS) $< -o $@
bin:
    @if [ ! -d bin ]; then \
        mkdir bin;\
    fi

clean :
    rm *.o;
.PHONY:all clean
~                        

 makefile 出现错误,请注意命令行后的tab键。

posted @ 2017-04-21 09:15  于光远  阅读(459)  评论(0编辑  收藏  举报