Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / November 2005

Tip: Looking for answers? Try searching our database.

unresolved external symbol

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AK - 07 Nov 2005 22:43 GMT
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
Mark - 07 Nov 2005 23:08 GMT
You're probably missing a dependency.
Properties->Linker->Input->Additional Dependencies.

Hope this helps,
Mark.

> I have a .NET application that compiles but has a problem during linking :
>
[quoted text clipped - 18 lines]
> Regards,
> ak
AK - 08 Nov 2005 15:20 GMT
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

> You're probably missing a dependency.
> Properties->Linker->Input->Additional Dependencies.
[quoted text clipped - 24 lines]
> > Regards,
> > ak
Nishant Sivakumar - 08 Nov 2005 15:24 GMT
Have you added the corresponding cpp file to the project?

Signature

Regards,
Nish [VC++ MVP]

>I have a .NET application that compiles but has a problem during linking :
>
[quoted text clipped - 19 lines]
> Regards,
> ak
AK - 08 Nov 2005 15:58 GMT
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[i] = 0;

 return status;
}

}

Regards,
ak

> Have you added the corresponding cpp file to the project?
>
[quoted text clipped - 21 lines]
> > Regards,
> > ak
Nishant Sivakumar - 08 Nov 2005 17:06 GMT
In labtest2.h, the function should be declared as :-

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

Signature

Regards,
Nish [VC++ MVP]

> In the scaled down version, I only have 3 files : Form1.cpp, Lab Test 2.h,
> &
[quoted text clipped - 209 lines]
>> > Regards,
>> > ak
AK - 08 Nov 2005 17:34 GMT
Yes - that does it !
Thank you for the help - this will remind me to  protype functions within
the namespace of their use.

Regards,
ak

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

> namespace K1
> {
[quoted text clipped - 214 lines]
> >> > Regards,
> >> > ak

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.