Erreur edition de liens: jeton et symbole externe non résolu avec Visual C++ Express
Bonjour,
j'essaye d'appeler dans un projet windows form une fonction (MaFonction)définie dans un fichier .cpp externe (cette meme fonction déplacée dans le fichier contenant le main fonctionne, j'ai bien un problème à l'appeler dans un fichier différent en mode Windowsform)
En mode console (j'ai créé deux projets différents et copié/collé simplement les bouts de code qu'y m'intéresse) tout va bien mais en mode Windows form l'édition de liens me jette avec cette erreur:
>Édition des liens en cours...
1>Xtern.obj : error LNK2028: jeton non résolu (0A000011) "void __cdecl
MaFonction(void)" (?MaFonction@@$$FYAXXZ) référencé dans la fonction
"private: void __clrcall Xtern::Form1::button1_Click(class System::Object
^,class System::EventArgs ^)"
(?button1_Click@Form1@Xtern@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>Xtern.obj : error LNK2019: symbole externe non résolu "void __cdecl
MaFonction(void)" (?MaFonction@@$$FYAXXZ) référencé dans la fonction
"private: void __clrcall Xtern::Form1::button1_Click(class System::Object
^,class System::EventArgs ^)"
(?button1_Click@Form1@Xtern@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
mon projet est très simple (j"ai isolé mon problème) mais je ne m'en sors
pas le projet Visual est ici :http://cjoint.com/?ckkiFf2gdP, les sources plus bas si quelqu'un avait la bonté de m'aider :)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
// Xtern.cpp*: fichier projet principal.
#include "stdafx.h"
#include "Form1.h"
#include "Game.h"
using namespace Xtern;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Activation des effets visuels de Windows*XP avant la création de tout contrôle
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Créer la fenêtre principale et l'exécuter
AllocConsole();
freopen("CONOUT$", "wb", stdout);
Application::Run(gcnew Form1());
return 0;
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
// Game.cpp: mon fichier externe
#include <stdio.h>
#include <windows.h>
#include "stdafx.h"
#include "Game.h"
class Game{
public:
Game();
~Game();
void MaFonction();
};
void Game::MaFonction() { printf("coucou\n"); } |
Code:
1 2 3 4 5 6 7 8 9
|
//Game.h
#ifndef _GAME_H
#define _GAME_H
class Game;
#endif |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
//Form1.h lié à ma fenêtre comportant un seul bouton pour appeler MaFonction()
#pragma once
#include "Game.h"
extern void MaFonction();
namespace Xtern {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Description résumée de Form1
///
/// AVERTISSEMENT*: si vous modifiez le nom de cette classe, vous devrez modifier la
/// propriété 'Nom du fichier de ressources' de l'outil de compilation de ressource managée
/// pour tous les fichiers .resx dont dépend cette classe. Dans le cas contraire,
/// les concepteurs ne pourront pas interagir correctement avec les ressources
/// localisées associées à ce formulaire.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO*: ajoutez ici le code du constructeur
//
}
protected:
/// <summary>
/// Nettoyage des ressources utilisées.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
protected:
private:
/// <summary>
/// Variable nécessaire au concepteur.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(73, 55);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(146, 74);
this->button1->TabIndex = 0;
this->button1->Text = L"GO";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 266);
this->Controls->Add(this->button1);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
printf("Olivier was there\n");
MaFonction();
}
};
} |
merci par avance
Olivier