Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Problème lors de la compilation

3 réponses
Avatar
Davy Duriatti
Je débute en Visual C++, et je rencontre un problème de compilation que je
n'arrive pas à résoudre.
Lors de la compilation, l'erreur est la suivante:

Compiling...
Complexe.cpp
Fonction.cpp
MathFunc.cpp
SIMULATION.CPP
Linking...
SIMULATION.OBJ : error LNK2001: unresolved external symbol "public:
__thiscall CFonction<double>::~CFonction<double>(void)"
(??1?$CFonction@N@@QAE@XZ)
SIMULATION.OBJ : error LNK2001: unresolved external symbol "public:
__thiscall CFonction<double>::CFonction<double>(class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> >,double,double,long)" (??0?$CFonction@N@@QAE@V
?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@NNJ@Z)
Debug/TRY.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

SIMULATION.exe - 3 error(s), 0 warning(s)

Je joint le bout de code qui semble poser problème...
Auriez-vous une solution à cette erreur ? Je vous remercie d'avance pour
votre aide...

Davy

////////////////////////
// FICHIER FONCTION.H //
////////////////////////
#if
!defined(AFX_FONCTION_H__9855AB89_EE90_440C_953F_D56FFF26DBDB__INCLUDED_)
#define AFX_FONCTION_H__9855AB89_EE90_440C_953F_D56FFF26DBDB__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <string>
#include "Complexe.h"

template <class _T> class CFonction
{
public:
CFonction(std::string Stg,_T Lint,_T Uint,long nbPts);
~CFonction();
_T Integre(_T XMin,_T XMax);
_T Derive(_T ValX);
_T Eval(_T VAR);
std::string m_Expr;

private:
long m_nbPts;
_T m_Uint;
_T m_Lint;
_T *m_ord;
_T *m_abs;
int m_nbChar;
bool Conversion(std::string ch);
_T Valeur(int i,_T VAR);
_T Term(int i,_T VAR);
_T Nmbre(int i,_T VAR);
int *m_T;
std::string m_Fonctions;
int m_P;
};

#endif //
!defined(AFX_FONCTION_H__9855AB89_EE90_440C_953F_D56FFF26DBDB__INCLUDED_)


//////////////////////////
// FICHIER FONCTION.CPP //
//////////////////////////

#include "Fonction.h"
#include <string>
#include <tchar.h>
#include <math.h>
#include <iostream.h>

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

template<class _T> CFonction<_T>::CFonction(std::string Stg,_T Lint,_T
Uint,long nbPts)
{
m_Lint=Lint;
m_Uint=Uint;
m_nbPts=nbPts;
int k=0;
m_abs=new _T[m_nbPts];
m_ord=new _T[m_nbPts];
m_Fonctions="cos240sin241tan242atn243log244exp245sqr246";
for (int i=0;i<Stg.size();i++)
{
k++;
char str=Stg[i];
if (str>='a' && str<='z' && str!='x') i=i+2;
}
m_nbChar=k+1;
m_Expr=Stg;
m_T=new int[m_nbChar];
Conversion(m_Expr);
m_P=0;
for(int j=0;j<m_nbPts;j++)
{
m_abs[j]=Lint+j*((Uint-Lint)/(nbPts-1));
m_ord[j]=Eval(m_abs[j]);
}
}

template<class _T> CFonction<_T>::~CFonction()
{
delete[] m_abs;
delete[] m_ord;
}

3 réponses

Avatar
.oO LGV Oo.
"Davy Duriatti" a écrit dans le message de
news:bnp43m$ofb$
Je débute en Visual C++, et je rencontre un problème de compilation que je
n'arrive pas à résoudre.
Lors de la compilation, l'erreur est la suivante:

Compiling...
Complexe.cpp
Fonction.cpp
MathFunc.cpp
SIMULATION.CPP
Linking...
SIMULATION.OBJ : error LNK2001: unresolved external symbol "public:
__thiscall CFonction<double>::~CFonction<double>(void)"
(??1?$@@)
SIMULATION.OBJ : error LNK2001: unresolved external symbol "public:
__thiscall CFonction<double>::CFonction<double>(class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> >,double,double,long)" (??0?$@@
?$?$@std@@V?$@2@@std@@)
Debug/TRY.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

SIMULATION.exe - 3 error(s), 0 warning(s)

Je joint le bout de code qui semble poser problème...
Auriez-vous une solution à cette erreur ? Je vous remercie d'avance pour
votre aide...

Davy

////////////////////////
// FICHIER FONCTION.H //
////////////////////////
#if
!defined(AFX_FONCTION_H__9855AB89_EE90_440C_953F_D56FFF26DBDB__INCLUDED_)
#define AFX_FONCTION_H__9855AB89_EE90_440C_953F_D56FFF26DBDB__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <string>
#include "Complexe.h"

