473,785 Members | 2,794 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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@Tex tDB@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_REVI SION 1
#define TEXT_MINOR_REVI SION 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::inva lid_argument);
~TextDB();
TextDB(const TextDB &copy) throw(std::inva lid_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::inva lid_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(file name);
}

TextDB::~TextDB ()
{
}

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

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

void TextDB::initial ize(std::string in_filename)
{
sprintf(myVersi on, "%d.%d.%d", TEXT_MAJOR_REVI SION,
TEXT_MINOR_REVI SION, TEXT_BUILD);
std::ifstream infile(filename .c_str(), std::ios_base:: in);
if(!infile.is_o pen())
{
throw std::invalid_ar gument("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 5271

"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::myVersi on[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@Tex tDB@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::inva lid_argument);
~TextDB();
TextDB(const TextDB &copy) throw(std::inva lid_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::inva lid_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::myVersi on[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.newshosti ng.com...

"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::myVersi on[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
1726
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 my Python Code I use threads to communicate over the network and stuff like this. Compilation and linking are working very well under Windows and Linux with the same code. Under the sgi, UNIX machine some errors occur and I don't no why....
3
14547
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 G:\NewUIPackers1\drivers\Unser\bin\WIN32\DEBUG\PPKAW1UI.dll .... LINK : warning LNK4224: /PDBTYPE is no longer supported; ignored UIDLL.def : error LNK2001: unresolved external symbol DllCanUnloadNow
7
6553
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 LIBCMT(D).DLL. (My requirement is that we can't link with MSVCRT(D).LIB.) Below are steps I've followed, and the resulting problems 1. Using the New Project wizard, generate a Visual C++ .NET Class Library project (call it "Doomed") and a VC++...
1
8121
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 My problem is that when I try to compile the library I got a list of linking error messages. I am not a specialist of porting C++ code to .Net. Does anyone has an idea on how to make this code compile in .Net ? Thanks, Joannes Vermorel
1
9486
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 MSVCRTD.lib LIBCD.lib" but I am still getting conflict linking problems. But if I do specify /NODEFAULTLIB, I'll get anther bunch of linking errors. Anybody knows why? thanks,
4
6412
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 library: http://www.apache.org/dist/xml/xerces-c/binaries/xerces-c_2_7_0-windows_2000-msvc_60.zip
0
4887
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 against VS2005. They all/mostly seem to be within the STL. Any idea what might cause something like this? Linking errors follow. ---
0
2557
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 using the /MT compilation option. Our debug solution's /MTd flag works fine and using /MD also seems to work ok. For some reason I can't fathom, when I use /MT, linking the static excutable completely dies (problems resolving symbols in the STL,...
0
3984
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
2971
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 following link for doing so: http://www.ibm.com/developerworks/db2/library/techarticle/0301stolze/0301stolze.html While linking the below mentioned code, I am facing some errors. I have installed PCRE and am using Visual C++ 6.0 in 32-bit mode. The
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10329
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8974
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.