The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Compile Errors...
Discuss Compile Errors... in the C Programming forum on Dev Shed. Compile Errors... C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 12th, 2005, 08:03 PM
|
|
Registered User
|
|
Join Date: Mar 2005
Posts: 3
Time spent in forums: 44 m 13 sec
Reputation Power: 0
|
|
|
Compile Errors...
I am using DevC++ 4.9.9.0 , and there is an issue that I have been experiencing ever since I started using it. This is the problem:
When I download someone else's source code, and try to compile it in DevC++, I get compile errors.
Now I know thats a bit vague, but to be a little more specific, the code was normally originally written and tested in borland. Also, I don't seem to experience problems when I just write programs from scratch(though I have not done anything complex at all). I can give you an example of a program that gave some compile errors.
If you go to URL and download 'Win32 Example (II)' , that is a program that gives me errors.
Also if it makes a difference, I am on WinXP Pro.
So to get to the point, I was wondering if someone could help me out here. Thanks!
Sincerely,
---------
|

March 12th, 2005, 08:18 PM
|
 |
Renaissance Redneck
|
|
Join Date: Jan 2004
Location: Central New York. Texan via Arizona, out of his element!
|
|
|
That's a Visual C++ project requiring a resource compiler, etc. Precisely how are you trying to use it?
__________________
Functionality rules and clarity matters; if you can work a little elegance in there, you're stylin'.
If you can't spell "u", "ur", and "ne1", why would I hire you? 300 baud modem? Forget I mentioned it.
DaWei on Pointers Politically Incorrect.
|

March 12th, 2005, 10:32 PM
|
|
Registered User
|
|
Join Date: Mar 2005
Posts: 3
Time spent in forums: 44 m 13 sec
Reputation Power: 0
|
|
|
Boy I feel dumb...Yeah you are right that was a Visual C++ project. Oops. However upon trying another that was *not* it still did not work. The new one that I tried was "GIF View" at URL .
It also gives me a huge list of errors when I try to compile.
|

March 13th, 2005, 04:27 AM
|
|
Contributing User
|
|
Join Date: Jul 2004
Posts: 337

Time spent in forums: 1 Day 9 h 34 m 56 sec
Reputation Power: 9
|
|
|
can you post your errors?
Use code tags as described in the post for new users at the top of the forum topics
|

March 13th, 2005, 05:44 AM
|
 |
Contributing User
|
|
Join Date: Aug 2003
Location: UK
|
|
Quote: | Originally Posted by JesusFreak Boy I feel dumb...Yeah you are right that was a Visual C++ project. Oops. However upon trying another that was *not* it still did not work. The new one that I tried was "GIF View" at http://www.cplusplus.com/src/ .
It also gives me a huge list of errors when I try to compile. |
Don't feel dumb, there is no problem. Dev-C++ can handle resource scripts (.rc files) using the GNU windres.exe tool that is included as part of the package.
The GIF View project is also MSVC++ (the .dsp file is the giveaway). Dev-C++ can import DSP files via File->Import...
After that you will probably encounter a number of common problems. Dev-C++ uses the MinGW/GCC compiler. The GCC version with your version of Dev-C++ is I believe 3.2. GCC strongly supports and enforces the ISO C++ standard, MSVC++ is much more relaxed and permissive. Also in some instances it just breaks the rules (with respect to scoping of variables declared within a 'for' statement for example).
Depending on the quality of the original code (in terms of its ISO adherence), you will almost certainly need to do some porting to get the code to run.
The first thing to do is either fix the headers to use the 'extensionless' versions such as <iostream> in place of <iostream.h>, or add the -Wno-deprecated option to the C++ options. I suggest the latter initially, and fix the code later whan compiling large amounts of third-party code - life's too short to get pedantic! However any new code you write should use the non-deprecated form. In this case it is actually one header at fault (<ifstream.h>), so you choose!
Where you see code like:
Code:
for (int n=0;n<nImages;n++) pTempImg[n]=img[n];
and the variable n is used outside of the loop, move the declaration outside of the loop:
Code:
int n ;
for (n=0;n<nImages;n++) pTempImg[n]=img[n]; // (pointer copy)
Add the following declaration after including standard headers:
Code:
using namespace std ;
- in ISO C++ the standard libarary is in the std namespace.
After doing the above on GIF View, two errors remained (actually more than two messages but they were duplicates of the same errors).
Code:
error: `nocreate' is not a member of `std::ios'
warning: multi-character character constant
Well indeed ios::nocreate is not part of the ISO library, and is not supported by MinGW. I simply removed it without consideration of teh semantic consequences for the code, but it is probably OK!
The multi-character warnings are surprising, I have never seen code like that and am surprised it is only a warning. I suggest rewriting the code. Change 'MB' to ('M' << 8) | 'B' and
Code:
bmpfile.write((char*)'\0\0\0\0',4);
to
Code:
{
char nulls[4] = { 0, 0, 0, 0 } ;
bmpfile.write(nulls,4);
}
GIF View will then compile, link, and run.
In general however, the approach here is not to get overawed by the quantity of errors. Fix them one at a time, reading and understanding each error message in turn. Notice that the raft of error messages in the original code were all fixed in just five steps - there were only five actual errors!
You might also bare in mind that any source code you may find on the Internet is not necessarily of the highest quality, even when it comes from a respected source! You should be highly critical and suspicious of any such code if you are using it as a learning example.
Clifford
Last edited by clifford : March 13th, 2005 at 05:49 AM.
|

