小编Kua*_*hen的帖子

Makefile自动链接依赖?

让程序在编译时找出依赖关系很容易(使用gcc -MM).然而,链接依赖(决定应链接哪些库)似乎很难弄清楚.当需要具有要链接的单个库的多个目标时,此问题变得紧急.

例如,需要构建三个动态库目标t1.so,t2.so和t3.so.t1.so需要数学库(-lm),而t2和t3则不需要.编写单独的规则会很繁琐.需要与数学库链接的三个目标的单个规则可以省去麻烦.但是,由于数学库未用于t2.so和t3.so,因此会导致目标大小膨胀.

有任何想法吗?

dependencies gcc makefile linkage

5
推荐指数
1
解决办法
2338
查看次数

期待C++模板编程问题`;' 在'它'之前?

我正在编写一小段代码来执行基于策略的模板编程.在此程序中,定义了CDecayer类,它使用DecayerPolicy作为其策略类.然而,编译器抱怨"预期`;' 在'它'之前关于CDecayer部分.有什么建议?

#include <iostream>
#include <vector>
#include <map>
#include <utility>



int main()
{
}

struct CAtom
{
};

class CStateUpdater
{
public:
  virtual void UpdateState(CAtom* patom) = 0;
};


struct CDecayerPolicy
{
  typedef std::pair<unsigned int, unsigned int> indexpair;
  std::map<indexpair, double> mDecayRate;

  CDecayerPolicy()
  { 
    mDecayRate.clear();
  }

  ~CDecayerPolicy()
  {}
};



template<class DecayerPolicy>
class CDecayer: public DecayerPolicy, public CStateUpdater
{
public:
  virtual void UpdateState(CAtom* patom)
  {
    for(std::map<DecayerPolicy::indexpair, double >::const_iterator it =  DecayerPolicy::mDecayRate.begin(); it!= DecayerPolicy::mDecayRate.end(); it++)
      {
// atom state modification code …
Run Code Online (Sandbox Code Playgroud)

c++ templates

4
推荐指数
1
解决办法
5626
查看次数

标签 统计

c++ ×1

dependencies ×1

gcc ×1

linkage ×1

makefile ×1

templates ×1