why VC7 linker complains this undefined...

L

linq936

Hi,
I have some code like this,

h1.h:
class H1{
public:
const static string myStr;
};

h1.c:
#include "h1.h"

const string H1::myStr = "some string";

The 2 files, h1.h and h1.c are in one library, h1.lib.

Then I have this file in another library,h2.lib,

h2.c
#include "h1.h"

int r = some_function(H1::myStr);

In linking h2.lib I can see from the linking command that h1.lib is
linked, but I still get this link error,

h2.obj : error LNK2001: unresolved external symbol "public: static
class string const H1::myStr" (?myStr@H1@@2V?$string@D@@B)

Do you see what is wrong?
 
V

Victor Bazarov

I have some code like this,

h1.h:
class H1{
public:
const static string myStr;
};

h1.c:
#include "h1.h"

const string H1::myStr = "some string";

The 2 files, h1.h and h1.c are in one library, h1.lib.

Then I have this file in another library,h2.lib,

h2.c
#include "h1.h"

int r = some_function(H1::myStr);

In linking h2.lib I can see from the linking command that h1.lib is
linked, but I still get this link error,

h2.obj : error LNK2001: unresolved external symbol "public: static
class string const H1::myStr" (?myStr@H1@@2V?$string@D@@B)

Do you see what is wrong?

Nope. Perhaps you should try asking in a VC++ newsgroup...
I suggest 'microsoft.public.vc.language'.

V
 
A

Adrian

Either you forgot to add h1.c to your project or the compiler is confused by
your unorthodox choice of extension (i.e. "c" is for the C language, most
compilers associate a .cpp or .cxx extension with the C++ language).

Adrian
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top