cvSaveImage was not declared in this scope? - file

My code worked perfectly for months until today. Its in C++
#include <iostream>
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
using namespace std;
int main()
{
IplImage* img = cvLoadImage("C:/Users/Amadeus/Documents/H1/cat.png");
int result=cvSaveImage("C:/Users/Amadeus/Documents/H1/cat.png",img); <----- Problem
return 0;
}
It keeps saying "cvSaveImage was not declared in this scope". Files that would compile perfectly before all say it now. I don't understand why it worked for many months and today it says it wasn't declared. I even opened files that I knew worked for sure and even those didn't. It's like the header files are corrupt or something? What do you think?

Obviously, something changed in your system. I assume you don't know what exactly. The good point to start finding it out is to view your file after preprocessing is done. See for example this question on how to do this. Most probably you are pointing wrong or corrupted cv.h file for some reason.
By the way, why aren't you using modern C++ OpenCV functions imread and imwrite? They are in all ways better than their old C ancestors.

Related

C: Linking functions works without sharing headers or extern declaration

I am currently "playing" around in a quite big and old codebase and, quite unfortunately, it has no fixed style attached to it. So it was just made to work but that also means that quite a lot of it can be described as spaghetti code.
I came across something that I do not fully undersand. Compiler is from ARM/KEIL and it is for an embedded system.
first file:
fileA.c
// prototype
int GetSomething( int a );
// implementation
int GetSomething( int a) {
DoSomething();
}
second file:
fileB.c
// prototype
int GetSomething( int a )
void main ( void ) {
GetSomething(10);
}
There are no headers which have a declaration for the function GetSomething but the function is still correctly linked. Originally, there are a extern keyword in the second file in the declaration of GetSomething, but with or without that results in the same binary. The code has been tests and works.
I've seen Stackoverflow Question but that doesn't seem to cover my case as it seems to have nothing to do with the extern keyword.
I hope that somebody can explain that to me or tell me what is going on. Thanks.
Using header files and #include directives are just a more organized and neater way to use various parts of code in a program at different places.
When you do something like #include "header.h" a copy of header.h is put into the file.
So when you write
GetSomething( int a );
you are essentially doing an alternative to what
#include would normally do.
Another important detail is that function prototypes have the extern storage class specifier by default.
One thing you should keep in mind is that declaring function prototypes across your files manually can result in error prone and hard to maintain code. So it is best to utilize header files and #include directives.

Minix - System call not correctly calling function?

