返回列表 回复 发帖

大家帮忙看看困扰了我一个月的错误~~~

共有文件3个:Broker.h  Broker.C mds.C
Broker.h
#ifndef ITSO_BROKER_H
#define ITSO_BROKER_H
/* gris-search.c*/
#include "globus_common.h"
/* LDAP stuff */
#include "lber.h"
#include "ldap.h"
#include <string>
#include <vector>
#include <list>
#include <algorithm>
/* note this should be the GIIS server,but it could be the
   GRIS server if you are only talking to a local machine
   remember the port numbers are different */
#define GRID_INFO_HOST "gridhost"
#define GRID_INFO_PORT "2135"
#define GRID_INFO_BASEDN "mds-vo-name=gridhost.cauglobus.edu,o=grid"
namespace itso_broker {
void GetLinuxNodes(vector<string>& res,int n);
}
#endif
Broker.C
/* gris_search.c */
#include "globus_common.h"
#include "globus_gram_client.h"
/* LDAP stuff */
#include "lber.h"
#include "ldap.h"
#include <string>
#include <vector>
#include <algorithm>
#include "Broker.h"
/* note this should be the GIIS server,but it could be the
   GRIS server if you are only talking to a local machine
   remember the port numbers are different */
#define GRID_INFO_HOST "gridhost"
#define GRID_INFO_PORT "2135"
#define GRID_INFO_BASEDN "mds-vo-name=gridhost.cauglobus.edu,o=grid"
namespace itso_broker {
class Host {
   string hostname;
   long cpu;
   public:
   Host(string h,int c):hostname(h),cpu(c) {};
   ~Host() {};
   string getHostname() { return hostname; };
   int getCpu() { return cpu; };
};
bool predica(Host* a,Host* b) {
  return (a->getCpu() > b->getCpu());
}
void GetLinuxNodes(vector<string>& res,int n)
{
   LDAP * ldap_server;
   LDAPMessage * reply;
   LDAPMessage * entry;
   char * attrs[1];
   char * server=GRID_INFO_HOST;
   int port=atoi(GRID_INFO_PORT);
   char * base_dn=GRID_INFO_BASEDN;
   /* list of attributes that we want included in the search result*/
   attrs[0]=GLOBUS_NULL;
   globus_module_activate(GLOBUS_GRAM_CLIENT_MODULE);
   /* Open connection to LDAP server */
   if ((ldap_server=ldap_open(server,port))==GLOBUS_NULL)
   {
      ldap_perror(ldap_server,"ldap_open");
      exit(1);
    }
    /* Bind to LDAP server */
    if (ldap_simple_bind_s(ldap_server,"","")!=LDAP_SUCCESS)
    {
       ldap_perror(ldap_server,"ldap_simple_bind_s");
       ldap_unbind(ldap_server);
       exit(1);
     }
     /* do the search to find all the linux available nodes */
     //string filter="(objectClass=MdsComputer)(Mds-Os-name=Linux)";
     string filter="(&(Mds-Os-name=Linux)(Mds-Host-hn=*))";
     if(ldap_search_s(ldap_server,base_dn,
                       LDAP_SCOPE_SUBTREE,
                       const_cast<char*>(filter.c_str()),attrs,0,
                       &reply)!=LDAP_SUCCESS)
      {
          ldap_perror(ldap_server,"ldap_search");
          ldap_unbind(ldap_server);
          exit(1);
       }
       vector<Host*> nodes;
       /* go through the entries returned by the LDAP server.for each
          entry,we must search for the right attribute and then get the
          value associated with it */
       for (entry=ldap_first_entry(ldap_server,reply);
            entry!=GLOBUS_NULL;
            entry=ldap_next_entry(ldap_server,entry))
       {
          //cout << endl << ldap_get_dn(ldap_server,entry) << endl;
          BerElement * ber;
          char** values;
          char * attr;
          char * answer=GLOBUS_NULL;
          string hostname;
          int cpu;
          int cpu_nb;
          long speed;
          for (attr=ldap_first_attribute(ldap_server,entry,&ber);
               attr!=NULL;
               attr=ldap_next_attribute(ldap_server,entry,ber))
          {
             values=ldap_get_values(ldap_server,entry,attr);
             answer=strdup(value[0]);
             ldap_value_free(values);
             if (strcmp("Mds-Host-hn",attr)==0)
                hostname=answer;
             if (strcmp("Mds-Cpu-Free-15minX100",attr)==0)
                cpu=atoi(answer);
             if (strcmp("Mds-Cpu-Total-count",attr)==0)
                cpu_nb=atoi(answer);
             if (strcmp("Mds-Cpu-speedMHz",attr)==0)
                speed=atoi(answer);
             // printf("%S %s%\n",attr,answer);
           }
           //chech if we can really use this node
           if (!globus_gram_client_ping(hostname.c_str()))
              nodes.push_back(new Host(hostname,speed*cpu_nb*cpu/100));
           };
           sort(nodes.begin(),nodes.end(),predica);
           vector<Host*>::iterator i;
           for(i=nodes.begin();(n>0)&&(i!=nodes.end());n--,i++){
              res.push_back((*i)->getHostname());
              //cout << (*i)->getHostname() << "" << (*i)->getCpu() << endl;
              delete *i;
            }
            for(;i!=nodes.end();++i)
               delete *i;
            ldap_unbind(ldap_server);
            globus_module_deactivate(GLOBUS_GRAM_CLIENT_MODULE);
       } /* get_ldap_attribute */
       }
mds.C
#include <string>
#include <vector>
#include <Broker.h>
using namespace itso_broker;
int main(int argc,char ** argv)
{  
         vector<string> Y;
         GetLinuxNodes(Y,atoi(argv[1]));
   vector<string>::iterator i;
   for(i=Y.begin();i!=Y.end();++i)
      cout << *i << endl;
}
我的makefile文件为mds.make:

include globus_header

all: mds

%.o: %.C
        g++ -g -c -I. $(GLOBUS_CPPFLAGS) $< -o $@

mds: mds.o Broker.o
        g++ -g -o $@ $(GLOBUS_CPPFLAGS)  $(GLOBUS_LDFLAGS) $^  $(GLOBUS_PKG_LIBS)

其中globus_header是包含我要调用的globus平台提供的API

当我执行make -f mds.make时,错误如下:

g++ -g -c -I. -I/usr/local/globus/globusroot/include -I/usr/local/globus/globusroot/include/gcc32dbg Broker.C -o Broker.o
In file included from /usr/include/g++-3/std/bastring.h:36,
                 from /usr/include/g++-3/string:6,
                 from Broker.C:7:
/usr/include/g++-3/std/straits.h: In function `char
*string_char_traits<char>::move (char *, const char *, unsigned int)':
/usr/include/g++-3/std/straits.h:129: cannot convert `bcopy(s2, s1, n)'
from type `void' to type `char *'
make: *** [Broker.o] Error 1

烦请大家帮忙看看究竟是什么问题啊,困扰了我一个月了,毕业设计要完不成了,呜呜
fedora core6上是用strings.h这个文件了
我的red hat 7.3里是用string.cpp,所以格式为include <string> ,写成include <string.h>会报错的
返回列表