thrift:
http://archive.apache.org/dist/thrift/0.9.3/
下載thrift-0.9.3.exe和thrift-0.9.3.tar.gz
解壓縮到C盤
執行thrift -r --gen cpp student.thrift
生成
boost:
http://pilotfiber.dl.sourceforge.net/project/boost/boost/1.61.0/boost_1_61_0.7z
輸入bootstrap,便生成bjam.exe文件
輸入bjam toolset=msvc-10.0 variant=debug,release threading=multi link=static,便生成boost庫(時間挺長20分鐘以上)
修改VS2010的參數 在項目的組合顯示那找到屬性頁,打開屬性頁,選擇配置屬性,選擇VC++目錄,設置includepath和libpath,
E:\boost_1_61_0
E:\boost_1_61_0\stage\lib
至此設置完畢
寫下面代碼編譯
#include
<boost/config.hpp> #include
<iostream> #include
<vector> #include
<string> #include
<boost/graph/adjacency_list.hpp> #include
<boost/tuple/tuple.hpp> enum family {
Jeanie, Debbie, Rick, John, Amanda, Margaret, Benjamin, N }; int main() { using namespace boost; const char *name[]
= { "Jeanie" ,
"Debbie" ,
"Rick" ,
"John" ,
"Amanda" , "Margaret" ,
"Benjamin" }; adjacency_list
<> g(N); add_edge(Jeanie,
Debbie, g); add_edge(Jeanie,
Rick, g); add_edge(Jeanie,
John, g); add_edge(Debbie,
Amanda, g); add_edge(Rick,
Margaret, g); add_edge(John,
Benjamin, g); graph_traits
< adjacency_list <> >::vertex_iterator i, end; graph_traits
< adjacency_list <> >::adjacency_iterator ai, a_end; property_map
< adjacency_list <>, vertex_index_t >::type index_map
= get(vertex_index, g); for (boost::tie(i,
end) = vertices(g); i != end; ++i) { std::cout
<< name[get(index_map, *i)]; boost::tie(ai,
a_end) = adjacent_vertices(*i, g); if (ai
== a_end) std::cout
<< "
has no children" ; else std::cout
<< "
is the parent of " ; for (;
ai != a_end; ++ai) { std::cout
<< name[get(index_map, *ai)]; if (boost::next(ai)
!= a_end) std::cout
<< ",
" ; } std::cout
<< std::endl; } return EXIT_SUCCESS; }
Libevent官網:http://libevent.org/ windows 7下編譯: 編譯環境: windows 7 + VS2010 (1)解壓libevent到F:\libevent\libevent-2.0.21-stable
(2)打開Microsoft visual studio 2010命令行工具 (3)修改以下三個文件,添加宏定義: 在以下3個文件開頭添加“#define _WIN32_WINNT 0x0500” libevent-2.0.21-stable\event_iocp.c libevent-2.0.21-stable\evthread_win32.c libevent-2.0.21-stable\listener.c (4)使用VS命令提示工具編譯: cd/d F:\libevent\libevent-2.0.21-stable nmake /f Makefile.nmake (5)編譯結果:
libevent_core.lib:All core event and buffer functionality. This library contains all the event_base, evbuffer, bufferevent, and utility functions.
libevent_extras.lib:This library defines protocol-specific functionality that you may or may not want for your application, including HTTP, DNS, and RPC.
libevent.lib:This library exists for historical reasons; it contains the contents of both libevent_core and libevent_extra. You shouldn’t use it; it may go away in a future version
of Libevent. (6)VS2010下使用lib 新建一個VC++控制檯項目: 環境配置: 項目下建一個Lib目錄,將上面三個lib文件copy到該目錄下。 新建一個Include目錄,將F:\libevent\libevent-2.0.21-stable\include下的文件和文件夾copy到該目錄下,F:\libevent\libevent-2.0.21-stable\WIN32-Code下的文件copy到該目錄下,2個event2目錄下的文件可合併一起。 main代碼: // LibeventTest.cpp : 定義控制檯應用程序的入口點。 // #include "stdafx.h" #include <string.h> #include <errno.h> #include <stdio.h> #include <signal.h> #ifndef WIN32 #include <netinet/in.h> # ifdef _XOPEN_SOURCE_EXTENDED # include <arpa/inet.h> # endif #include <sys/socket.h> #endif #include "event2/bufferevent.h" #include "event2/buffer.h" #include "event2/listener.h" #include "event2/util.h" #include "event2/event.h" #include <WinSock2.h> static const char MESSAGE[] = "Hello, World!\n"; static const int PORT = 9995; static void conn_writecb(struct bufferevent *bev, void *user_data) { struct evbuffer *output = bufferevent_get_output(bev); if (evbuffer_get_length(output) == 0) { printf("flushed answer\n"); bufferevent_free(bev); } } static void conn_eventcb(struct bufferevent *bev, short events, void *user_data) { if (events & BEV_EVENT_EOF) { printf("Connection closed.\n"); } else if (events & BEV_EVENT_ERROR) { printf("Got an error on the connection: %s\n", strerror(errno));/*XXX win32*/ } /* None of the other events can happen here, since we haven't enabled * timeouts */ bufferevent_free(bev); } static void signal_cb(evutil_socket_t sig, short events, void *user_data) { struct event_base *base = (struct event_base *)user_data; struct timeval delay = { 2, 0 }; printf("Caught an interrupt signal; exiting cleanly in two seconds.\n"); event_base_loopexit(base, &delay); } static void listener_cb(struct evconnlistener *listener, evutil_socket_t fd, struct sockaddr *sa, int socklen, void *user_data) { struct event_base *base = (struct event_base *)user_data; struct bufferevent *bev; bev = bufferevent_socket_new(base, fd, BEV_OPT_CLOSE_ON_FREE); if (!bev) { fprintf(stderr, "Error constructing bufferevent!"); event_base_loopbreak(base); return; } bufferevent_setcb(bev, NULL, conn_writecb, conn_eventcb, NULL); bufferevent_enable(bev, EV_WRITE); bufferevent_disable(bev, EV_READ); bufferevent_write(bev, MESSAGE, strlen(MESSAGE)); } int main(int argc, char **argv) { struct event_base *base; struct evconnlistener *listener; struct event *signal_event; struct sockaddr_in sin; #ifdef WIN32 WSADATA wsa_data; WSAStartup(0x0201, &wsa_data); #endif base = event_base_new(); if (!base) { fprintf(stderr, "Could not initialize libevent!\n"); return 1; } memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_port = htons(PORT); listener = evconnlistener_new_bind(base, listener_cb, (void *)base, LEV_OPT_REUSEABLE|LEV_OPT_CLOSE_ON_FREE, -1, (struct sockaddr*)&sin, sizeof(sin)); if (!listener) { fprintf(stderr, "Could not create a listener!\n"); return 1; } signal_event = evsignal_new(base, SIGINT, signal_cb, (void *)base); if (!signal_event || event_add(signal_event, NULL)<0) { fprintf(stderr, "Could not create/add a signal event!\n"); return 1; } event_base_dispatch(base); evconnlistener_free(listener); event_free(signal_event); event_base_free(base); printf("done\n"); return 0; } 項目屬性設置: VC++目錄: 包含目錄,添加:F:\Projects\LibeventTest\LibeventTest\Include; 庫目錄,添加:F:\Projects\LibeventTest\LibeventTest\Lib; C/C++: 代碼生成-->運行庫:多線程調試 (/MTd)(Debug下),多線程 (/MT)(Release下) 連接器: 輸入:ws2_32.lib;wsock32.lib;libevent.lib;libevent_core.lib;libevent_extras.lib; ws2_32.lib;wsock32.lib;是用來編譯Windows網絡相關的程序庫。 編譯,生成!
#include <event2/event.h>
#include <stdio.h> int main() { const char *version = event_get_version(); printf("%s\n",version); return 0; } |