Images in graphics.h

I am trying to display an image and it seems that readimagefile doesn't work... I am not sure why. Could you give an example of a c++ code example in which readimagefile is used just to make sure I've done everything right?
It would be much easier to post what you have and allow us to correct it then it would be for one of us to start a project just to demonstrate one function. It also allows us to preemptively fix issues that haven't come up yet, but are bound to bite you. Are you getting an error? If so then what is it? If not, then what is the observed behavior compared to the expected behavior?
Error I get: undefined reference to `readimagefile'

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <fstream>

const char *img = "test.bmp";

using namespace std;

int main()
{
    
    initwindow(400, 300, "First Sample");
    readimagefile(img,10,11,10,10);
    getch();
    return 0;
}
Sounds to me like you haven't linked the file correctly.

As Tarik says, this is a linking problem.

On the assumption that you're trying to use a library function named readimagefile, there are two steps.

First, you #include the relevant header. This you have done. This tells the compiler what it needs to know about the library function you want to use.

You must then actually provide the library function. This is what you have not done. The library is the the actual binary code that will do the actual work of the function you want to call. This lives in the library file (on windows, typically a *.dll or a *.lib file, and on Linux they're named *.so or *.a). Whatever you're using to actually build your code comes with a way for you to specify the name and location of library files to use. Read the documentation and learn how to do that. Then, do it.

Last edited on
What IDE and compiler are you using OP?
Topic archived. No new replies allowed.