unresolved external symbol

G

Guest

I have a .NET application that compiles but has a problem during linking :

error LNK2001: unresolved external symbol "int __cdecl ReadLn(struct _iobuf
*,char * const)" (?ReadLn@@$$FYAHPAU_iobuf@@QAD@Z)

The ReadLn function prototype is defined in a header file
& is called in another header file.
My compiler options are set to /Gd & /Tp.

If I do not call the function (& just have it's prototype declared),
then the program links fine.

When I try to resolve the ambiguity by explicitly calling the function
like namespace::function, I get an error saying that function is not a
member of namespace. This puzzles me since everywhere I look
(Classe View, Intellisense, Context Help) recognizes ReadLn as
a member of the my namespace.

Why is the linker confused on this function ?

Regards,
ak
 
G

Guest

You're probably missing a dependency.
Properties->Linker->Input->Additional Dependencies.

Hope this helps,
Mark.
 
G

Guest

Mark,

Thanks for the help, but there are no lib files to attach to the project.
I've scaled down the code to a bare minimum just to show the linker problem
with the ReadLn function but don't see a way to post the code - is it
possible to post source files on this newsgroup ?

Regards,
ak
 
G

Guest

In the scaled down version, I only have 3 files : Form1.cpp, Lab Test 2.h, &
Form2.h . The contents of Form1.cpp are :

#include "stdafx.h"
#include "Form2.h"
#include <windows.h>

using namespace K1;

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
Application::Run(new Form2());
return 0;
}

The contents of LabTest 2.h are :

#define MAX_DWELL_SAMPLES 1000

typedef unsigned short ushort;

#pragma pack(1)



#pragma pack()

/*
***********************
** Function prototypes
***********************
*/


int ReadLn(FILE *ifile, char line[]);


& the contents of Form2.h are :

#pragma once
#include <stdio.h>
#include <windows.h>
#include <math.h>
#include <sys/timeb.h>
#include <time.h>
#include "LabTest 2.h"


namespace K1
{

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;


int point_cnt = 0, dwell_samples = 0;
char ifname[80];
FILE *sfile;
char *timeline;
int i, retries;
struct _timeb timebuffer;
BOOL bStatus;


/// <summary>
/// Summary for Form2
///
/// WARNING: If you change the name of this class, you will need to change
the
/// 'Resource File Name' property for the managed resource
compiler tool
/// associated with all .resx files this class depends on.
Otherwise,
/// the designers will not be able to interact properly with
localized
/// resources associated with this form.
/// </summary>
public __gc class Form2 : public System::Windows::Forms::Form
{
public:
Form2(void)
{
InitializeComponent();
}

protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::Button * button1;





private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container* components;

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->button1 = new System::Windows::Forms::Button();
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::point(112, 112);
this->button1->Name = S"button1";
this->button1->Size = System::Drawing::Size(144, 48);
this->button1->TabIndex = 0;
this->button1->Text = S"test button";
this->button1->Click += new System::EventHandler(this, button1_Click);
//
// Form2
//
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(400, 254);
this->Controls->Add(this->button1);
this->Name = S"Form2";
this->Text = S"Form2";
this->ResumeLayout(false);

}


private: System::Void button1_Click(System::Object * sender,
System::EventArgs * e)
{

FILE *ifile;
int ret = FALSE, i, status;
char line[80];

ifile = fopen(ifname, "rt");
if (ifile == NULL) printf("Unable to open %s\n", ifname);
else
{
status = ReadLn(ifile, line);
if (status) sscanf(line, "%d", &dwell_samples);
if (dwell_samples > MAX_DWELL_SAMPLES) dwell_samples =
MAX_DWELL_SAMPLES;


i = 0;
status = ReadLn(ifile, line);
while (status)
{
status = ReadLn(ifile, line);
i++;
}
point_cnt = i;
ret = TRUE;
}
fclose(ifile);

}


};




int ReadLn(FILE *ifile, char line[])
{
int status, i = 0;
char buffer;

status = fread(&buffer, 1, 1, ifile);
while ((status) && (buffer != '\n') && (i < 80))
{
line[i++] = buffer;
status = fread(&buffer, 1, 1, ifile);
}
line = 0;

return status;
}

}

Regards,
ak


Nishant Sivakumar said:
Have you added the corresponding cpp file to the project?

--
Regards,
Nish [VC++ MVP]


AK said:
I have a .NET application that compiles but has a problem during linking :