I need to create a system call in Minix for a homework assignment. I've gotten most of the set up finished, but for some reason the function that the system call is actually calling isn't being found correctly. (Pardon any bad wording choices, I'm not sure the best words to explain this).
I've created a mylib.h in /usr/include (and /usr/src/include), with the following code:
#include <lib.h>
#include <unistd.h>
#include <stdio.h>
int mycall(){
message m;
return (_syscall(PM_PROC_NR, MYCALL, &m));
}
I also added mylib.h to the appropriate Makefile.
I've defined MYCALL in /usr/src/include/minix/callnr.h, and I've added do_mycall to the corresponding slot in /usr/src/servers/pm/table.h.
I've added int do_mycall(void); to /usr/src/servers/pm/proto.h, and I added a simple function declaration in misc.c.
int do_mycall(void){
printf("I've been called");
return 0;
}
I've also tried placing it in it's own .c file, which I added to the Makefile in that directory.
I performed make in /usr/src/servers/pm/ and /usr/src/include, and make includes in /usr/src/releasetools.
However, when I call mycall(), and catch the return value, it's -1.
I've added some prints, and I can tell that the function in mylib.h is being called, and MYCALL is correctly defined as the index in table.h, and table.h should have the do_mycall line correctly in place (though I don't really know how to test that it's there upon execution). So, all I can tell is that in _syscall, do_mycall isn't correctly mapping to it's function.
I tried replacing the prototype in photo.h with just the code in misc.c (so the prototype would be missing), but nothing happened differently, and make didn't complain.
Can anyone help me figure out what's causing this, or how I can narrow down where the disconnect is here?
If anyone knows where _syscall is defined, that might help, since I could maybe add some prints in it to figure out how far it's getting.
I was unable to find a specific cause, but after exhausting all options I could find, the issue appears to have been with my virtual machine. I repeated everything I did to set up the system call on VMware Player, instead of VirtualBox, and everything worked fine.

Warning: assignment makes pointer from integer without a cast undefined

I realise there are a lot of questions related to this issue but I couldn't make head nor tale from the ones I read through.
I'm trying to start learning C for the Amiga and decided to have a try following this tutorial:
http://www.pcguru.plus.com/tutorial/amiga_c.html
On reaching this point, I'm already running into noob problems:
#include <proto/intuition.h>
#include <intuition/screens.h>
#include <proto/dos.h>
#include <stdio.h>
int main(void) {
struct Screen *myScreen;
if (myScreen = LockPubScreen(NULL)) {
printf("Public Screen locked.\n");
Delay(100);
UnlockPubScreen(NULL, myScreen);
printf("Public Screen unlocked.\n");
}
return 0;
}
I'm using the GCC compiler with the following command from the Shell:
gcc -o LockPubScreen LockPubScreen.c
This returns the following:
Warning: assignment makes pointer from integer without a cast
undefined reference to 'LockPubScreen'
undefined reference to 'Delay'
undefined reference to 'UnlockPubScreen
Apart from 'HelloWorld' this is the first attempt at either C or programming the Amiga so I imagine I missing something obvious.
You probably need to include one or more of these additional files to get the prototype for the functions you're missing:
#include <intuition/gadgetclass.h>
#include <intuition/IntuitionBase.h>
#include <libraries/gadtools.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
Then, as NPE suggests, may may run into link errors if your compiler doesn't include the requisite library by default, and if you don't specify it.
If you had mentioned that you were trying to compile the program under AmigaOS 4.x, the answer would have been obvious. Library function calls in OS4 must either contain the library interface as well - IIntuition->LockPubScreen(), IDOS->Delay(), etc. - or you must #define __USE_INLINE__ at the beginning of the code.

error: identifier "sytem" is undefined

I have just started to learn C language and I'm just trying to write Hello World to get started but I get this error message. I'm sure the answer is obvious but can someone please tell me what I need to do? This is my code:
#include <stdio.h>
int main()
{
printf("Hello World ");
system("Pause");
return 0;
}
#include<stdlib.h>
Include this header file..
You need to add another header file:
#include <stdlib.h>
When you have an undefined call like this you can always throw "man 3 system" and you'll get something like this so you can see if you're missing a header file.
FYI, for your specific program, you may want to consider no using system("Pause") since it's system dependent. It would be better to pause with a break point (if you're using an IDE) or something more C standard like getchar()
You need to #include <stdlib.h>
If you aren't sure which header a standard function is defined in, its man page will tell you.
Insert
#include <stdlib.h> //in C
or
#include <cstdlib> //in C++
before your main() function.
Note that your IDE should refrain from closing your program. If it doesn't, change IDE.
You should include the following library.
#include <stdlib.h>
It's simple as that.
I hope you find this useful.
As the others said, you need to include an header; if you're running on Linux, you may install "manpages-dev" package, and then tape "man system" which will tell you what are the headers you need to use.

C Implicit declaration differs from internal function declaration

I'm having some trouble with C standard functions. As an example, I'm getting that error in the memcpy function, even passing the right arguments to it.
I've included a header as #include "header.h", and I've included , and so in the "header.h" file.
(I'm also getting this error with strcpy, strtok, and some other standard functions, all respective headers included in "header.h")
Can anyone please help me with this? I'm running out of time to deploy this work...
Thanks in advance
It seems it was some trouble within eclipse. I right clicked one of those functions, selected Source->Add includes and it solved the problem (but didn't added any header).
I hope this can be helpful for someone else
Since you have not posted your code I assume that you have not included the following lines of code, at the top of your file:
#include <string.h>
In case your are using a C++ compiler (i.e. g++) then:
#include <cstring>

Resources