How to use graphics.h in codeblocks? - c++

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?

Related

Add libcurl Unreal Engine 4

i need to include libcurl in my unreal engine project, i need to use it in game, how i can do it? i have tried standard tutorial for include curl in visual studio, but not work.
the compiler return error on other portion of code if i include curl with following code
#include <curl\curl.h>
I have tried also to change separator to / but nothing, i have read about thirdbart library but how i can add curl?
other questione, look in Visual Studio project, curl.h is included in extetrnal reference for Engine project, but not in Game project.. how i can include?
EDIT
i have included the directory
C:\Lib\curl\builds\libcurl-vc-x64-release-static-ipv6-sspi-winssl\include\
lib direcotry
C:\curl\builds\libcurl-vc-x86-release-static-ipv6-sspi-winssl\lib\
when include curl show this error when i compile:
If i remove #include curl\curl.h from code it compile fine.
I have solved!, You must add the path of library in VC++ tab in , includes directory and lib directory, after you must add this line in you build.cs
PublicAdditionalLibraries.Add("path to lib file");
PublicIncludePaths.Add("path to includes directory");
have nice day!

How to build 102 example of libigl tutorial in Visual C++?

I am currently using Visual C++ 10.0(2010) on a win7 32bit OS.
When I tried to build the basic examples of libigl github tutorials:
libigl tutorials
The following installation code works fine:
#include <igl/cotmatrix.h>
#include <Eigen/Dense>
#include <Eigen/Sparse>
#include <iostream>
int main()
{
Eigen::MatrixXd V(4,2);
V<<0,0,
1,0,
1,1,
0,1;
Eigen::MatrixXi F(2,3);
F<<0,1,2,
0,2,3;
Eigen::SparseMatrix<double> L;
igl::cotmatrix(V,F,L);
std::cout<<"Hello, mesh: "<<std::endl<<L*V<<std::endl;
return 0;
}
which indicates there is basically no problem per the tutorials.
However, I cannot get the tutorial 102 through:
#include <igl/readOFF.h>
#include <igl/viewer/Viewer.h>
Eigen::MatrixXd V;
Eigen::MatrixXi F;
int main(int argc, char *argv[])
{
// Load a mesh in OFF format
igl::readOFF("../shared/bunny.off", V, F);
// Plot the mesh
igl::viewer::Viewer viewer;
viewer.data.set_mesh(V, F);
viewer.launch();
}
After getting a series of building error message of missing some special headers, and then adding the corresponding directory containing the header into the including directory of VS, there is still some header missing which cannot be found in my computer.
Except for the include directory which is required per the tutorial:
x:\Program\libigl-master\include; $(IncludePath);
I already added others as follows:
x:\Program\libigl-master\external\glfw\include;
x:\Program\libigl-master\external\AntTweakBar\src;
x:\Program\libigl-master\external\AntTweakBar\include;
x:\Program\libigl-master\external\glew\include;
Error message is still there:
x:\Program\libigl-master\external\glfw\include\glfw\glfw3.h(163): fatal error C1083: Cannot open include file: 'GL/glcorearb.h': No such file or directory
1>
So I added:
x:\Program\libigl-master\external\glfw\include\GLFW
D:\Program\libigl-master\external\glfw\include\
and got:
x:\program\libigl-master\external\glfw\include\glfw\glfw3.h(163): fatal error C1083: Cannot open include file: 'GL/glcorearb.h': No such file or directo
which does not exist in my computer.
What should I do?
I had the exact same issue, and the thing is that simply adding their include paths won't make it work - as they said it would. That is because LIBIGL itself is just an auxiliary library to help manipulate 3D shapes, but their examples use much more than that (their matrix system comes from Eigen, their graphical system uses GLFW+GLEW, among many others).
But you can get most of the examples working on MSVS setting up the essential libraries. Download the following:
Eigen: This is for the basic matrix/vector arithmetics etc.
GLFW: This is used to create and handle windows for OpenGL.
GLEW: This library has the actual OpenGL function bindings to use OpenGL functions.
Note that these libraries are essential to compile the examples jut because when the examples were made, the creators had the enviroment set up with them (otherwise they would have to code by hand those OpenGL and Windows/Linux windows handling etc. In case you're interested, this is what "pure OpenGL" code looks like). So what you have to do is: set the enviroment for these libraries. This is how to do it:
After creating an empty project in MSVS, go to Solution explorer > right click the project > Properties. You've opened the Property Pages, where all the project configurations are done. We need to specify 3 things: where the compiler can find the headers, the libraries we're using and where it can find these libraries.
First we set up the headers: on the left menu expand C/C++ > General, and on the right, select Aditional Include Directories, click on the down arrow and click edit. A window will open with blank fields, click them twice to add items. Add the eigen header path, the libigl folder path, the glew folder path and the glfw folder path in each line (this is a very confusing interface).
Ok, now we need to specify which libraries we're going to use. Again, in the left menu, go to Linker > Input > Aditional Dependencies (almost the same kind of interface). Add glew32s.lib, glfw3.lib and opengl32.lib (one for each line). Finally, specify where those libraries are. Go to Linker > General > Aditional Library Directories, and specify the path where the downloaded glew32s.lib and glfw3.lib are. (something like "C:\Users...\glfw-3.2.1.bin.WIN32\lib-vc2010") - make sure you're specifying the path to the right compiler - for instance, if you're using MSVS 32 bits 2010 you should select vc2010 and not mingw-64.
If you create a source file in the project using the tutorial 2012 source code it should compile, but you might have to specify the paths to the dll's such as OpenGL32.dll if it's not already in your system path.
Finally, one last thing that might go wrong has to do with something called Runtime Library - it's in C/C++ > Code Generation > Runtime Library. Basically it describes a method to compile code, and each library we're using was compiled using a different one, so we might get errors... Honestly I don't know a lot about that, I just know that mine wasn't working with the default one, so I changed to /MD and it worked. Go figure.
PS: You might as well need to update your graphics card for OpenGL to work.
The only thing that worked for me was creating a visual studio project with cmake-gui. Here is what I did:
Download and install cmake https://cmake.org/download/.
Open cmake-gui.
In 'where is the source code', put the path to the tutorials: .../libigl/tutorial.
In 'where to build the binaries', put whatever your like (I used .../libigl/tutorial/build).
You will also see a bunch of options in red. Select/deselect as desired. I had to deselect Matlab as it couldn't find it for some reason.
Configure and generate (when asked, choose whichever version of Visual Studio you are using).
You should now have a Visual Studio solution in the build folder. Open and build.
I had the same problem in Visual Studio 2013. And the head file I was trying to use was igl/sort.h which cannot be opened.
In the tutorial , they said
Simply add libigl/include to your include path and include relevant headers.
And the include path they were referring here is actually the include directories which can be found under project>properties>Configuration Properties>VC++ Directories, not the Additional Include Directories.

Xcode Version 6.0.1 gmp.h header file not found, even though gmp.h and gmpxx.h are in local/include

i'm trying to get GMP working with Xcode. So far I have untared the file in the home directory, ran all the necessary commands to have it configure, make, and install
./configure --prefix=/usr/local --enable-cxx
make
make check
sudo make install
Both the gmp.h and gmpxx.h are in the usr/local/include, however I still am getting an error when trying to include the files. I believe I need to add a complier flag but for this version of Xcode I do not know how to do that. If that is not the case and I need to do something else please advise and I would very much appreciate it.
My code looks like the following:
#include <iostream>
#include <gmp.h>
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}
Can I code with GMP in c++ ? Or do I need code in c? Any help getting this to work would be very much appreciated, thanks a ton in advance!
Sorry if this seems like a DUPLICATE question, i did look at the other questions and I was not able to get it to work following answers from previous questions.
UPDATE
Added the libgmp.la and libgmpxx.la to Xcode, also added /usr/local/include to header file search and it is still not working! I see the library files in my project and if I put "gmp.h" instead of it works but when I go to use GMP it fails telling me to chnange the in other GMP files to "gmp.h" which doesn't seem right.
ANY IDEAS?
this is the fix according to another SO question:
1) Open the left panel,
goto "ProjectName", Targets, Build phases, Link binary with libraries
and select your library.
2) Open the left panel,
goto "ProjectName", Project, Header Search Paths,
write the path where the headers of your library are
(the .h files, usually in /usr/local/include).
3) Open the left panel,
goto "ProjectName", Project, Library Search Paths,
write the path where your libraries are
(the .a or .dylib files, usually in /usr/local/lib)

