win7環境下VS2013編譯boost_1_58_0步驟:html
1 #include <iostream> 2 #include <boost/thread/thread.hpp> 3 4 void hello() 5 { 6 std::cout << "Hello world, I'm a thread!" << std::endl; 7 } 8 int main() 9 { 10 boost::thread thrd(&hello); 11 thrd.join(); 12 }
win7環境下VS2013編譯libevent-2.0.22-stable步驟:ios
source.cpp源碼以下:git
1 #include <string.h> 2 #include <errno.h> 3 #include <stdio.h> 4 #include <signal.h> 5 6 #ifndef WIN32 7 #include <netinet/in.h> 8 # ifdef _XOPEN_SOURCE_EXTENDED 9 # include <arpa/inet.h> 10 # endif 11 #include <sys/socket.h> 12 #endif 13 14 #include "event2/bufferevent.h" 15 #include "event2/buffer.h" 16 #include "event2/listener.h" 17 #include "event2/util.h" 18 #include "event2/event.h" 19 20 #include <WinSock2.h> 21 22 static const char MESSAGE[] = "Hello, World!\n"; 23 24 static const int PORT = 9995; 25 26 27 static void conn_writecb(struct bufferevent *bev, void *user_data) 28 { 29 struct evbuffer *output = bufferevent_get_output(bev); 30 if (evbuffer_get_length(output) == 0) 31 { 32 printf("flushed answer\n"); 33 bufferevent_free(bev); 34 } 35 } 36 37 static void conn_eventcb(struct bufferevent *bev, short events, void *user_data) 38 { 39 if (events & BEV_EVENT_EOF) 40 { 41 printf("Connection closed.\n"); 42 } 43 else if (events & BEV_EVENT_ERROR) 44 { 45 printf("Got an error on the connection: %s\n", 46 strerror(errno));/*XXX win32*/ 47 } 48 /* None of the other events can happen here, since we haven't enabled 49 * timeouts */ 50 bufferevent_free(bev); 51 } 52 53 static void signal_cb(evutil_socket_t sig, short events, void *user_data) 54 { 55 struct event_base *base = (struct event_base *)user_data; 56 struct timeval delay = { 2, 0 }; 57 58 printf("Caught an interrupt signal; exiting cleanly in two seconds.\n"); 59 60 event_base_loopexit(base, &delay); 61 } 62 63 static void listener_cb(struct evconnlistener *listener, evutil_socket_t fd, 64 struct sockaddr *sa, int socklen, void *user_data) 65 { 66 struct event_base *base = (struct event_base *)user_data; 67 struct bufferevent *bev; 68 69 bev = bufferevent_socket_new(base, fd, BEV_OPT_CLOSE_ON_FREE); 70 if (!bev) 71 { 72 fprintf(stderr, "Error constructing bufferevent!"); 73 event_base_loopbreak(base); 74 return; 75 } 76 bufferevent_setcb(bev, NULL, conn_writecb, conn_eventcb, NULL); 77 bufferevent_enable(bev, EV_WRITE); 78 bufferevent_disable(bev, EV_READ); 79 80 bufferevent_write(bev, MESSAGE, strlen(MESSAGE)); 81 } 82 83 int main(int argc, char **argv) 84 { 85 struct event_base *base; 86 struct evconnlistener *listener; 87 struct event *signal_event; 88 89 struct sockaddr_in sin; 90 91 #ifdef WIN32 92 WSADATA wsa_data; 93 WSAStartup(0x0201, &wsa_data); 94 #endif 95 96 base = event_base_new(); 97 if (!base) 98 { 99 fprintf(stderr, "Could not initialize libevent!\n"); 100 return 1; 101 } 102 103 memset(&sin, 0, sizeof(sin)); 104 sin.sin_family = AF_INET; 105 sin.sin_port = htons(PORT); 106 107 listener = evconnlistener_new_bind(base, listener_cb, (void *)base, 108 LEV_OPT_REUSEABLE|LEV_OPT_CLOSE_ON_FREE, -1, 109 (struct sockaddr*)&sin, 110 sizeof(sin)); 111 112 if (!listener) 113 { 114 fprintf(stderr, "Could not create a listener!\n"); 115 return 1; 116 } 117 118 signal_event = evsignal_new(base, SIGINT, signal_cb, (void *)base); 119 120 if (!signal_event || event_add(signal_event, NULL)<0) 121 { 122 fprintf(stderr, "Could not create/add a signal event!\n"); 123 return 1; 124 } 125 126 event_base_dispatch(base); 127 128 evconnlistener_free(listener); 129 event_free(signal_event); 130 event_base_free(base); 131 132 printf("done\n"); 133 return 0; 134 }
win7環境下VS2013編譯openssl步驟:bootstrap
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <time.h> 5 #include <openssl/bn.h> 6 #include <openssl/ec.h> 7 #include <openssl/rand.h> 8 #include <openssl/err.h> 9 #include <openssl/ecdsa.h> 10 #include <openssl/ecdh.h> 11 12 #pragma comment(lib, "libeay32.lib") 13 14 int main() 15 { 16 17 return 0; 18 }
win7環境下VS2013編譯thrift步驟:windows
初試thrift:app
最後我想說一句,對這些開源項目,真特麼是操蛋,網上資料很雜,一種一種的試,我真是醉了。socket
本文參考資料:工具
win7環境下VS2013編譯boost_1_58_0:http://jingyan.baidu.com/article/a3aad71aa1ebe7b1fb009681.htmloop
win7環境下VS2013編譯libevent-2.0.22-stable步驟:http://www.cnblogs.com/luxiaoxun/p/3603399.html測試
http://zengwu3915.blog.163.com/blog/static/2783489720153402449305/
win7環境下VS2013編譯openssl:http://blog.csdn.net/liuhongxiangm/article/details/18400837
http://blog.sina.com.cn/s/blog_55feec4101010x51.html
thrift初試:http://blog.csdn.net/hbuxiaoshe/article/details/6558391