Note that there are some explanatory texts on larger screens.

plurals
  1. POerror LNK2010 in visual c, cannot call method in other project file
    text
    copied!<blockquote> <p>error LNK2019: unresolved external symbol "char * __cdecl BytesToString(unsigned char const *,unsigned int)" (?BytesToString@@YAPADPBEI@Z) referenced in function _wmain C:\Users\anandada\Documents\Visual Studio 2010\Projects\ByteToString\ByteToString\ByteToString.obj ByteToString</p> </blockquote> <p>above is the error I am getting. code is shown below. ByteToString is a console Win32 application and Utility is Win32 DLL.</p> <blockquote> <p>Utility.c</p> </blockquote> <pre><code>#include "stdafx.h" #include "Utility.h" #include "stdlib.h" char* BytesToString( const unsigned char* PpcbBytes, const unsigned int PuiNoOfBytes) { unsigned char bRetVal = 0; unsigned int ctr = 0; char* PpszString = NULL; int len=0; do { PpszString=(char*)calloc(PuiNoOfBytes*3+1,sizeof(char)); if(NULL==PpszString) break; len=5; } while(0); return PpszString; } </code></pre> <blockquote> <p>Utility.h</p> </blockquote> <pre><code>#ifndef _UTILITY_H #define _UTILITY_H __declspec(dllexport) char* BytesToString( const unsigned char* PpcbBytes, const unsigned int PuiNoOfBytes); #endif </code></pre> <blockquote> <p>ByteToString.cpp</p> </blockquote> <pre><code>// ByteToString.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "string.h" #include "stdlib.h" #include "..\Utility\Utility.h" int _tmain(int argc, _TCHAR* argv[]) { unsigned char pbArray[5]={0x41,0x42,0x43,0x44,0x45}; char* pbExpArray=NULL; unsigned int Flag=1; int len=0; pbExpArray=BytesToString(pbArray,5); free(pbExpArray); Flag=strcmp("41 42 43 44 45 ",pbExpArray); len=strlen(pbExpArray); return 0; } </code></pre> <p>I have set project properties like this:</p> <p>both ByteToString and Utility project calling conventions are: __cdecl</p> <p>In ByteToString, Linker->General->Additional Directories: $(OutDir)</p> <p>(I tried this too Linker->General->Additional Directories:$(SolutionDir)$(Configuration)\ )</p> <p>In ByteToString, Linker->Input->Additional Dependenicies: Utility.lib</p> <p>I aslo tried this,</p> <pre><code>#ifndef _UTILITY_H #define _UTILITY_H extern "C" { __declspec(dllexport) char* BytesToString( const unsigned char* PpcbBytes, const unsigned int PuiNoOfBytes); } #endif </code></pre> <p>This gives error:</p> <blockquote> <p>error C2059: syntax error : 'string'</p> </blockquote> <p>Update:</p> <ol> <li>While creating project, I had added <strong>Utility.cpp</strong>. I renamed it to <strong>Utility.c</strong>, set the project properties and compiled. I got the error shown above. </li> <li>Then I renamed it back to <strong>Utility.cpp</strong> and compiled. No error.</li> </ol> <p>Why is this? I want <strong>Utility</strong> file in <strong>.c</strong>. What is the correct method to add a <strong>.c</strong> file into project?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload