开发者

Pesky Link Errors

I am using visual studio 2010 and believe I have a project settings issue. I have a header file that has some declarations in it:

definitions.h

#include <string>

struct myStruct
{
    std::string x[4];
    std::string y[8];
};

void InitializeStructData();

extern myStruct data[12];

and the cpp file initializes my structure:

definitions.cpp

#include "definitions.h"
#include <string>

mySturct data[12];

void InitializeStructData()
{
    data[0].x[0] = "a";
    data[0].x[1] = "b";
    ....
    data[0].y[0] = "a";
    ....
    ....
    data[11].y[7] = "done initializing"';
开发者_高级运维}

and I have a form that has some buttons and things whose text I populate from the arrays depending on different circumstances:

myForm.cpp

#include "definitions.h"

... 

//form initialization

As soon as I have two #include "definitions.h" statements I get link errors:

Error   1   error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * Definitions" 
Error   2   error LNK1169: one or more multiply defined symbols found


Your question is missing the important part.

You have a std::string* Definitions in a header, that you forgot to use extern with.


Do you have your code (.h file) inside:

#ifndef DEFINITIONS_H
#define DEFINITIONS_H

#endif

to help prevent you from defining it multiple times, if you have it included in multiple places?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