c++框架crow搭建web服务入门

环境
Ubuntu
gcc 7.5.0
按照github官方的安装

cd /usr/local 
git clone https://github.com/ipkn/crow.git
cd crow 
mkdir build
cd build
cmake ..
make

执行到make时候报错了

[  4%] Built target amalgamation
[  9%] Generating ws.html
[  9%] Built target example_ws_copy
[ 19%] Built target example_websocket
[ 28%] Built target helloworld
make[2]: *** No rule to make target '/usr/lib/libtcmalloc_minimal.so', needed by 'examples/example'.  Stop.
CMakeFiles/Makefile2:249: recipe for target 'examples/CMakeFiles/example.dir/all' failed
make[1]: *** [examples/CMakeFiles/example.dir/all] Error 2
Makefile:94: recipe for target 'all' failed

放狗搜了一圈,把crow和crow.h cp到/usr/local/include 下
并且按照官方说明安装依赖库

sudo apt-get install build-essential libtcmalloc-minimal4 && sudo ln -s /usr/lib/libtcmalloc_minimal.so.4 /usr/lib/libtcmalloc_minimal.so

使用g++ -o target helloworld.cpp 编译

/tmp/cciae6FI.o: In function `__static_initialization_and_destruction_0(int, int)':
helloworld.cpp:(.text+0x93e): undefined reference to `boost::system::generic_category()'
helloworld.cpp:(.text+0x94a): undefined reference to `boost::system::generic_category()'
helloworld.cpp:(.text+0x956): undefined reference to `boost::system::system_category()'

查了一下,应该是boost库的问题
再次编译 g++ -o target helloworld.cpp -lboost_system

/usr/bin/ld: /tmp/cc5f9293.o: undefined reference to symbol 'pthread_sigmask@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

最后编译命令 g++ -o target helloworld.cpp -lboost_system -lpthread
顺利通过!

helloworld.cpp

#include "crow.h"

int main()
{
    crow::SimpleApp app;

    CROW_ROUTE(app, "/")([](){
        return "Hello world";
    });

    app.port(18080).multithreaded().run();
}
reference

https://github.com/ipkn/crow
https://www.jianshu.com/p/e6ad3e505d5b
https://blog.csdn.net/qq_21567767/article/details/105911906
https://blog.csdn.net/zmyer/article/details/18963323

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值