changing file from C to C++
Hello!!
I'm using MFC.
I'm using a sample which has C files.
I want to put some C++ code inside, and so, I have to change the name of the files from C to C++.
To do this, I rename the files in the Explorator, and in Visual Studio, I delete the file and then add the .cpp ones.
But when I've only done this, linking errors appear:
GradientImport.obj : error LNK2001: unresolved external symbol "void __cdecl DoAbout(struct AboutRecord *)" (?DoAbout@@YAXPAUAboutRecord@@@Z)
Am I doing wrong? Do someone know what I haver to do? Maybe change something in the Settings Project, but what?
:) :) :) :) :) :)
Thanks for any help...
Re: changing file from C to C++
You should read the help of the
extern "C" directive and Mixed-Language Programming with C++.
I hope this helps
Re: changing file from C to C++
Hi....
Thanks very much for your help yesterday.
As you have told me, I have used the extern "C" symbol in my GradientImport.cpp file like this :
extern "C"{
#include "GradientImport.h"
}
The link errors have almost all disappeared, except three of them which are :
libcmt.lib(atox.obj) : error LNK2005: _atol already defined in msvcrt.lib(MSVCRT.dll)
libcmt.lib(xtoa.obj) : error LNK2005: __ultoa already defined in msvcrt.lib(MSVCRT.dll)
Creating library .\Release/GradientImport.lib and object .\Release/GradientImport.exp
libcmt.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
I think that the 2 first ones must be easy to resolve, but I don’t know exactly how to do...
In my Project Settings, I have :
-for the C/C++ :
Use run-time library : Multithreaded
Calling convention : _cdecl
-for the Link :
Object/library modules : version.lib user32.lib kernel32.lib gdi32.lib msvcrt.lib
Ignore Libraries : libcmtd.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib
Do someone can help me?
Is there something I am doing wrong?
And for the third error, have you got any idea?
Thanks very much for any help....
:) :) :) :) :) :)
Thanks for any help...
Re: changing file from C to C++
Hi,
You included the Multithreaded static link library (LIBCMT) and the Multithreaded dynamic link library (MSVCRT), which is one to much. Remove your link MSVCRT and it should work. Have a look in the help "C Run-Time Debug Libraries".
In general I recommend to start with the Project AppWizard and to insert own source and header files into it. That is really much faster than the other way round.
Re: changing file from C to C++
Hi...
Thanks very much for your fast answer.
I have done like you have said, and now, I have just the last link error:
libcmt.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Do you think it can be a problem in my code?
This error appears when, after including <afx.h> at the top of my GradientImport.cpp, I’m doing this...
CFileDialog fileDlg(TRUE);
fileDlg.DoModal();
If I’m removing this 2 lines, the error disappears.
Do you know what does it mean?
(I’m sorry to interrupt you in your work if so...)
And I really thank you for all your advice.
Cecile.
:) :) :) :) :) :)
Thanks for any help...
Re: changing file from C to C++
Sorry, but I don't know the details of your project. Is it Unicode? Have you made a new project with the AppWizard, as I adviced you, and integrated your cpp and h files in it? If it is a MFC app. the wizard will generate the main stuff by itself.
So long - Ralf