error LNK2001: unresolved external symbol "int __cdecl ReadLn(struct
_iobuf
*,char * const)" (?ReadLn@@$$FYAHPAU_iobuf@@QAD@Z)

The ReadLn function prototype is defined in a header file
& is called in another header file.
My compiler options are set to /Gd & /Tp.

If I do not call the function (& just have it's prototype declared),
then the program links fine.

When I try to resolve the ambiguity by explicitly calling the function
like namespace::function, I get an error saying that function is not a
member of namespace. This puzzles me since everywhere I look
(Classe View, Intellisense, Context Help) recognizes ReadLn as
a member of the my namespace.

Why is the linker confused on this function ?

Regards,
ak
 
N

Nishant Sivakumar

In labtest2.h, the function should be declared as :-

namespace K1
{
int ReadLn(FILE *ifile, char line[]);
}

--
Regards,
Nish [VC++ MVP]


AK said:
In the scaled down version, I only have 3 files : Form1.cpp, Lab Test 2.h,
&
Form2.h . The contents of Form1.cpp are :

#include "stdafx.h"
#include "Form2.h"
#include <windows.h>

using namespace K1;

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
Application::Run(new Form2());
return 0;
}

The contents of LabTest 2.h are :

#define MAX_DWELL_SAMPLES 1000

typedef unsigned short ushort;

#pragma pack(1)



#pragma pack()

/*
***********************
** Function prototypes
***********************
*/


int ReadLn(FILE *ifile, char line[]);


& the contents of Form2.h are :

#pragma once
#include <stdio.h>
#include <windows.h>
#include <math.h>
#include <sys/timeb.h>
#include <time.h>
#include "LabTest 2.h"


namespace K1
{

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;


int point_cnt = 0, dwell_samples = 0;
char ifname[80];
FILE *sfile;
char *timeline;
int i, retries;
struct _timeb timebuffer;
BOOL bStatus;


/// <summary>
/// Summary for Form2
///
/// WARNING: If you change the name of this class, you will need to change
the
/// 'Resource File Name' property for the managed resource
compiler tool
/// associated with all .resx files this class depends on.
Otherwise,
/// the designers will not be able to interact properly with
localized
/// resources associated with this form.
/// </summary>
public __gc class Form2 : public System::Windows::Forms::Form
{
public:
Form2(void)
{
InitializeComponent();
}

protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::Button * button1;





private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container* components;

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->button1 = new System::Windows::Forms::Button();
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::point(112, 112);
this->button1->Name = S"button1";
this->button1->Size = System::Drawing::Size(144, 48);
this->button1->TabIndex = 0;
this->button1->Text = S"test button";
this->button1->Click += new System::EventHandler(this, button1_Click);
//
// Form2
//
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(400, 254);
this->Controls->Add(this->button1);
this->Name = S"Form2";
this->Text = S"Form2";
this->ResumeLayout(false);

}


private: System::Void button1_Click(System::Object * sender,
System::EventArgs * e)
{

FILE *ifile;
int ret = FALSE, i, status;
char line[80];

ifile = fopen(ifname, "rt");
if (ifile == NULL) printf("Unable to open %s\n", ifname);
else
{
status = ReadLn(ifile, line);
if (status) sscanf(line, "%d", &dwell_samples);
if (dwell_samples > MAX_DWELL_SAMPLES) dwell_samples =
MAX_DWELL_SAMPLES;


i = 0;
status = ReadLn(ifile, line);
while (status)
{
status = ReadLn(ifile, line);
i++;
}
point_cnt = i;
ret = TRUE;
}
fclose(ifile);

}


};




int ReadLn(FILE *ifile, char line[])
{
int status, i = 0;
char buffer;

status = fread(&buffer, 1, 1, ifile);
while ((status) && (buffer != '\n') && (i < 80))
{
line[i++] = buffer;
status = fread(&buffer, 1, 1, ifile);
}
line = 0;

return status;
}

}

Regards,
ak


Nishant Sivakumar said:
Have you added the corresponding cpp file to the project?

--
Regards,
Nish [VC++ MVP]


AK said:
I have a .NET application that compiles but has a problem during linking
:

error LNK2001: unresolved external symbol "int __cdecl ReadLn(struct
_iobuf
*,char * const)" (?ReadLn@@$$FYAHPAU_iobuf@@QAD@Z)

The ReadLn function prototype is defined in a header file
& is called in another header file.
My compiler options are set to /Gd & /Tp.

