Groups | Blog | Home
all groups > visual c libraries > september 2007 >

visual c libraries : c++: unresolved external symbol...


Kai
9/7/2007 8:55:50 AM
Hi guys,

I wrote a class witch should be used with windows and linux.

After compiling the project with vs2005 I get an error:

Error 1 error LNK2019: unresolved external symbol "int const
__cdecl
mstrcpy(char *,int,char *)" (?mstrcpy@@YA?BHPADH0@Z) referenced in
function "public: __thiscall CStr::CStr(class CStr &)" (??
0CStr@@QAE@AAV0@@Z) cstr.obj

Concerning to that error message I forgot to define a header or is
there anything else incorrect in my code?

This is the method the compiler obviously doesn't like:

const errno_t mstrcpy(char* dest, size_t len, char* src)
{
#ifdef __WIN32__
return strcpy_s(dest,len,src);
#elif __unix__
return (errno_t)((strncpy(dest,src,(size_t)len)!=NULL)?
0:1);
#else
return (errno_t)1;
#endif

}

my header looks like that:

#ifdef __WIN32__
#include "stdafx.h"
#ifndef __STDIO_H
#define __STDIO_H
#endif

#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <errno.h>

using namespace std;

Thanks a lot in advance.

Bye
Kai
SvenC
9/7/2007 6:09:03 PM
Hi Kai,

[quoted text, click to view]

The header with the prototype seems to be in place, otherwise the compiler
would have told you

[quoted text, click to view]

According to your error description the linker is giving the error, not the
compiler, right?
[quoted text, click to view]

The above is defined in a cpp or c file, right? I guess you forgot to add
that cpp or c file to your project, hence the linker does not find the
implementation.

--
SvenC
SvenC
9/8/2007 12:00:00 AM
Hi Kai,

[quoted text, click to view]

The header is not the problem, that holds only the declaration. The problem
is the missing definition of mstrcpy.
Where is the definition? Is it a cpp which is part of the project or is it a
separate lib?
If it is a separate lib then you have to add it to
Project->Properties->Linker.

[quoted text, click to view]

What is a cpp project?

--
SvenC
Kai
9/8/2007 2:31:26 AM
[quoted text, click to view]

Would be a simple result but unfortunately it wasn't that easy. Header
files are added to project.
By the way it's a cpp project.
Kai
9/8/2007 4:02:09 AM
[quoted text, click to view]
By writing cpp project I do mean a visual studio c++ project
solutiion.

the definition was wrong:
definition had char*, int, char* as parameters and the method required
char*, size_t, char*

a real beginner fault. embarrassing for me...

thank you for your help.

Cya
Kai
AddThis Social Bookmark Button