warning: exception of type ‘std::bad_alloc’ will be caught catch(bad_alloc e){ cout << e.what() << endl;} ^~~~~ warning: by earlier handler for ‘std::exception’ catch (exception e){ cout << e.what() << endl;}
catch语句块不能随意乱安排。派生类型的异常放在前面,基类异常应该放在最后
1 2 3 4 5 6 7 8 9 10 11 12 13
intmain() { try { throwDerivedException(); } catch (DerivedException& e) { // Handle derived class first std::cerr << "Caught DerivedException: " << e.what() << std::endl; } catch (BaseException& e) { // Then handle base class std::cerr << "Caught BaseException: " << e.what() << std::endl; } return0; }
So, go ahead and install distcc on the server computer (in my case, the desktop)
And then spin up the server. (The following assumes I’m on the 10.8.33.0 subnet, and I’m allowing all hosts on that subnet to send jobs)
1
sudo distccd --log-file=/tmp/distccd.log --daemon -a 10.8.33.0/24
Setting up distcc (client) So, now you have to tell ccache to use the distcc distributed compilation servers. To do this, just add the following line to your ~/.bashrc file.
1
export CCACHE_PREFIX=distcc
Next, we have to tell distcc where to go to find the server. This also, just add to the bottom of your ~/.bashrc (my desktop is at 10.8.33.182 and it has 8 cores, my laptop is at localhost and has 4)
1
export DISTCC_HOSTS='localhost/4 10.8.33.182/8'
在另一个终端,使用下面命令检验ccache的运行效果
1
watch -n1 'ccache -s -v'
或者watch -n1 'ccache --show-stats -v'
编译时,使用top看 distcc process starts spooling up its threads.
/* * @tparam T point type * @param first Given the starting point of a line segment * @param last The endpoint of a given line segment * @param third Given point * @return T Distance from point to line */ template <typename T> static T PointToLineDistance(const Point<T>& first, const Point<T>& last, const Point<T>& third){ float dis_suqare = ((first.y - last.y) * third.x + (last.x - first.x) * third.y + (first.x * last.y - last.x * first.y)) * ((first.y - last.y) * third.x + (last.x - first.x) * third.y + (first.x * last.y - last.x * first.y)) / ((last.x - first.x) * (last.x - first.x) + (last.y - first.y) * (last.y - first.y)); return std::sqrt(dis_suqare); }