[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Linkning med g++ 3.2



Hejsa.

Jeg har for nyligt opgraderet til RedHat 8.0, og har tilsyneladende dermed fået sneget version 3.2 af gcc ind på
maskinen i stedet for RedHats egen 2.96, der lå der tidligere. Da jeg skulle kompilere et af mine gamle programmer
betød det så, at jeg var nødt til at løbe alle mine header-filer igennem for at få det stemt af med den
ANSI-standard, som 3.2 overholder. Det lykkedes mig at få alle mine .c og .cpp-filer til at bliver oversat til
object-kode.

Men med linkningen opstår der et problem, som helt sikkert er trivielt (og skyldes at jeg sikkert ikke overholder
ANSI). Jeg får tonsvis af følgende:

#> g++ test.cpp
/tmp/ccHKM5QK.o: In function `main':
/tmp/ccHKM5QK.o(.text+0x36): undefined reference to `CModel::CModel[in-charge](int, int*, int, int*)'
/tmp/ccHKM5QK.o(.text+0x62): undefined reference to `CModel::~CModel [in-charge]()'
/tmp/ccHKM5QK.o(.text+0x7f): undefined reference to `CModel::~CModel [in-charge]()'

Alle problemerne er i mine egne filer, så det lader ikke til at være et problem med forskellige versioner af libc
og gcc. Så vidt jeg kan se har jeg deklareret alle mine funktioner, så er der nogen, der kan fortælle mig, hvad
jeg skal lave om eller hvor jeg skal kigge for at blive klogere (eksempel vedlagt).

Mvh,

Claus



---[CUT: test.cpp ]---

#include <iostream>
#include <cstdlib>
#include "model.h"

main()
{
  std::cout << "Hej fra test.cpp\n";

  CModel test(1,NULL, 2, NULL);

  std::cout << "JDJD\n" ;
}

---[CUT: model.h ]---
#ifndef _MODEL_H_
#define _MODEL_H_

class CModel {
 private:
  int m_intercept;
  int m_nTraits;
  int m_nCovariates;
  int *m_traitnumbers;
  int *m_covariatenumbers;

 public:
  CModel();          // Default dummy constructor
  CModel(int ntraits, int traits[], int ncov, int cov[]); // Constructor

  virtual ~CModel(); // Destructor

  int nTraits();

  void Clear();
};

int AddTrait(CModel model);

#endif


---[CUT: model.cpp]
#include <cstdlib>
#include "model.h"

// Constructor
CModel::CModel()
{
  m_nTraits = 0;
  m_nCovariates = 0;

  m_traitnumbers = NULL;
  m_covariatenumbers = NULL;
}


CModel::CModel(int ntraits, int traits[], int ncov, int cov[])
{
  int i;

  m_intercept = 1;
  m_nTraits = ntraits;
  m_nCovariates = ncov;

  m_traitnumbers = new int[ntraits];
  m_covariatenumbers = new int[ncov];

  for (i = 0; i< ntraits; i++) {
    m_traitnumbers[i] = traits[i];
  }

  for (i = 0; i< ncov; i++) {
    m_covariatenumbers[i] = cov[i];
  }
}

CModel::~CModel()
{
  if (m_traitnumbers != NULL) {
    delete[] m_traitnumbers;
    m_traitnumbers = NULL;
  }
  if (m_covariatenumbers != NULL) {
    delete[] m_covariatenumbers;
    m_covariatenumbers = NULL;
  }

}



void CModel::Clear() {
  m_intercept = 1;
  if (m_traitnumbers != NULL) {
    delete[] m_traitnumbers;
    m_traitnumbers = NULL;
  }
  if (m_covariatenumbers != NULL) {
    delete[] m_covariatenumbers;
    m_covariatenumbers = NULL;
  }
}


int CModel::nTraits() {
  return m_nTraits;

}


int AddTrait(CModel model)
{
  int *newdata = new int[model.nTraits()+1];
  //  int i;

  delete[] newdata;
}




 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *