Can't make png++ work properly - c++

I need to work on png pictures for a school project using c++. I found png++ which seems pretty easy to use but I had some really hard time setting up everything to make it work (which it doesn't). I used Cygwin to properly install zlib and libpng. I properly included the png++ headers in my project (I'm using Eclipse). Here are some things that are not properly working:
If I try this line of code (as seen here ):
image img(1024,768);
I get this error after compiling on eclipse:
#error Byte-order could not be detected.
I read this answer here, but the solution is not working for me (I'm on windows 8 64 bit), and I get this other error (which is my main problem because Byte-order can be "brutally" fixed):
missing template arguments before 'img'
But even if I type a valid template argument (like < png::rgb_pixel> < png::rgba_pixel > < png::gray_pixel > < png::ga_pixel >) it says it's invalid.
I'm clearly not an expert on this and I wouldn't know what else to try. Any help would be much appreciated. If you need more info write a comment and I'll provide.

For the template arguments, I think that is actually just an Eclipse issue, it should have compiled fine. But in order to get rid of the Eclipse errors, you can see my answer here: https://stackoverflow.com/a/28400902/583620.
For the byte-order problem an easy way to solve this is to just go into the png++ header folder location (probably under /usr/local/include), open config.hpp, and put
#define _WIN32
before the // Endianness test comment. That should do it. Alternatively you can try what was mentioned in the answer you posted earlier and change _WIN32 to WIN32 although in my case WIN32 was not defined either so it was quicker to just define _WIN32.

Related

There are too many errors for the IntelliSense engine to function correctly

Please leave the window-installer tag in - this Q/A is not for
C++ experts, but for people like me, who use C++ when they have to.
They may face this potential time-waster, and need a quick fix to get
msi.h or other includes operational quickly. VS2017 templates must
have changed quite a bit - I didn't see this issue before.
Visual Studio 2017 Community Edition with all available C++ components installed (perhaps this problem does not exist in the professional edition?).
File => New => Project... => Visual C++\Windows Desktop\Windows Console Application => OK.
Do a quick test build to verify there are no errors. Right click solution => Build. As stated no errors should show up.
Now add this include for msi.h directly below #include stdafx.h right above the main() function in the console appliation's CPP file:
#include <msi.h>
// And just to make things link:
#pragma comment(lib, "msi.lib")
A red error chevron should show up in the top left corner at the start of the first line comment saying on hover: "There are too many errors for the IntelliSense engine to function correctly, some of which may not be visible in the editor. PCH warning: an unknown error occurred. An IntelliSense PCH file was not generated."
Doing a build now should reveal numerous errors. In my case from wincrypt.h - and it got me thinking about WIN32_LEAN_AND_MEAN - see answer below. I thought such basics would already be included.
I keep seeing this problem in all new C++ Windows Console Application projects, but when I try in an older project created with Visual Studio 2013 it compiles correctly with msi.h included along with the link pragma.
Judging from the error message there must be something wrong with the precompiled header (PCH). This is what threw me off.
UPDATE: Others have asked about the same error message for other include files (not MSI related). I guess this is a generic problem that strikes every now and then - probably with classes that are in little use (or include Windows.h - perhaps)?
As a general suggestion this might be a hidden dependency problem (an include that is missing), or an incorrect order of the include files (you need to change the order of your includes for some technical reason that is not immediately obvious) or a incorrect or missing define (like seen in the answer below the line underneath). My take on it: get on github.com and search for similar sample code.
These issues can be quite clunky to work out for those of us who need C++ occasionally, and otherwise be "well known" for the C++ pros (who fix it in seconds as second nature). C++ pros: please keep in mind that issues such as these can kill a whole day's worth of productivity for those of us forced to clunk around with C++ when we need to - and have no C++ pros around to ask - terrible situation that! :-) - I hereby declare a "be nice to your C++ guru - if you got them - day!").
In stdafx.h, try adding this after #pragma once and before other includes:
#define WIN32_LEAN_AND_MEAN
// Windows Header Files:
#include <windows.h>
Now try to rebuild your solution and see if the problem has disappeared.
Though simple, the strangeness of the error message (seen in the question above) can throw people off course trying to figure out what is wrong. Also, this behavior seems new in VS2017 - template change.
It looks like including <atlstr.h> will also work, so that probably makes my problem more obscure. Could have sworn I tried this though - maybe after I made project settings changes that made it fail still (exactly what I hope to help others avoid).
If only these basic includes could be present in the file but commented out so they could be enabled quickly in sequence for testing - without any fuss.

Xcode noob: Don't understand compiler error message

I'm fairly new to Xcode and have recently gotten an error message that is probably clear to anyone who knows what they're doing, but I am unsure how to react to this one.
I have a project that is mostly C++, with just a few C files in it. Everything was fine until I tried to add some code to find the computer's MAC address. Apple provides a project example (GetPrimaryMACAddress), and I downloaded, built, and tested that. It works just fine.
After that, I simply copied the C source from the Apple example project and included it into my code project. Then I started getting this error message:
I have tried including the IOKit framework explicitly via the linker; no help. I tried adding more #include statement to the Apple example code; no help. I think that I do not understand what the compiler message is telling me regarding importing from module 'Darwin.MacTypes'.
Clicking on the error message took me to a line in usr/include/MacTypes.h:
I'm not clear on how to Import Darwin.MacTypes. I don't really understand how the source code for GetMACAddress could compile so effortlessly in one project and not another. I didn't rearrange nor add nor delete any of the #include statements in the Apple-supplied C file.
I'll bet there is a simple answer that I am just not seeing. How should I react to this error message?
I had a similar problem with types like UInt16 and UInt32. I just included the MacTypes with the following include statement:
#include <MacTypes.h>
This solved all my type-problems for my example c-file.
Let me guess, when you want to compile C++ source, you should create a C++ source file
(On the toolbar: File > New > File.. > Source > C++ File)

MinGW screw up with COLORREF and RGB

I am trying to build a 3rd party open source project using MinGW. One of the dependencies is wxWidgets. When I try to make the project from MSYS I get a compiler error from
/MinGW/msys/1.0/local/include/wx-2.8/wx/msw/private.h
In function 'COLORREF wxColourToRGB(const wxColour&)':
error: cannot convert 'RGB' to 'COLORREF {aka long unsigned int}' in return
This is somewhat odd given that, according to Microsoft the RGB macro returns a COLORREF.
In fact, looking in H:\MinGW\include I find wingdi.h with the following code
#define RGB(r,g,b) ((COLORREF)((BYTE)(r)|((BYTE)(g) << 8)|((BYTE)(b) << 16)))
What sort of thing would cause this error? Is there some way I can check to see if COLORREF and RGB are being included from wingdi.h and not somewhere else? Is that even worth checking?
Specifications
GCC version 4.7.2
wxWidgets version 2.8.12
(I'm new to C++ and MinGW specifically but generally computer and programming literate)
Try preprocessing the source with -E and check what is actually happening with the macro expansion or whether something is redefining the macro.
The preprocessed source undoubtedly will be very lengthy after #includeing its header dependencies. Your text editor's search function, grep and findstr are your friends here.

OpenCV 2.4 : undefined reference to cvRand

I can't find the file I have to include to my code to get cvRand (and all other related functions, such as cvRandInit ... ) to be recognized by the compiler. It's weird, because in the past this code used to work as is. Must be an issue with OpenCV2.4.
Also, when I right-clic on cvRand (I work with Qt Creator) and ask to follow the symbol under the cursor, the IDE open a file called compat.hpp. I have several files named compat.hpp, so I don't know which one I have to include. My OS is Ubuntu 11.04.
So far, I included core.hpp, highgui.hpp, and cv.h.
I googled on this, but couldn't find any related issue... so I guess this is not an issue, and I just miss something stupid.
The includes were obviously right, I figured that it has to be a lib problem, by guessing I found that I had to add libopencv_legacy.so. Everything works fine now, thx stackoverflow.

Basic example code compiling help required - I can't get any SDK examples to work

I'm very new to C++; I've worked with several SDKs now on various applications and every time come across the problem that I can't get the 'example code' to compile. This is a very broad question basically regarding ANY example code that is given over the net - what is the standard procedure to make things compile? I know how to compile code that I've written myself but when given a large project containing several CPP and H files, what do I start with? My first port of call, to open 'main.cpp' in Dev-C++ and hit the 'compile' button generally throws up errors about header files not being available and so on.
I won't give a specific example as this has happened several times. I feel as someone getting to grips with C++ that I would learn a lot quicker if I could start with code that works and tweak it myself rather than having to fumble around building things up piece by piece.
The most recent example is a set of example code provided by a company which 10 files:
-Arial.ttf
-demo_resources.rc
-icon.ico
-main.c
-simple.dsp
-simple.dsw
-simple.exe
-simple.h
-trial.c
-trials.c
Running the .exe file works absolutely fine; however if I open main.c and press compile, I receive many error messages. As an example, the first two lines of code in main.c are:
#include "simple.h"
#include <sdl_text_support.h>
This alone spews the error messages:
1: expected unqualified-id before "public"
1: expected `,' or `;' before "public"
2: In file included from trial.c
Clearly I am doing something very wrong as this code must have compiled for someone else in the past to have generated the .exe file. Again this is not an isolated issue, I have this problem all the time.
Since Dev-C++ is perfectly equipped to deal with plain old C files, I can't see that that is the issue. Secondly, simple.h is definitely included in the correct directory. The second include though, sdl_text_support.h is obviously not in my file list above. I have searched the rest of the SDK and found the file lurking elsewhere. How do I explicitly reference the location of the header file using Dev-C++?
Any general tutorial to how to compile pre-made projects or help of any kind would be greatly appreciated.
I like this page:
http://www.cprogramming.com/tutorial.html
I am not familiar with DevC++, but you cannot assume that if you can open main.c and press a button, then everything will work out. No build system is that smart.
If you write your own code (and you understand compiling and linking) then you can keep your files in order and know exactly how to build everything; someone else's codebase may come with a makefile or some other guide to it's organization, but you'll have to learn how to use a good build system, and the one you're using sounds inadequate.
open the project by simple.dsw instead of main.cpp and it should work .