I'm trying to make a cookie clicker clone and when I include the SDL_ttf header file, I get an error. How do I resolve this error?
#include <iostream>
#include <SDL2\SDL.h>
#include "..\SDL2_ttf-2.0.15\i686-w64-mingw32\include\SDL2\SDL_ttf.h"
I compile with:
g++ -o test test.cpp -I../SDL2-2.0.16/i686-w64-mingw32/include -L../SDL2-2.0.16/i686-w64-mingw32/lib -lmingw32 -lSDL2main -lSDL2
I got this error message:
In file included from test.cpp:3:0:
..\SDL2_ttf-2.0.15\i686-w64-mingw32\include\SDL2\SDL_ttf.h:34:17: fatal error: SDL.h: No such file or directory
#include "SDL.h"
I'm on a windows machine (windows 10) and using sublime.
Put the -lSDL2_ttf flag in the compile line
Related
I am trying to compile a cpp using with the following command:
g++ -IC:\Users\XXX\libcurl-7.56.0\libcurl-7.56.0\include\curl -LC:\Users\XXX\libcurl-7.56.0\libcurl-7.56.0\lib program.cpp
this program has a header file which uses libcurl. the curl library is at -
C:\Users\XXX\libcurl-7.56.0\libcurl-7.56.0\include\curl\curl.h
gcc gives the following error even though curl.h is in the path -I
mylibrary.h:26:10: fatal error: curl/curl.h: No such file or directory
#include <curl/curl.h>
what am I doing wrong?
The error message means the file curl/curl.h could not be found in the search path specified by -I. You updated the question with the path to the file so the command should be:
g++ -IC:\Users\XXX\libcurl-7.56.0\libcurl-7.56.0\include -LC:\Users\XXX\libcurl-7.56.0\libcurl-7.56.0\lib program.cpp
Also, can you please try using \ instead of / as path separator in your mylibrary.h file:
#include <curl\curl.h>
I have just installed the latest stable version of wxWidget on my mac and tried to compile the code from the hello world tutorial. This is the code that is causing the error:
#include <wx/wxprec.h>'
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
My compiler throws the following warning:
hello_world.cpp:4:10: fatal error: 'wx/wxprec.h' file not found
#include <wx/wxprec.h>
^~~~~~~~~~~~~
1 error generated.
I have checked the directory where I installed wxMac and the file wxprec.h exists in the "include" sub-directory.
If anyone knows why the file cannot be found even though it exists please let me know.
I found out the answer to this problem. To fix it I used the following line to compile/build the hello world app:
g++ `wx-config --cxxflags` -o out *.cpp `wx-config --libs`
after doing this it was only a matter of sorting out the linking, adding header guards and adding in
IMPLEMENT_APP(MyApp)
and
DECLARE_APP(MyApp)
in MyApp.h and MyApp.cpp respectively which functions as the main function.
I got this information from https://wiki.wxwidgets.org/Hello_World
I am OS X user and I've recently installed "cppunit" library using brew. When I try to compile "test.cpp" file using TestCase.h header the error occurs:
> test.cpp:3:10: fatal error: 'TestCase.h' file not found
> #include "TestCase.h"
I am compiling this file:
test.cpp
#include <iostream>
#include "TestCase.h"
using namespace CppUnit;
class EmptyTest : public TestCase
{
};
int main()
{
}
Using this command:
g++ -Wall -pedantic -std=c++14 test.cpp -o test.x -lcppunit
I've also tried compiling with -I giving the path to the library directory but still with the same error.
All my friends using cppunit and brew can simply include the header and the program works fine.
I would appreciate every answer.
I've solved this problem. I had issues with Xcode. Reinstall works fine.
I'm trying to write an OpenGL program which I'm compiling through MinGW. I've managed to successfully link OpenGL, GLUT, GLFW and GLM to my main.cpp file. Given the following headers:
#include "GL/glut.h"
#include "GLFW/glfw3.h"
#include "GL/glew.h"
#include "glm/vec3.hpp"
And the following cmd line:
g++ -o leaf.exe -Wall physics.cpp -mwindows lib/glut32.lib -lopengl32 -lglu32 -lglfw3dll -lglew32 -IC:/MinGW/include/GL
I manage to get it to compile successfully. However, when placing the .a files in MinGW/lib, the .dll file in source folder and the .h file in C:\MinGW\include and adding
#include "GL/glew.h"
With the following command line
g++ -o leaf.exe -Wall physics.cpp -mwindows lib/glut32.lib -lopengl32 -lglu32 -lglfw3dll -lglew32 -IC:/MinGW/include/GL
Then I get a long list of errors including:
In file included from physics.cpp:6:0:
c:\mingw\include\gl\glew.h:85:2: error: #error gl.h included before glew.h
#error gl.h included before glew.h
In file included from physics.cpp:6:0:
c:\mingw\include\gl\glew.h:1814:94: error: 'GLchar' does not name a type
typedef void (GLAPIENTRY * PFNGLBINDATTRIBLOCATIONPROC) (GLuint program, GLuint index, const GLchar* name);
My first time trying to make something without using Visual Studio or Eclipse. Been trying lots of fixes for it I've found here but nothing concrete.
Thanks for reading this far!
You need to reorder your includes:
#include "GL/glew.h"
#include "GL/glut.h"
#include "GLFW/glfw3.h"
#include "glm/vec3.hpp"
GLFW (and GLUT?) automatically include GL.h, which is what GLEW is complaining about. Not sure why you're using GLUT and GLFW in the same build, they don't exactly go together...
I have an SDL program that I need to compile on my Mac with the line:
#include <SDL.h>
I have libsdl installed using MacPorts, and the output of sdl-config --cflags is:
-I/opt/local/include/SDL -D_GNU_SOURCE=1 -D_THREAD_SAFE
which is, indeed, where the SDL headers are located:
$ ls /opt/local/include/SDL
SDL.h SDL_cpuinfo.h SDL_keyboard.h SDL_rwops.h
...
and then my Makefile invokes the compiler (clang++) with:
CXXFLAGS=`sdl-config --cflags`
Invoking the compiler with -v shows that it is being included in the search path:
#include "..." search starts here:
#include <...> search starts here:
/opt/local/include/SDL
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.1.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
but the compiler errors with:
./drawable.h:4:10: fatal error: 'SDL.h' file not found
#include <SDL.h>
^
It compiles fine if I change it to #include <SDL/SDL.h>, but other (Linux) machines that the program needs to compile on don't specify it that way. What am I not understanding about how to set up my include path?
EDIT:
Here's a minimal example:
$ cat main.cpp
#include <SDL.h>
int main(int argc, char *argv[]) { }
$ sdl-config --cflags
-I/opt/local/include/SDL -D_GNU_SOURCE=1 -D_THREAD_SAFE
$ ls /opt/local/include/SDL/SDL.h
/opt/local/include/SDL/SDL.h
$ clang++ -v `sdl-config --cflags` main.cpp
...
#include "..." search starts here:
#include <...> search starts here:
/opt/local/include/SDL
....
main.cpp:1:10: fatal error: 'SDL.h' file not found
#include <SDL.h>
^
1 error generated.
ANSWER:
SDL.h turned out to be a broken symbolic link, my own fault.
I think in your Makefile, CXXFLAGS are not included in the compilation command.
Your Makefile should have something like:
$(CXX) $(CXXFLAGS) $(SRC) -o $(EXE)
OK, this just turned out to be my own stupidity, but maybe someone else will benefit from it. I created the /opt/local/include/SDL directory and filled it with soft links to the actual header files in /Library/Frameworks/SDL.framework/Headers, because my project relied on the former. I then, in working on another means of installing SDL, deleted the framework, leaving a bunch of dead links. ls without arguments helpfully showed me filenames, but not that they were links, which I had forgotten by this point. So, SDL.h didn't really exist. A smarter approach might have been to soft link the directory, which would have probably given a more helpful error message, but I was trying to put some other SDL package links in there too.