473,382 Members | 1,107 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Linking error

Okay, everything seems simple enough but I get the following Link error:

TeXt.obj : error LNK2001: unresolved external symbol "private: static char *
TextDB::TextDB::myVersion" (?myVersion@TextDB@1@0PADA)

My environment is Visual Studio .NET, I think it's C++ 7 from the microsoft
visual studio versioning point of view.

Here is TeXt.h:

// Annoying MSVC++ warning:
#pragma warning( disable : 4290 )

// TeXt - Standalone Pure Text Database Management System

#ifndef TEXT_DB
#define TEXT_DB

#define TEXT_MAJOR_REVISION 1
#define TEXT_MINOR_REVISION 0
#define TEXT_BUILD 0

/*
Revision History:
-----------------
1.0.1

---------
- Created. I've run into too many situations
where something like this would have been
useful.
*/

//#include <bool.h>
#include <string>
#include <stdexcept>
/*

// If no bool.h, uncomment:
typedef short int bool;
#ifndef false
#define false 0
#endif
#ifndef true
#define true 1
#endif
*/

namespace TextDB
{
class TextDB
{
public:
// Constructors/Destructor:
TextDB(const std::string filename) throw(std::invalid_argument);
~TextDB();
TextDB(const TextDB &copy) throw(std::invalid_argument);

static const char *getVersion();
private:
// Private because it is illogical to instantiate a
// TextDB object without a filename
TextDB();

void initialize(std::string in_filename)
throw(std::invalid_argument);

std::string filename;
static char myVersion[20];
}; // class TextDB
} // namespace TextDB

#endif // #ifndef TEXT_DB

AND then here is TeXt.cpp:

//#include <bool>
#include <string>
#include <fstream>
#include "TeXt.h"
namespace TextDB
{
TextDB::TextDB(const std::string filename)
{
initialize(filename);
}

TextDB::~TextDB()
{
}

TextDB::TextDB(const TextDB &copy)
{
initialize(copy.filename);
}

const char *TextDB::getVersion()
{
return myVersion;
}

void TextDB::initialize(std::string in_filename)
{
sprintf(myVersion, "%d.%d.%d", TEXT_MAJOR_REVISION,
TEXT_MINOR_REVISION, TEXT_BUILD);
std::ifstream infile(filename.c_str(), std::ios_base::in);
if(!infile.is_open())
{
throw std::invalid_argument("Could not open database file <" +
filename + ">");
}
this->filename = in_filename;
infile.close();
} // initialize()
} // namespace TextDB

I'm sure the answer is simple, but I can't see it obviously.

Thank you very much!

Kevin Grigorenko
Jul 19 '05 #1
4 5249

"Kevin Grigorenko" <kz****@psu.edu> wrote in message news:bj***********@f04n12.cac.psu.edu...
static char myVersion[20];


This is only a declaration.

You must also define it. Put

char TextDB::myVersion[20];

inside the namespace TextDB in your cpp file.
Jul 19 '05 #2

Kevin Grigorenko <kz****@psu.edu> wrote in message
news:bj***********@f04n12.cac.psu.edu...
Okay, everything seems simple enough but I get the following Link error:

TeXt.obj : error LNK2001: unresolved external symbol "private: static char * TextDB::TextDB::myVersion" (?myVersion@TextDB@1@0PADA)

My environment is Visual Studio .NET, I think it's C++ 7 from the microsoft visual studio versioning point of view.

Here is TeXt.h: [snip] namespace TextDB
{
class TextDB
{
public:
// Constructors/Destructor:
TextDB(const std::string filename) throw(std::invalid_argument);
~TextDB();
TextDB(const TextDB &copy) throw(std::invalid_argument);

static const char *getVersion();
private:
// Private because it is illogical to instantiate a
// TextDB object without a filename
TextDB();

void initialize(std::string in_filename)
throw(std::invalid_argument);

std::string filename;
static char myVersion[20];


This is only a declaration, it's not a defintion.
No storage is reserved. Do this in your implementation
file (inside your namespace 'TextDB':

char TextDB::myVersion[20];

I'd recommend replacing that char array with a std::string.

-Mike

Jul 19 '05 #3
"Ron Natalie" <ro*@sensor.com> wrote in message
news:3f***********************@news.newshosting.co m...

"Kevin Grigorenko" <kz****@psu.edu> wrote in message news:bj***********@f04n12.cac.psu.edu...
static char myVersion[20];


This is only a declaration.

You must also define it. Put

char TextDB::myVersion[20];

inside the namespace TextDB in your cpp file.


Thanks, that did it. So any variables declared static must explicitly be
defined? Can this be done inline?

Kevin Grigorenko
Jul 19 '05 #4

"Kevin Grigorenko" <kz****@psu.edu> wrote in message news:bj***********@f04n12.cac.psu.edu...
Thanks, that did it. So any variables declared static must explicitly be
defined?
Yes
Can this be done inline?


No, with the exception of static integral constants. The implementations need
the definition to figure out which module actually allocates the storage for the
variable. This all harps back to an age old issue as to whether C (or C++)
could define the same data in multiple object files and have the linker fold
them all into the same object. The early C linkers did support this, but the
powers that were decided to not require this (although any linker that could
do seperate compilation of Fortran (common blocks) had to have the capability).
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Wolfgang | last post by:
I have a problem with linking my CPP Code under a irix6 machine (sgi, UNIX). In my CPP code I use some Functions which are written in Python. So its a kind of CPP wrapper for my Python functions In...
3
by: Saurabh Aggrawal | last post by:
Hi, I am porting an application for 64-bit AMD processor and while linking the application i am getting the following errors: Processing directory uidll... Linking DLL...
7
by: wmkew | last post by:
Hello everyone I'm encountering a R6002 Runtime error and several bugs when trying to generate a simple Managed C++ application with .NET 2003. The main problem seems to arise from linking with...
1
by: Joannes Vermorel | last post by:
I am currently trying to port a small open source scientfic library written in C++ to .Net. The code (including the VS solution) could be found at http://www.vermorel.com/opensource/selfscaling.zip...
1
by: Kay | last post by:
I already specified to ignore specific library: MSVCPRT.lib MSVCRT.lib LIBC.lib MSVCRTD.lib LIBCD.lib command line is like: /INCREMENTAL /NOLOGO /DLL /NODEFAULTLIB:"MSVCPRT.lib MSVCRT.lib LIBC.lib...
4
by: Sanjay Kumar | last post by:
Folks ! I am working with VC++ after a long time and having problem linking latest xerces 2.7 in VC++ 2005 Express Edition. I have done following: 1. downloaded and unpacked the the...
0
by: Adam Clauss | last post by:
I have managed C++ library (is bridging between a Win32 .dll and a C# application). All was well when compiled under VS2003, but I am running into a series of linking errors when compiling...
0
by: Philip Lowman | last post by:
I am in the process of trying to migrate a couple of build solutions to Visual Studio Express 2005 from VS 2003 Professional and I am running into a weird C/C++ runtime library linking issue when...
0
by: xieml2007 | last post by:
Dear Madam or Sir, I encountered one problem which is quite similiar to the discussions launched at the web site: http://www.thescripts.com/forum/thread280324.html
0
by: dotyet | last post by:
Hi Everyone, I am trying to build a DB2 UDB UDF which can perform regex over the table data. The user defined function will call an external .dll file to do the task. I am referring to the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.