error C1083: Cannot open include file: 'FL/Fl.h': No such file or directory

First of all I'm still new here and therefore have no idea how to format the code so it looks neat in this question, I hope this is acceptable.
I am following the programming principles and practice from Stroustrup. You might guess what the problem is...yes FLTK instalation. I have followed all the steps carefully to build the project in VS C++ 2013; pages 1204-1206. (I've done appendix C successfully, having to do with std_lib_facilities.h).
I was trying to build the following win32 project, as shown in the book:
#include <FL/Fl.h>
#include <FL/Fl_Box.h>
#include <FL/Fl_Window.h>
int main()
{
Fl_Window window(200, 200, "Window title");
Fl_Box box(0, 0, 200, 200, "Hey, I mean, Hello, World!");
window.show();
return Fl::run();
}
After building solution, I receive an error which reads: Error 1 error C1083: Cannot open include file: 'FL/Fl.h': No such file or directory
I have also followed the steps to copy across some lib files from the FLTK lib directory into c:\users\pablo\desktop\c++ course files\visual c++\win32project1\source.cpp which is the file I created for Visual Studio Express 2013.
Can somebody help me? Where do I find this missing file? Is the problem perhaps having to do with the fact that the FLTK version is a bit outdated to be used in VS 2013? (When I compiled the FLTK library, I got some errors having to do with backup file and some warnings.)
I have researched this long an hard. I found some questions having to do with this in this forum but not exactly related to the above mentioned problem. Thanks very much in advance.
PS Well, there was one question having to do with the same error. I've followed some of the tricks mentioned as an answer to the same question but to no avail.
("A neat trick you can do for these types of errors is to place your cursor into the file name of the #include statement and press Ctrl+Shift+G. It will fail and display a message box showing what the include paths are. The solution is to simply add additional include paths to the SDK by right clicking your project and going to Properties>C/C++>General and setting "Additional Include Directories".")
The other suggestion shown didn't work either: ("Make sure the include directory is not the FL directory, but its parent. The reason for this is when you say #include "FL/Fl.h", you're asking the compiler to step into a folder called FL to find Fl.h, which will reside in FL's parent. If you specify FL as an include directory then you need only say #include "Fl.h"").
The other answer isn't remotely true (I have literally just compiled an FLTK program with all headers in the form #include <FL/xxx.H>). When you download FLTK you get a directory (say fltk-1.3.2) which has this structure
/fltk-1.3.2/
FL/
GL/
src/
lib/
examples/
+ other stuff
The sub directory FL contains all the header files. As such if wherever you've placed the fltk-1.3.2 directory is located at \foo\ then you need to add \foo\fltk-1.3.2\ to your additional include headers field. Do be careful, you might have accidentally chosen the wrong directory (it happens) or you might have extracted the contents of a zipped version of the file into a nested version of itself meaning you might have something like \foo\fltk-1.3.2\fltk-1.3.2\ So have a look.
If it can't find the headers you almost certainly have got the additional include directories field looking in the wrong place or in the wrong format. Click on the drop down button, click edit and manually click the new folder button and navigate to it.
What you will find next is that you have to point the linker in the right direction. In the above the default place to install the library files (.lib static should be default for FLTK) so you need to add \foo\fltk-1.3.2\lib\ to configuration properties -> Linker -> General -> Additional library directories
THEN you need to link to the specific libraries. Since the linker now knows where to look you down need to specify the path, but just name them. To do so go to configuration properties -> Linker -> Input -> Additional dependencies, click the drop down option, click edit and add on separate lines (and without these commas) fltkd.lib, fltkformsd.lib, fltkzlib.lib,wsock32.lib
This is because there is no header file named #include <FL/Fl.h> what they mean by this is to include either #include <FL> or #include <FL.h> depending on what program your making, but the former is most likely what you want to do since it's the standard version. #include <FL.h> is an old library, and is not even included in the standard. It is also not even included in every platform. You should not use the .h version in this example.
The same can be said for the other two header files as well.
The original question was about Windows, and the direct answer to the question is to add the directory above the FL directory (note: uppercase) to the include paths of the Visual Studio settings.
Since this is about windows, spelling of the header files may not matter, but such programs as shown by the OP are not portable because other systems use case sensitive file systems. For portability almost all FLTK header files must be written with uppercase ".H" to be found on case sensitive file systems (there are some exceptions). The correct example program - tested on case sensitive Linux with current development version FLTK 1.4.0 - would be:
#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Window.H>
int main() {
Fl_Window window(200, 200, "Window title");
Fl_Box box(0, 0, 200, 200, "Hey, I mean, Hello, World!");
window.show();
return Fl::run();
}
Note that this still needs the correct include path to compile and build.
this works !!!
On your own Linux/Mac: Download the source for fltk 1.1.10 and unpack it in a directory of your choice. You should be able to execute "configure", "make", and "sudo make install" to install fltk in /usr/local/lib and /usr/local/include.

Cannot open include file "sqlapi.h" in C++?

I am trying to connect c++ with SQLBase. After building my project I get an error as
" Cannot open include file: 'SQLAPI.h': No such file or directory ".
#include <stdio.h>
#include <SQLAPI.h> // main SQLAPI++ header
#include <sbAPI.h>
Can someone please tell me why am I getting this error and how to fix it?
The file "SQLAPI.h" is not in the include path. You need to add the path to the header files to the compilation flags.
If you are using GCC then add a flag -I like this:
g++ -I/path/to/headers <rest of arguments>
See http://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html for the -I option.
If using a Makefile, change CFLAGS or CXXFLAGS to add the -I option.
If using Visual Studio, go into the project properties dialog, select "Configuration Properties" and "VC++ Directories", and modify the "Include Directories" property. (Based on Visual C++ 2010 Express, should be similar in older versions.)
For VS 2008 C++ you need to set the following Project options:
[Project options dialog]
C\C++
Additional Include Directories = C:\Dev\Tools\Win32\SQLApi\3.8.2\include
Linker
General
Additional Library Directories - C:\Dev\Tools\Win32\SQLApi\3.8.2\lib
Input
Additional Dependencies - sqlapis.lib
Warning: example path provided!
Instead of 'C:\Dev\Tools...' set your actual SQLAPI++ library instance location!
I am learning C in Microsoft Visual C++ Express platform.
A way may work:
You should copy your own header files(like SQLAPI.h) to your solution file.
Obviously, it is a complicated way when you want to add much more of your own header files. You have to copy many times. There must be one simpler way to solve this problem by using system path or something else. But, I didn't solve it in this method totally.
Last, good luck. Hope it will be helpful.