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
Hi Kai, [quoted text, click to view] > 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?
The header with the prototype seems to be in place, otherwise the compiler would have told you [quoted text, click to view] > This is the method the compiler obviously doesn't like:
According to your error description the linker is giving the error, not the compiler, right? [quoted text, click to view] > > 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 > > }
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
Hi Kai, [quoted text, click to view] > On 7 Sep., 18:09, "SvenC" <Sv...@community.nospam> wrote: >> Hi Kai, >> >>> 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? >>>... >>> 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 >> >>> } >> >> 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. > > Would be a simple result but unfortunately it wasn't that easy. Header > files are added to project.
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] > By the way it's a cpp project.
What is a cpp project? -- SvenC
[quoted text, click to view] On 7 Sep., 18:09, "SvenC" <Sv...@community.nospam> wrote: > Hi Kai, > > > 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? > > The header with the prototype seems to be in place, otherwise the compiler > would have told you > > > This is the method the compiler obviously doesn't like: > > According to your error description the linker is giving the error, not the > compiler, right? > > > > > 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 > > > } > > 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
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.
[quoted text, click to view] On 8 Sep., 11:44, "SvenC" <Sv...@community.nospam> wrote: > Hi Kai, > > > > > On 7 Sep., 18:09, "SvenC" <Sv...@community.nospam> wrote: > >> Hi Kai, > > >>> 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? > >>>... > >>> 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 > > >>> } > > >> 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. > > > Would be a simple result but unfortunately it wasn't that easy. Header > > files are added to project. > > 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. > > > By the way it's a cpp project. > > What is a cpp project? > > -- > SvenC
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
Don't see what you're looking for? Try a search.
|