I downloaded Dev C++ from Bloodshed to compile and run my c++ code. One of my headers for my main.cpp is #include "stdafx.h"
Unfortunately, this is not recognized by Dev C++, so I added a header file named stdafx.h to the same folder where my main.cpp sits. I also included the header files referenced by my stdafx.h in the same folder. Is this the correct approach? Because when I go to compile my main.cpp, I am still getting the error that the header files (i.e., afxwin.h, afxext.h) for my stdafx.h cannot be found...
I would greatly appreciate your help as it has been several years since I coded in C++ and first time using Dev C++. Thank you in advance. I have included the text of my stdafx.h below.
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
The compiler error was:
C:\Documents and Settings\Guest BCox\My Documents\Dev C++\/stdafx.h:8:64: afxwin.h: No such file or directory
C:\Documents and Settings\Guest BCox\My Documents\Dev C++\/stdafx.h:9:46: afxext.h: No such file or directory
This guy wants to compile mfc code. The only way i know is by using Microsoft Visual C++. even if u dont want to buy the compiler u can still use the free express edition and Force it to compile MFC code:
Check out this link on compiling MFC code on the free Visualstudio express edition
follow the steps given...and voila!! your code executes, which is what u are looking for right?
wish u sucess :)
Please post your full Basic 3, they are covered in the thread titled "Please Read Before Posting a Question".
Now, one other thing. Code written for Microsoft compilers will usually not work out of the box.
stdafx.h is not 'available', it is project specific.
It is an automatically generated file created when you use the Project Wizard creation in Microsoft VC++ (where presumably this code came from). It serves almost no purpose other to martial precompiled headers (a feature that Dev-C++ does not have and is of dubious benefit in any case). Often it is not required, even in VC++, but the IDE creates it in any case. The cynical would suggest that it is a way of locking in users to their development tool by making code fail to build in other tools.
I suggest that you start by deleting the line that includes stdafx.h. It is possible that is all you need do; it depends on what functions your code calls. If it uses Win32 API calls, macros or structures, you will at least need <windows.h>. If it uses MFC classes (and the stdafx.h you posted indicates that it does), you haven't a hope, and will need a Microsoft tool. Note that the free MSCV++ 2008 Express does not support MFC, but the .NET is better in any case, regard MFC as deprecated.
Finally don't put your projects in "C:\Documents and Settings\Guest BCox\My Documents\Dev C++\"; Dev-C++ does not always play well with paths containing spaces.
I have changed the directory path as you will find in the compile log:
Compiler: Default compiler
g++.exe "C:\Dev-Cpp\Projects\SSP\main.cpp" -o "C:\Dev-Cpp\Projects\SSP\main.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
In file included from C:\Dev-Cpp\Projects\SSP\main.cpp:1:
C:\Dev-Cpp\Projects\SSP\/stdafx.h:8:64: afxwin.h: No such file or directory
C:\Dev-Cpp\Projects\SSP\/stdafx.h:9:46: afxext.h: No such file or directory
C:\Dev-Cpp\Projects\SSP\/stdafx.h:11:68: afxcmn.h: No such file or directory
C:\Dev-Cpp\Projects\SSP\main.cpp:8: error: _TCHAR' has not been declared
C:\Dev-Cpp\Projects\SSP\main.cpp:9: error: ISO C++ forbids declaration ofargv' with no type
_TCHAR' has not been declared
C:\Dev-Cpp\Projects\SSP\main.cpp:9: error: ISO C++ forbids declaration of
> I have changed the directory path as you will find in the compile log:
I recommend that you move c:\dev-cpp\projects to c:\projects or anywhere not within c:\dev-cpp. Apart from polluting the installation being a bad idea in any case, there is a known problem with Dev-C++ that sometimes causes builds to fail when in c:\dev-c++\ subfolders - don't ask me why!
Anyway, the suggestion was not intended as a solution, it is merely to avoid other unrelated problems later. You still have not removed the include (which was intended as a solution), or clarified whether or not this is an MFC project (in which case the solution won't work).
The header of my Main.cpp prgrm was
This .cpp is Levenberg-Marquardt routine/prgrm. It was written for Visual C++ 2005. It calls on the type `_TCHAR' that is found in the .h files referenced in stdafx.h. This prgrm runs on MS Visual Studio. I would like to use the code in Dev C++ as it is easier to use than Visual Studio. What should I do now?
Its like I am talking and you are not listening. Repeating your problem does not help. Answer the questions, perform the suggestions, post the results. It is unlikely that we will fix this in one step, but you have to do thr first step if we are to progress!
And as I have already said:
1) delete the line that includes stdafx.h.
2) Replace it with the necessary direct headers; you will at least need <windows.h>.
Without seeing the code I could not possible tell you what you actually need to include. And you still have not said whether it requires MFC? You cannot use Dev-C++ for MFC apps. So if you just answer that question, we may be able to decide to stop now and not waste time. If it turns out that it does require MFC after I asked twice, you will have wasted time.
> It calls on the type `_TCHAR' that is found in the .h files
> referenced in stdafx.h.
No it is not. At least not directly. Read the documentation: http://msdn.microsoft.com/en-us/library/c426s321(VS.71).aspx _TCHAR required <tchar.h> to be included. So now replace:
rebuild the code and post the log (assuming it fails), then we'll determine the next step.
Of course, the other question is why are you changing compilers? Visual Studio is hardly "hard to use", and when it comes to debugging is far superior, and that is probably where you spend most of your development effort.
Thank you for Clifford's detailed response. My header for my main.cpp is now:
And because the header file afxwin.h references over two dozen other header files, I have put these 27 header files in my director where afxwin.h resides (i.e., C:\Projects\SSP\C). But looking at the log, still it seems the compiler does not recognize or read these 27 header files.
Compiler: Default compiler
g++.exe "C:\Projects\SSP\main.cpp" -o "C:\Projects\SSP\main.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
In file included from C:\Projects\SSP\main.cpp:2:
C:\Projects\SSP\/afxwin.h:62:24: ofcglobals.h: No such file or directory
C:\Projects\SSP\/afxwin.h:63:20: CPoint.h: No such file or directory
C:\Projects\SSP\/afxwin.h:64:19: CSize.h: No such file or directory
C:\Projects\SSP\/afxwin.h:88:30: CFrameWnd_inline.h: No such file or directory
In file included from C:\Projects\SSP\main.cpp:2:
C:\Projects\SSP\/afxwin.h:98: error: expected `)' before '*' token
I think Clifford said this earlier, but if your code relies on
MFC stuff, it will not work with GCC.
> #include "afxwin.h" // MFC core and standard components
> #include "afxext.h" // MFC extensions
I give up! Three times I have explained that YOU CANNOT USE MFC IN DEV-C++!!! And you have consistently ignored that fact, and ignored my question about whether this project needs it.
Now it is possible (in fact likely) that you had MFC support enabled in Visual C++, but that you don't actually use it in this code.
Now I am telling you what to do, and you are doing other things instead. That is kind of missing teh point of asking for assistance!
Do EXACTLY this:
REMOVE the following lines:
and replace them with:
then build the code and post the log. If you do other stuff besides that which has been requested, you will screw up the experiment, and the results will not provide the information I am looking for in order to assist YOU.
Note that these instructions are not necessarily a solution, but an experiment. When it does not work, do not try to 'fix' it before posting the results - that will invalidate the experiment, and I will not be able to advise.
Log in to post a comment.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.