-
April 14th, 2010, 10:45 PM
#1
LNK2028 and LNK2019 errors
Hi! I am not sure if I'm in the right forum so please correct me.
Anyway, I am new to VC++ and I can’t get why I keep on getting these linking errors:
Cosgen is the name of my project.
------ Build started: Project: Cosgen, Configuration: Debug Win32 ------
Compiling...
Cosgen.cpp
Linking...
Cosgen.obj : error LNK2028: unresolved token (0A000017) "public: void __clrcall Cosgen::LinesDraw::hello(void)" (?hello@LinesDraw@Cosgen@@$$FQAMXXZ) referenced in function "private: void __clrcall Cosgen::Form1::linesB_Click(class System::Object ^,class System::EventArgs ^)" (?linesB_Click@Form1@Cosgen@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
Cosgen.obj : error LNK2019: unresolved external symbol "public: void __clrcall Cosgen::LinesDraw::hello(void)" (?hello@LinesDraw@Cosgen@@$$FQAMXXZ) referenced in function "private: void __clrcall Cosgen::Form1::linesB_Click(class System::Object ^,class System::EventArgs ^)" (?linesB_Click@Form1@Cosgen@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
C:\SP_C++\Cosgen\Debug\Cosgen.exe : fatal error LNK1120: 2 unresolved externals
Build log was saved at "file://c:\SP_C++\Cosgen\Cosgen\Debug\BuildLog.htm"
Cosgen - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Here is my pseudocode:
//Form1.h
#include "LinesDraw.h" //I included the .h file
private: LinesDraw *ldraw;
ld = new LinesDraw; //I successfully made an object
ld->hello(); //and call the method from LinesDraw.h
//LinesDraw.h
void LinesDraw::hello();//hints that there is a method hello in LinesDraw
//LinesDraw.cpp
void LinesDraw::hello(){
int hello_num=3; //hello is implemented
)
Anyway, I want to implement it in the cpp file since I can’t run opengl functions in a .h file.
Form1.h is a managed file while LinesDraw.h is an unmanaged file.
Is it possible that I call a method in LinesDraw.h from Form1.h?
Also, I already tried putting __clrcall such as:
void __clrcall LinesDraw::hello();
and
void __clrcall LinesDraw::hello(){
int hello_num=3; //hello is implemented
)
But it didn’t work.
I’m really stuck right now and I don’t know what to do next.
So I will really appreciate it if you helped. Thanks!
-
April 15th, 2010, 12:30 AM
#2
Re: LNK2028 and LNK2019 errors
What is LinesDraw? Is this native C++ class? Please show more code to understand what happens.
-
April 15th, 2010, 02:53 AM
#3
Re: LNK2028 and LNK2019 errors
LinesDraw is an unmanaged file.
What's the difference between unmanaged file and native file anyway?
I thought they're the same.
Oh well, that shows how a newbie I am in C++.
Hoping to hear from you soon.
Thanks!
-
April 15th, 2010, 04:39 AM
#4
Re: LNK2028 and LNK2019 errors
Originally Posted by zole_ria9
What's the difference between unmanaged file and native file anyway?
Thanks!
Good question. If you ask it, you need to learn unmanaged (native) C++ first, then C#. Only after this, if necessary, start using C++/CLI for managed/unmanaged interoperability. There is no other reason for using C++/CLI. If you want to make user interface, do this in C#.
Regarding your question:
//Form1.h
#include "LinesDraw.h" //I included the .h file
private: LinesDraw *ldraw;
ld = new LinesDraw; //I successfully made an object
ld->hello(); //and call the method from LinesDraw.h
LinesDraw should be declared as:
class LinesDraw
{
public:
void hello();
}
...
What is your code exactly?
-
April 17th, 2010, 04:42 AM
#5
Re: LNK2028 and LNK2019 errors
So native (unmanaged file) is the one which we usually program in console?
I've already tried using them both, that is, C# and C++.
But what I did using them are simple programs.
I've also already used C# in making an interpreter with a UI
and C++ with opengl but only console based 3d like making a windows with a rotating triangle.
I thought that unmanaged file and native are just the same except that unmanaged file is referred to the VC++ counterpart of native files.
Here's my code:
I excluded the part which is generated by VC++ since it would be too long.
But I tried to include everything which will make it better to understand.
Cosgen.cpp : main project file and will call Form1.h which is the main UI
Code:
#include "stdafx.h"
#include "Form1.h"
#include "LinesDialog.h"
#include "LinesDraw.h"
using namespace Cosgen;
[STAThreadAttribute]
int main(array<System::String ^> ^args){
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
Form1.h --> this is the main UI, this will call LinesDialog.h
--> as you can see Form1.h needs the values of
checkedSL = ld->sLinesRB->Checked;
checkedCL = ld->cLinesRB->Checked;
checkedZZL = ld->zzLinesRB->Checked;
which is on LinesDialog.h
--> after that, Form1.h would then call LinesDraw.h and call this function:
void LinesDraw::hello();
which is implemented in LinesDraw.cpp using
void LinesDraw::hello(){
//3d functions here using opengl
}
Code:
#pragma once
#include <iostream>
#include "LinesDialog.h"
#include "LinesDraw.h"
#include "ShapesDialog.h"
using namespace std;
#using <mscorlib.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
namespace Cosgen {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class Form1 : public System::Windows::Forms::Form
{
private: System::Windows::Forms::Label^ colorL;
public: System::Windows::Forms::Label^ sample;
bool checkedSL;
bool checkedCL;
bool checkedZZL;
private: System::Windows::Forms::ColorDialog^ colorDialog1;
public: Form1(void){InitializeComponent();}
protected:
~Form1(){ if (components){ delete components; } }
//declarations of tools that I've used such as:
//--> private: System::Windows::Forms::MenuStrip^ menuStrip1;
//lots of declarations like this here:
//--> private: System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void){
//I erased the codes generated by VC++ but retained samples such as:
// -->System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
//-->this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
}
#pragma endregion
private: System::Void linesB_Click(System::Object^ sender, System::EventArgs^ e) {
LinesDialog^ ld = gcnew LinesDialog;
Form1^ myForm = gcnew Form1;
LinesDraw *ldraw = new LinesDraw;
if(ld->ShowDialog() == System::Windows::Forms::DialogResult::OK){
checkedSL = ld->sLinesRB->Checked;
if(checkedSL==true) {
sample->Text="Straight Lines Selected";
ldraw->hello(); //this here is an unresolved external
}
else {sample->Text="Nothing Selected"; }
}
}
private: System::Void shapesB_Click(System::Object^ sender, System::EventArgs^ e) {
ShapesDialog^ sd = gcnew ShapesDialog;
sd->ShowDialog();
}
private: System::Void colorsB_Click(System::Object^ sender, System::EventArgs^ e) {
colorDialog1->ShowDialog();
colorL->Text::set(this->colorDialog1->Color::get().ToString());
panel3->BackColor::set(this->colorDialog1->Color::get());
}
};
}
LinesDialog.h
Code:
#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
#include <iostream>
#include "stdafx.h"
#include "LinesDraw.h"
using namespace std;
#using <mscorlib.dll>
namespace Cosgen {
public ref class LinesDialog : public System::Windows::Forms::Form {
public:
bool checkedSL;
bool checkedCL;
bool checkedZZL;
LinesDialog(void){ InitializeComponent(); }
protected:
~LinesDialog(){
if (components){delete components;}
}
//declaration of objects/tools here such as -->
//--> private: System::Windows::Forms::Button^ submitLDB;
//--> private: System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void){
//initialize here such as -->
//-->this->ResumeLayout(false);
//-->this->PerformLayout();
}
#pragma endregion
private: System::Void submitLDB_Click(System::Object^ sender, System::EventArgs^ e) {}
};
}
LinesDraw.h
Code:
#pragma once
#include <iostream>
#include "stdafx.h"
using namespace std;
namespace Cosgen{
public class LinesDraw{
public:
LinesDraw(void){//constructor}
~LinesDraw(){//destructor}
void LinesDraw::hello();
//additional class calls here
};
}
LinesDraw.cpp
Code:
#include "stdafx.h"
#define GLUT_DISABLE_ATEXIT_HACK
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glaux.h>
#include <GL/glut.h>
#include "LinesDraw.h"
class LinesDraw{
public:
LinesDraw();
~LinesDraw();
void hello();
int num;
};
LinesDraw::LinesDraw(){ num=1; }
LinesDraw::~LinesDraw(){ num=0; }
void LinesDraw::hello(){ int hello_num=0; }
But if you want to see the whole project I can show it to you through email.
-
April 17th, 2010, 07:43 AM
#6
Re: LNK2028 and LNK2019 errors
void LinesDraw::hello(){ int hello_num=0; }
This function belongs to the LinesDraw class declared in the same .cpp file. LinesDraw class required by Form1 should belong to Cosgen namespace. To correct this, remove LinesDraw class declaration from LinesDraw.cpp and add this line instead:
using namespace Cosgen;
-
April 18th, 2010, 10:55 PM
#7
Re: LNK2028 and LNK2019 errors
When I did something like this in my LinesDraw.cpp:
Code:
#include "stdafx.h"
#define GLUT_DISABLE_ATEXIT_HACK
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glaux.h>
#include <GL/glut.h>
#include "LinesDraw.h"
using namespace Cosgen;
class LinesDraw{
public:
LinesDraw();
~LinesDraw();
//void hello();
int num;
};
LinesDraw::LinesDraw(){num=1;}
LinesDraw::~LinesDraw(){num=0;}
//void LinesDraw::hello(){ int hello_num=0; }
An error like this occurs:
------ Build started: Project: Cosgen, Configuration: Debug Win32 ------
Compiling...
LinesDraw.cpp
.\LinesDraw.cpp(23) : error C2872: 'LinesDraw' : ambiguous symbol
could be '.\LinesDraw.cpp(15) : LinesDraw'
or 'c:\sp_c++\cosgen\cosgen\LinesDraw.h(17) : Cosgen::LinesDraw'
.\LinesDraw.cpp(27) : error C2872: 'LinesDraw' : ambiguous symbol
could be '.\LinesDraw.cpp(15) : LinesDraw'
or 'c:\sp_c++\cosgen\cosgen\LinesDraw.h(17) : Cosgen::LinesDraw'
Cosgen.cpp
Generating Code...
Build log was saved at "file://c:\SP_C++\Cosgen\Cosgen\Debug\BuildLog.htm"
Cosgen - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I also tried to change things in my LinesDraw.h and Form1.h but nothing seems to work.
Also, if this would run then where would I implement the things that I want to be done?
-
April 19th, 2010, 01:14 AM
#8
Re: LNK2028 and LNK2019 errors
Remove LinesDraw class definition from LinesDraw.cpp !
Code:
#include "stdafx.h"
#define GLUT_DISABLE_ATEXIT_HACK
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glaux.h>
#include <GL/glut.h>
#include "LinesDraw.h"
using namespace Cosgen;
/*
class LinesDraw{
public:
LinesDraw();
~LinesDraw();
//void hello();
int num;
};
*/
LinesDraw::LinesDraw(){num=1;}
LinesDraw::~LinesDraw(){num=0;}
void LinesDraw::hello(){ int hello_num=0; }
-
April 20th, 2010, 01:47 AM
#9
Re: LNK2028 and LNK2019 errors
Hi thanks for all the help.
I already solved this problem.
I was wrong in declaring the classes in my LinesDraw.h
Instead of what I did before, it should be something like this:
Code:
#pragma once
#include <iostream>
#include "stdafx.h"
using namespace std;
namespace Cosgen{
public class LinesDraw{
public:
LinesDraw::LinesDraw();
LinesDraw::~LinesDraw();
void LinesDraw::hello();
};
}
and my LinesDraw.cpp should be something like this.
Code:
#include "stdafx.h"
#define GLUT_DISABLE_ATEXIT_HACK
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glaux.h>
#include <GL/glut.h>
#include "LinesDraw.h"
class LinesDraw{
public:
LinesDraw();
~LinesDraw();
void hello();
};
Cosgen::LinesDraw::LinesDraw(){ int num=1; }
Cosgen::LinesDraw::~LinesDraw(){ int num=0; }
void Cosgen::LinesDraw::hello(){ int hello_num=0; }
I really thank you without your help I wouldn't be able to solve this.
Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|