GLFW/glfw3.h included failed - c++

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.

Related

How qt find <Qxxx/qxxx.h>?

In Qt 6.4.0, we can use such code to include qt components:
#include <QtCore/qchar.h>
#include <QtCore/qbytearray.h>
#include <QtCore/qbytearrayview.h>
#include <QtWidgets/qtwidgetsglobal.h>
But I found that the real paths of those .h file are NOT under such folder like QtCore, QtWidgets etc. , actually most of them are under such directory:
/Users/tony/Qt/6.4.0/macos/lib/QtXXX.framework/Headers/qtxxx.h
I'm wondering that since QtCore is not the real path but Headers, Shouldn't we write #include "Headers/qtxxx.h" ? how can #include <QtCore/qchar.h> such path works?
Using the -I argument
You have to tell to your compiler which directory you want to include to find the headers properly. For example in clang and gcc you can use this directory as -I argument, like this:
clang++ yourprogram.cpp -I /Users/tony/Qt/6.4.0/macos/lib/QtXXX.framework/Headers/
And in your source code you will write includes at this way:
#include "QtCore/qchar.h"
#include "QtCore/qbytearray.h"
#include "QtCore/qbytearrayview.h"
#include "QtWidgets/qtwidgetsglobal.h"
Note it uses " " instead < >, this means you are finding the included files relative to your compile options instead of your system.
Although this works, it's recommended to use relative paths of your project to point headers directories.
It's been solved: This phenomenon only shows on MacOS since MacOS uses "framework" to organize a set of lib and headers, which can be parsed by the clang-module name to the realpath.

gtk/gtk.h: No such file or directory, on Windows, using VS code

I try to compile a cpp file with this header:
#include <stdlib.h>
#include <gtk/gtk.h>
I work with MSYS2, so both the compiler and the gtk library are installed through it. The cpp compiler path is:
D:\msys\usr\bin\cpp.exe
and here is the VS code include path additions, which I supplied to the IntelliSense Configurations page under "include path":
D:\msys\mingw64\include\gtk-2.0\**
D:\msys\mingw64\include\**
D:\msys\mingw64\lib\**
D:\msys\usr\include\**
and I have gtk etc. in the include folder. I actually installed three different versions of gtk, 2-4.
Before I added them to the include path, I got an error like "cannot open source file", and after adding them I get the
fatal error: gtk/gtk.h: No such file or directory
error. gtk/gtk.h is located just inside gtk-2.0. What am I doing wrong?
Thanks a lot.

C++ include error from #include "DevEngine/Core.h"

So there are 1 files that I want to link together, Core.h and Events.h.
Core.h is in a folder called DevEngine and the Events.h file is in a folder called Events witch is inside DevEngine.
Here are the file directorys:
Core.h = src/DevEngine/Core.h
Events.h = src/DevEngine/Events/Events.h
I have added a #include "DevEngine/Core.h" : Cannot open include file: 'DevEngine/Core.h': No such file or directory DevEngine. I don't know where I have went wrong.
I have tried: #include "../DevEngine/Core.h". That still gives me a error.
You can do #include "../Core.h".
You can also set the directories the compiler uses to search for the header files (-I option in gcc) and then use paths to those files relative to one of those directories. (See for example gcc documentation on search paths.)
This could be done differently depending on the way you are building the project.
For Visual Studio, look in this thread.
For CMake, use include_directories.

How to include third party libraries in C++ windows?

I have the boost library in my downloads folders. When I tried to include a particular file. It is throwing errors. Below is the code and the steps I did.
\main.cpp
#include "type_index.hpp"
int main(){
//some code
return 0;
}
I opened the command prompt and ran the following command
g++ -IC:\Users\Owner\Downloads\boost_1_70_0\boost -o main main.cpp
I got the following error in command prompt
In file included from main.cpp:2:0:
C:\Users\Owner\Downloads\boost_1_70_0\boost/type_index.hpp:17:28: fatal error: boost/config.hpp: No such file or directory
#include <boost/config.hpp>
^
compilation terminated.
How can I run the above file? Do I have to change the location of boost directory from downloads folder to some where within mingw directories?
Adding the picture of directory:
Assuming boost is correctly configured and built on your system, there will be a location where the hub of the boost include root is located. Ex: if you downloaded and built boost in c:\Stuff\boost_1_70_0, then within that folder will be the hub of the boost include set, c:\Stuff\boost_1_70_0\boost, and it contains all of the boost headers.
boost is referenced by amending the include path to provide access to the boost include hub; not to provide access to the top-most headers in the hub. Similar to openssl, boost prefaces all of their header includes in their own headers, with boost/. The consumers of boost should do the same, Therefore, the include path must include the folder where the boost/ hub can be found. It should not include the boost/ hub itself as part of the path.
Ex: This is correct
g++ -Ic:\Stuff\boost_1_70_0 -o main main.cpp
This, on the other hand is wrong:
g++ -Ic:\Stuff\boost_1_70_0\boost -o main main.cpp
With the former, when code includes:
#include <boost/asio.hpp>
the include path is searched, and the file is found. Further, within that header, when the compiler see this:
#include <boost/asio/associated_allocator.hpp>
it can still resolve correctly, because dropping that "thing" on the end of one of the folders in the include path works.
Now, consider the wrong case. What happens if you configure the include path to accidentally specify the boost/root hub itself? Well, now you can do this:
#include <asio.hpp>
But as soon as the preprocessor starts in on that header it will see:
#include <boost/asio/associated_allocator.hpp>
Um.. woops. The pre-processor will look for this and never find it
Summary
When using boost headers in your source, you always refer to them with the boost hub preamble:
#include <boost/headername.hpp>
and always include the folder where the boost/ hub is located in your build configuration as an amended include path; not full path including the boost/ hub.

Include statement: can't find SDL/SDL.h file

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.