I am using CodeBlocks 20.03 and I want to use SDL_Image library to load JPEG, JPG and other image formats in my program. For that reason, I installed SDL_2.0.14 from the sdl website as a development library but not the runtime one. Now I copied all the .dll files into the MinGW bin folder and .lib files into the lib folder and again the SDL_image.h header file into SDL2 folder under the CodeBlocks compiler MinGW include folder.
Furthermore, I added the following lines in the linker library line through Settings->Compiler->Linker settings:-lmingw32 -lSDL2main -lSDL2 -lSDL2_image
I am sorry to be unable to post any photos for not having 10 reputations.
And now I am trying to compile the following code in my SDL2 project:
#include <iostream>
#include <SDL2/SDL.h>
#include "SDL2/SDL_image.h"
int main()
{
std::string path{"E:/C++ Project/Project/hrithik.jpg"};
IMG_Load(path.c_str());
IMG_Quit();
return 0;
}
But the wondering part is that my code doesn't compile, showing an error on the IMG_Load(..) line but, not in SDL2/SDL_image.h line.
I am using 64 bit Windows but 32 bit MinGW and SDL. I want to load png file format but without this function, it is not possible. Again, if I create any object of enum IMG_InitFlags, present in that header file the code works and compiles. I checked the header file definition and saw that my parameters were all correct.
Related
I'm not having any success with #include <opencv>, no matter what I try. [EDIT: I've also tried #include <opencv2> and #include <opencv4>, but there was no difference].
For context, I'm on Ubuntu 20.04, using Sublime Text 3, the latest version of OpenCV is installed on the system (at /usr/local/include/opencv4/opencv2), and I've tried something like six different build systems for cpp, including the default.
no matter what I try and how I fiddle with files, I always get the same error:
/home/user/Projects/Mind/CScript/Script.cpp:5:10: fatal error: opencv: No such file or directory
5 | #include <opencv>
| ^~~~~~~~
compilation terminated.
[Finished in 0.1s with exit code 1]
[shell_cmd: g++ "/home/user/Projects/Mind/CScript/Script.cpp" -o "/home/user/Projects/Mind/CScript/Script" && "/home/user/Projects/Mind/CScript/Script"]
[dir: /home/user/Projects/Mind/CScript]
[path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games]
I even tried to copy the whole opencv folder into the file path, but there was no change at all.
EDIT: The solution that worked was to paste the opencv2 folder from /usr/local/include/opencv4/ to /usr/local/include/. Apparently that additional folder wasn't supposed to be there.
An #include refers to a file, not a folder. A file so specified is looked for in the list of include paths.
-I /usr/local/include/opencv4/opencv2 adds that path to the list of include paths. The path, however, looks broken to me -- OpenCV has the legacy API in opencv/, and the updated API in opencv2/, but in either case there should be no opencv4/ in the path. (Double-checked with my APT.) Are you sure you did the OpenCV setup correctly?
The actual header's name is opencv2/opencv.hpp (note the .hpp at the end; generally, only the standard library's includes are without .hpp, all the third party libs I have seen so far use the .hpp extension).
Best practice is to leave the include path alone and write #include "opencv2/opencv.hpp" (with the subdirectory name) in your sources to avoid ambiguity.
I just start learning opengl and I started with GLFW library.
And I download the "Windows pre-compiled binaries" from http://www.glfw.org/download.html. Then I unzip my file into C:\GLFW
And now I have a problem when compiling my code. I use mingw in command line, like
gcc main.c -IC:\GLFW\include\GLFW -LC:\GLFW\lib-mingw -lglfw3 -lglfw3dll -lopengl32 -lgdi32
It always show "fatal error: GLFW/glfw3.h: No such file or directory"
but if I change #include <GLFW/glfw3.h> into just #include <glfw3.h> in my code,
it compiles successfully.
But every tutorial shows me the former. Why?
If I put the header file and lib file into mingw's searching path, is there any different?
It is because you include directly to C:\GLFW\include\GLFW, so there is no GLFW folder in this directory. If you want to use #include <GLFW/glfw3.h>, you will want to use this path instead C:\GLFW\include.
To answer to your two questions:
The include path is very relative to you. What do you prefer, #include <GLFW/glfw3.h> or #include <glfw3.h>?
You can put the lib and header in the mingw's path, but you have to remember that you will still need to enter the good path (#include <GLFW/glfw3.h> if you put it in the folder). I would not recommend this method, since I prefer to make an include and lib folder into my project directory. If you want to do more research: http://www.mingw.org/wiki/includepathhowto.
I've downloaded the latest version of FreeType and want to get the source code running in my program. I'm programming in Eclipse and I've copied all the Freetype files into my project. I've listed them under ProjectName/Source/FreeType2/..
I've added compiler include directories for the new folders, so my GCC C++ compiler knows where to look for them. However, if I build my project, an error occurs on the last line of the following code:
#include <ft2build.h>
#include FT_WINFONTS_H
#include FT_INTERNAL_DEBUG_H
I did some research and the macro file FT_INTERNAL_DEBUG_H is defined as <internal/ftdebug.h>. The file is present in my system and the macro file FT_WINFONTS_H compiles like a charm! I think it's got something to do with my directory stucture somehow. How should I change my directory structure in order to get things compiled succesfully? My current structure is like this:
ProjectName
Source
FreeType2
devel
docs
include
config
internal
objs
src
I know I used two "source" folders, but this shouldn't be the problem, right?
The error message I get is Invalid preprocessor directive: #include FT_INTERNAL_DEBUG_H
Thank you for your time ;)
I have recently started learning graphics in C++.
I tried #include <graphics.h> in my program in codeblocks but it shows error. Then I downloaded graphics.h header from a site and pasted in the include folder in codeblocks, yet it shows graphics.h:No such file or directory.
Can anyone teach me how to use graphics.h in codeblocks?
First download WinBGIm from http://winbgim.codecutter.org/ Extract it.
Copy graphics.h and winbgim.h files in include folder of your compiler directory
Copy libbgi.a to lib folder of your compiler directory
In code::blocks open Settings >> Compiler and debugger >>linker settings
click Add button in link libraries part and browse and select libbgi.a file
In right part (i.e. other linker options) paste commands
-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
Click OK
For detail information follow this link.
You don't only need the header file, you need the library that goes with it. Anyway, the include folder is not automatically loaded, you must configure your project to do so. Right-click on it : Build options > Search directories > Add. Choose your include folder, keep the path relative.
Edit For further assistance, please give details about the library you're trying to load (which provides a graphics.h file.)
If you want to use Codeblocks and Graphics.h,you can use Codeblocks-EP(I used it when I was learning C in college) then you can try
Codeblocks-EP http://codeblocks.codecutter.org/
In Codeblocks-EP , [File]->[New]->[Project]->[WinBGIm Project]
It has templates for WinBGIm projects installed and all the necessary libraries pre-installed.
OR try this https://stackoverflow.com/a/20321173/5227589
AFAIK, in the epic DOS era there is a header file named graphics.h shipped with Borland Turbo C++ suite. If it is true, then you are out of luck because we're now in Windows era.
Open the file graphics.h using either of Sublime Text Editor or
Notepad++,from the include folder where you have installed
Codeblocks.
Goto line no 302
Delete the line and paste int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX, in that line.
Save the file and start Coding.
It is a tradition to use Turbo C for graphic in C/C++. But it’s also a pain in the neck. We are using Code::Blocks IDE, which will ease out our work.
Steps to run graphics code in CodeBlocks:
Install Code::Blocks
Download the required header files
Include graphics.h and winbgim.h
Include libbgi.a
Add Link Libraries in Linker Setting
include graphics.h and Save code in cpp extension
To test the setting copy paste run following code:
#include <graphics.h>
int main( )
{
initwindow(400, 300, "First Sample");
circle(100, 50, 40);
while (!kbhit( ))
{
delay(200);
}
return 0;
}
Here is a complete setup instruction for Code::Blocks
How to include graphics.h in CodeBlocks?
My understanding is that when I build a C++ project in xcode and I have an include line in one of my C files in angle-bracket form then the C++ compiler that works with xcode looks in /System/Library/Frameworks/ to find the file. I think that because of this answer: when I use the line #include <OpenGL/gl.h> in my xcode project, where does it look for the gl.h file?
I have an SDL.h file at /System/Library/Frameworks/SDL.framework/headers/SDL.h (I downloaded the folder SDL.framework and copied it to that location with the command sudo cp -r /Volumes/SDL/SDL.framework System/Library/Frameworks)
But my include statement in one of the files in my xcode project still gives this error:
#include <SDL/SDL.h> //throws file not found
Did I properly install the SDL framework? Why doesn't xcode see it?
Under your projects Build Settings, do a search for "search". Add a header search path to the SDL directory /System/Library/Frameworks/SDL.framework/headers
Should be able to just do this after:
#include <SDL.h>
Hope that works for you.
You can also check out this link:
http://meandmark.com/blog/2012/01/using-sdl-with-xcode-4/
It's for Xcode 4, but it looks like all the pieces are there.