OpenCV 2.4 : undefined reference to cvRand - c++

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.

Related

Using the (antiquated) C crypt() method for homework - the compiler won't link?

all:
I'm supposed to use the crypt( ) function in a homework assignment. It's an old C method, which is probably pretty insecure, but it's just for demonstrative purposes.
The only thing, I can't figure out how to use the dang function. I'm using CLion as my IDE on Ubuntu. It's supposed to be defined in the <crypt.h> or <unistd.h>, but I cannot get this thing to compile. The crypt( ) function has an "undefined reference" error after building the project. I know it's one of those two libraries, though - so what's up? Is there an issue with linking to that library or something? I've read around and come across "use -lcrypt", but I'm not entirely sure what to do with that inside CLion. The only explanations were involving make files; which, didn't apply to me (or they did, and I didn't know how it related). There's not much documentation for it, either, because of how outdated the function is.
Thanks, all.
EDIT:
Thanks, Eugene! I think I figured this one out. . .
target_link_libraries(CryptExample -lcrypt)
In the CMake file.
To anyone that stumbles upon this in the future, add
target_link_libraries(CryptExample -lcrypt)
to your CMakeLists.txt in the CLion IDE. It should be put under the add_executable(. . .) line. Replace "CryptExample" with whatever you named your project.

Assimp won't build correctly in Code::Blocks - "TVITEMEXW not declared in current scope"

I'm currently working through the LearnOpenGL tutorials, which has been going fine thus far, until I've hit the model loading portion of the tutorial.
LearnOpenGL uses the Assimp library to handle model loading, but I don't seem to be able to get it to build properly (precompiled libraries don't work either for me) - it produces errors within "Display.cpp":
In function 'unzOpenCurrentFile3':
Line 1177: warning: assignment from incompatible pointer type
In member function 'int AssimpView::CDisplay::AddNodeToDisplayList(....'
Line 179 error: 'TVITEMEXW' was not declared in this scope
With the line 179 error appearing to be the main cause of failure. Having looked in the 'Display.cpp' file, the issue is with the following declaration:
TVITEMEXW tvi;
And TVITEMEXW doesn't seem to be declared/included within the file explicitly, but the included headers are stdio.h, stdlib.h, string.h, and "./unzip.h". After some searching, I've found that TVITEMEX is a windows structure with TVITEMEXW as a unicode name (according to this) but I'm fairly new to C++/compilers etc., and don't really know what to do with this information.
I created the Code::Blocks project file with CMake and MinGW from the Assimp 3.2.
Any help would be hugely appreciated, I've been stuck with this for a few days now and can't figure out how to resolve it myself. Apologies if I haven't provided enough/the correct information, I'm not entirely sure exactly what is relevant to the problem.
try replacing TVITEMEXW with TVITEMW and maybe sNew.itemex with sNew.item.

Can't make png++ work properly

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.

Compiler doesn't find reference to zip_get_num_entries on Windows

I want to use libzip in my program in C++ to extract files from a zip archive. So firstly, I get the number of files in it, get their names and read them. To get the number of files, I use 'zip_get_num_entries'. Its prototype is:
zip_uint64_t zip_get_num_entries(struct zip *, int)
And the way I use this function:
int nbrEntries(0);
zip *archive = zip_open("myZip.zip", 0, 0);
nbrEntries = zip_get_num_entries(archive, 0);
When I wrote this code, Code::Blocks suggested me zip_get_num_entries, so there's no problem of header. But when I compiled, the compiler (MinGW) told me that:
undefined reference to `_imp__zip_get_num_entries'
So I tried its deprecated equivalent, zip_get_num_files and it worked. I included to the project libzip.dll.a that I made with CMake. I had two files: libzip.dll and libzip.dll.a.
I'm sure it's a library problem (notice that I didn't have this problem on MacOS) but I don't know how to solve this. Thank you!
EDIT: I searched their website and read that the implementation of zip_get_num_files was new when they released the library available on the website. So I searched in their Mercurial repo and found versions that were released 2 days ago (a little bit newer than the release on the website, which has almost 1 year). I built it with CMake and it worked!
"Undefined reference" means that there is no definition/implementation (as opposed to declaration/prototype) of the function available. You forgot to link the library. Since you use MinGW with g++, it will take something like -lzip on the command line or as parts of LDFLAGS.
There is a chance that you misconfigured something, too - in which case the symbol name may be different depending on a define. But the most likely case is that you forgot to link the dependency.
I finally succeed to use zip_get_num_entries! I searched their website and read that the implementation of zip_get_num_files was new when they released the library available on the website. So I searched in their Mercurial repo and found versions that were released 2 days ago (a little bit newer than the release on the website, which has almost 1 year). I built it with CMake and it worked!

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 .