template <class _T> class CFonction
{
public:
CFonction(std::string Stg,_T Lint,_T Uint,long nbPts);
~CFonction();
_T Integre(_T XMin,_T XMax);
_T Derive(_T ValX);
_T Eval(_T VAR);
std::string m_Expr;

private:
long m_nbPts;
_T m_Uint;
_T m_Lint;
_T *m_ord;
_T *m_abs;
int m_nbChar;
bool Conversion(std::string ch);
_T Valeur(int i,_T VAR);
_T Term(int i,_T VAR);
_T Nmbre(int i,_T VAR);
int *m_T;
std::string m_Fonctions;
int m_P;
};

#endif //
!defined(AFX_FONCTION_H__9855AB89_EE90_440C_953F_D56FFF26DBDB__INCLUDED_)


//////////////////////////
// FICHIER FONCTION.CPP //
//////////////////////////

#include "Fonction.h"
#include <string>
#include <tchar.h>
#include <math.h>
#include <iostream.h>

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

template<class _T> CFonction<_T>::CFonction(std::string Stg,_T Lint,_T
Uint,long nbPts)
{
m_Lint=Lint;
m_Uint=Uint;
m_nbPts=nbPts;
int k=0;
m_abs=new _T[m_nbPts];
m_ord=new _T[m_nbPts];
m_Fonctions="cos240sin241tan242atn243log244exp245sqr246";
for (int i=0;i<Stg.size();i++)
{
k++;
char str=Stg[i];
if (str>='a' && str<='z' && str!='x') i=i+2;
}
m_nbChar=k+1;
m_Expr=Stg;
m_T=new int[m_nbChar];
Conversion(m_Expr);
m_P=0;
for(int j=0;j<m_nbPts;j++)
{
m_abs[j]=Lint+j*((Uint-Lint)/(nbPts-1));
m_ord[j]=Eval(m_abs[j]);
}
}

template<class _T> CFonction<_T>::~CFonction()
{
delete[] m_abs;
delete[] m_ord;
}






implémenter les méthodes templates dans le .h devrait résoudre ton problème

Avatar
Jacti

Je débute en Visual C++, et je rencontre un problème de compilation que je
n'arrive pas à résoudre.
Lors de la compilation, l'erreur est la suivante:


Ce n'est pas un problème de compilation mais une erreur de link (édition de
lien)
car les erreurs se produisent après la ligne "Linking..."
Par exemple, la deuxième erreur provient d'un appel à CFonction avec 5
paramètres
alors que CFonction n'en a que 4.

Compiling...
Complexe.cpp
Fonction.cpp
MathFunc.cpp
SIMULATION.CPP
Linking...
SIMULATION.OBJ : error LNK2001: unresolved external symbol "public:
__thiscall CFonction<double>::~CFonction<double>(void)"
(??1?$@@)
SIMULATION.OBJ : error LNK2001: unresolved external symbol "public:
__thiscall CFonction<double>::CFonction<double>(class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> >,double,double,long)" (??0?$@@
?$?$@std@@V?$@2@@std@@)
Debug/TRY.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

SIMULATION.exe - 3 error(s), 0 warning(s)

Je joint le bout de code qui semble poser problème...
Auriez-vous une solution à cette erreur ? Je vous remercie d'avance pour
votre aide...

Davy

////////////////////////
// FICHIER FONCTION.H //
////////////////////////
#if
!defined(AFX_FONCTION_H__9855AB89_EE90_440C_953F_D56FFF26DBDB__INCLUDED_)
#define AFX_FONCTION_H__9855AB89_EE90_440C_953F_D56FFF26DBDB__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <string>
#include "Complexe.h"

template <class _T> class CFonction
{
public:
CFonction(std::string Stg,_T Lint,_T Uint,long nbPts);
~CFonction();
_T Integre(_T XMin,_T XMax);
_T Derive(_T ValX);
_T Eval(_T VAR);
std::string m_Expr;

private:
long m_nbPts;
_T m_Uint;
_T m_Lint;
_T *m_ord;
_T *m_abs;
int m_nbChar;
bool Conversion(std::string ch);
_T Valeur(int i,_T VAR);
_T Term(int i,_T VAR);
_T Nmbre(int i,_T VAR);
int *m_T;
std::string m_Fonctions;
int m_P;
};

#endif //
!defined(AFX_FONCTION_H__9855AB89_EE90_440C_953F_D56FFF26DBDB__INCLUDED_)

//////////////////////////
// FICHIER FONCTION.CPP //
//////////////////////////

#include "Fonction.h"
#include <string>
#include <tchar.h>
#include <math.h>
#include <iostream.h>

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