March 14th, 2005, 12:55 PM
|
|
Registered User
|
|
Join Date: Mar 2005
Posts: 3
Time spent in forums: 44 m 13 sec
Reputation Power: 0
|
|
Thanks Clifford. Umm... how do I do this:
Quote: | add the -Wno-deprecated option to the C++ options |
Also, with the ifstream.h thing you mentioned -- in the code it is originally called 'fstream.h'. When I tried changing it to ifstream.h I got a 'no such file or directory' error. Did I just miss something, or do I not have a file I need, or what.
Also, I was unsure what you meant by this. Could you give me an example?
Quote: Add the following declaration after including standard headers:
Code:
using namespace std ;
|
Thanks. Also if anyone still wants to see, here is the error log when I tried to compile that gifview program:
URL
I must sound really new---which I am with C++. Just as a little background though I have used huge amounts of Javascript--which has some similar aspects. And I have done a ton with classes, objects, etc. It's just that there's *just* enough difference between these two languages that I find C++ hard to pickup. (especially understanding those error messages--goodness.)
Not by any means am I saying this to try to impress you(truly it is a sad resume indeed), I just thought that I should fill you in a little on my background with programming(or in my case scripting).
From what I understand there is a large amount of uncompatibility for code between different compilers. If I'm just getting started would it be wiser to use Borland simply because it is more widely used. Even on tutorial sites I have encountered errors with the lesson code. What would you suggest?
|

March 14th, 2005, 02:22 PM
|
|
Contributing User
|
|
Join Date: Jul 2004
Posts: 337

Time spent in forums: 1 Day 9 h 34 m 56 sec
Reputation Power: 9
|
|
For the using namespace thing, you simply put that after your #includes, like this:
Code:
#include <someinclude> // With no .h at the end
#include <somemore>
using namespace std; // Now, if a namepsace is not specified, the compiler assumes it is the std:: one
other code begins here!
|

March 14th, 2005, 02:31 PM
|
 |
Renaissance Redneck
|
|
Join Date: Jan 2004
Location: Central New York. Texan via Arizona, out of his element!
|
|
|
Javascript syntax is similar to C because it is derivative. The similarity virtually ends there. I have two C/C++ compilers from MS, one from Borland, and the Dev-Cpp model (Mingw). I would say the incompatibilites are fewer than you might think. Proprietary "enhancements" and toolsets probably present more differences than actual incompatibility. The 1998 vintage VC++ is probably the least compliant of them all, which is only to be expected.
|

March 15th, 2005, 05:20 PM
|
 |
Contributing User
|
|
Join Date: Aug 2003
Location: UK
|
|
Quote: | Originally Posted by JesusFreak Thanks Clifford. Umm... how do I do this |
As with any application you should explore the menus and dialogs as part of learning how to use it.
Project->Project options->Parameters
Clifford
|

March 15th, 2005, 05:24 PM
|
 |
Contributing User
|
|
Join Date: Aug 2003
Location: UK
|
|
Quote: | Originally Posted by JesusFreak Also, with the ifstream.h thing you mentioned -- in the code it is originally called 'fstream.h'. |
I mistyped you misunderstood! The point was that that the you only included one standard header. Changing it to <fstream> will fix the problem 'correctly' rather than using -Wno-deprecated. This is all explained in teh associate warning message - read it.
|

March 15th, 2005, 05:45 PM
|
 |
Contributing User
|
|
Join Date: Aug 2003
Location: UK
|
|
Quote: | Originally Posted by JesusFreak From what I understand there is a large amount of uncompatibility for code between different compilers. | If you get your code to work correcly with Dev-C++ it will almost always work elsewhere. The problem is most commercial compilers have a huge legacy market to support, if thier compilers threw out old pre-standardised code their customers would complain. That however is no reason to continue with bad habits (ot to learn them inthe first instance) supported by a permissive compiler.
Most compilers have options to enforce or relax standards. GCC (the compiler used by Dev-C++) by default enforces then, Many other compilers by default support backward compatibility.
Most of the issues you have raised are dealt with on the Bloodshed Forum's FAQ - http://sourceforge.net/forum/forum.php?forum_id=48211
Clifford
Last edited by clifford : March 17th, 2005 at 04:05 AM.
Reason: Changed Bloodshed forum link to forum rathet than FAQ thread - because the thread was replaced!
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|