If I do not call the function (& just have it's prototype declared),
then the program links fine.

When I try to resolve the ambiguity by explicitly calling the function
like namespace::function, I get an error saying that function is not a
member of namespace. This puzzles me since everywhere I look
(Classe View, Intellisense, Context Help) recognizes ReadLn as
a member of the my namespace.

Why is the linker confused on this function ?

Regards,
ak
 
G

Guest

Yes - that does it !
Thank you for the help - this will remind me to protype functions within
the namespace of their use.

Regards,
ak

Nishant Sivakumar said:
In labtest2.h, the function should be declared as :-
namespace K1
{
int ReadLn(FILE *ifile, char line[]);
}

--
Regards,
Nish [VC++ MVP]


AK said:
In the scaled down version, I only have 3 files : Form1.cpp, Lab Test 2.h,
&
Form2.h . The contents of Form1.cpp are :

#include "stdafx.h"
#include "Form2.h"
#include <windows.h>

using namespace K1;

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
Application::Run(new Form2());
return 0;
}

The contents of LabTest 2.h are :

#define MAX_DWELL_SAMPLES 1000

typedef unsigned short ushort;

#pragma pack(1)



#pragma pack()

/*
***********************
** Function prototypes
***********************
*/


int ReadLn(FILE *ifile, char line[]);


& the contents of Form2.h are :

#pragma once
#include <stdio.h>
#include <windows.h>
#include <math.h>
#include <sys/timeb.h>
#include <time.h>
#include "LabTest 2.h"


namespace K1
{

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;


int point_cnt = 0, dwell_samples = 0;
char ifname[80];
FILE *sfile;
char *timeline;
int i, retries;
struct _timeb timebuffer;
BOOL bStatus;


/// <summary>
/// Summary for Form2
///
/// WARNING: If you change the name of this class, you will need to change
the
/// 'Resource File Name' property for the managed resource
compiler tool
/// associated with all .resx files this class depends on.
Otherwise,
/// the designers will not be able to interact properly with
localized
/// resources associated with this form.
/// </summary>
public __gc class Form2 : public System::Windows::Forms::Form
{
public:
Form2(void)
{
InitializeComponent();
}

protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::Button * button1;





private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container* components;

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->button1 = new System::Windows::Forms::Button();
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::point(112, 112);
this->button1->Name = S"button1";
this->button1->Size = System::Drawing::Size(144, 48);
this->button1->TabIndex = 0;
this->button1->Text = S"test button";
this->button1->Click += new System::EventHandler(this, button1_Click);
//
// Form2
//
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(400, 254);
this->Controls->Add(this->button1);
this->Name = S"Form2";
this->Text = S"Form2";
this->ResumeLayout(false);

}


private: System::Void button1_Click(System::Object * sender,
System::EventArgs * e)
{

FILE *ifile;
int ret = FALSE, i, status;
char line[80];

ifile = fopen(ifname, "rt");
if (ifile == NULL) printf("Unable to open %s\n", ifname);
else
{
status = ReadLn(ifile, line);
if (status) sscanf(line, "%d", &dwell_samples);
if (dwell_samples > MAX_DWELL_SAMPLES) dwell_samples =
MAX_DWELL_SAMPLES;


i = 0;
status = ReadLn(ifile, line);
while (status)
{
status = ReadLn(ifile, line);
i++;
}
point_cnt = i;
ret = TRUE;
}
fclose(ifile);

}


};




int ReadLn(FILE *ifile, char line[])
{
int status, i = 0;
char buffer;

status = fread(&buffer, 1, 1, ifile);
while ((status) && (buffer != '\n') && (i < 80))
{
line[i++] = buffer;
status = fread(&buffer, 1, 1, ifile);
}
line = 0;

return status;
}

}

Regards,
ak


Nishant Sivakumar said:
Have you added the corresponding cpp file to the project?

--
Regards,
Nish [VC++ MVP]


I have a .NET application that compiles but has a problem during linking
:

error LNK2001: unresolved external symbol "int __cdecl ReadLn(struct
_iobuf
*,char * const)" (?ReadLn@@$$FYAHPAU_iobuf@@QAD@Z)

The ReadLn function prototype is defined in a header file
& is called in another header file.
My compiler options are set to /Gd & /Tp.

If I do not call the function (& just have it's prototype declared),
then the program links fine.

When I try to resolve the ambiguity by explicitly calling the function
like namespace::function, I get an error saying that function is not a
member of namespace. This puzzles me since everywhere I look
(Classe View, Intellisense, Context Help) recognizes ReadLn as
a member of the my namespace.

Why is the linker confused on this function ?

Regards,
ak

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top