template<class _T> CFonction<_T>::CFonction(std::string Stg,_T Lint,_T
Uint,long nbPts)
{
m_Lint=Lint;
m_Uint=Uint;
m_nbPts=nbPts;
int k=0;
m_abs=new _T[m_nbPts];
m_ord=new _T[m_nbPts];
m_Fonctions="cos240sin241tan242atn243log244exp245sqr246";
for (int i=0;i<Stg.size();i++)
{
k++;
char str=Stg[i];
if (str>='a' && str<='z' && str!='x') i=i+2;
}
m_nbChar=k+1;
m_Expr=Stg;
m_T=new int[m_nbChar];
Conversion(m_Expr);
m_P=0;
for(int j=0;j<m_nbPts;j++)
{
m_abs[j]=Lint+j*((Uint-Lint)/(nbPts-1));
m_ord[j]=Eval(m_abs[j]);
}
}

template<class _T> CFonction<_T>::~CFonction()
{
delete[] m_abs;
delete[] m_ord;
}


Jacti

Avatar
B. Monsuez
Le problème que tu as, c'est que quand tu instancies CFonction<double>,
le compilateur ne connait que les déclaration et non le code. Il ne te
dis rien ce qui est normal, il part du principe que tu lui fournira ce
code là au moment de l'édition de lien.
Mais comme tu n'as jamais instancier les méthodes présentes dans le
fichiers .cpp elles ne sont jamais crées, donc elle manque au moment de
l'édition de liens.
Donc, soit tu dis au compilateur d'instancier spécifiquement la classe
pour CFonction<double> soit au contrairer, tu inclus le fichier .cpp en
même temps que le fichier .h.

Cordialement


Davy Duriatti wrote:

Je débute en Visual C++, et je rencontre un problème de compilation que je
n'arrive pas à résoudre.
Lors de la compilation, l'erreur est la suivante:

Compiling...
Complexe.cpp
Fonction.cpp
MathFunc.cpp
SIMULATION.CPP
Linking...
SIMULATION.OBJ : error LNK2001: unresolved external symbol "public:
__thiscall CFonction<double>::~CFonction<double>(void)"
(??1?$@@)
SIMULATION.OBJ : error LNK2001: unresolved external symbol "public:
__thiscall CFonction<double>::CFonction<double>(class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> >,double,double,long)" (??0?$@@
?$?$@std@@V?$@2@@std@@)
Debug/TRY.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

SIMULATION.exe - 3 error(s), 0 warning(s)

Je joint le bout de code qui semble poser problème...
Auriez-vous une solution à cette erreur ? Je vous remercie d'avance pour
votre aide...

Davy

////////////////////////
// FICHIER FONCTION.H //
////////////////////////
#if
!defined(AFX_FONCTION_H__9855AB89_EE90_440C_953F_D56FFF26DBDB__INCLUDED_)
#define AFX_FONCTION_H__9855AB89_EE90_440C_953F_D56FFF26DBDB__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <string>
#include "Complexe.h"

template <class _T> class CFonction
{
public:
CFonction(std::string Stg,_T Lint,_T Uint,long nbPts);
~CFonction();
_T Integre(_T XMin,_T XMax);
_T Derive(_T ValX);
_T Eval(_T VAR);
std::string m_Expr;

private:
long m_nbPts;
_T m_Uint;
_T m_Lint;
_T *m_ord;
_T *m_abs;
int m_nbChar;
bool Conversion(std::string ch);
_T Valeur(int i,_T VAR);
_T Term(int i,_T VAR);
_T Nmbre(int i,_T VAR);
int *m_T;
std::string m_Fonctions;
int m_P;
};

#endif //
!defined(AFX_FONCTION_H__9855AB89_EE90_440C_953F_D56FFF26DBDB__INCLUDED_)


//////////////////////////
// FICHIER FONCTION.CPP //
//////////////////////////

#include "Fonction.h"
#include <string>
#include <tchar.h>
#include <math.h>
#include <iostream.h>

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

template<class _T> CFonction<_T>::CFonction(std::string Stg,_T Lint,_T
Uint,long nbPts)
{
m_Lint=Lint;
m_Uint=Uint;
m_nbPts=nbPts;
int k=0;
m_abs=new _T[m_nbPts];
m_ord=new _T[m_nbPts];
m_Fonctions="cos240sin241tan242atn243log244exp245sqr246";
for (int i=0;i<Stg.size();i++)
{
k++;
char str=Stg[i];
if (str>='a' && str<='z' && str!='x') i=i+2;
}
m_nbChar=k+1;
m_Expr=Stg;
m_T=new int[m_nbChar];
Conversion(m_Expr);
m_P=0;
for(int j=0;j<m_nbPts;j++)
{
m_abs[j]=Lint+j*((Uint-Lint)/(nbPts-1));
m_ord[j]=Eval(m_abs[j]);
}
}

template<class _T> CFonction<_T>::~CFonction()
{
delete[] m_abs;
delete[] m_ord;
}







--
B. Monsuez
-------------------------------------------------
Ingénieur-Expert --- Cabinet d'ingénièrie Monsuez
Sureté des logiciels/composants
Compilation/Analyse statique