I created a make file to run a sdl2 window
Make file
all:
g++ -I src/include -L src/lib -o main.cpp -lmingw32 -lSDL2main -lSDL2
Opened a new terminal and the command ''make'' doesn't create my .exe file, it isn't really recognized at all
is there an easier way to use the cmd terminal to create an .exe file with sdl2?
I tried going the cmd path : g++ -o main main.cpp
and the result was:
main.cpp:2:10: fatal error: SDL2/SDL.h: No such file or directory
2 | #include <SDL2/SDL.h>
| ^~~~~~~~~~~~
compilation terminated.
So apparently the problem is that my file doesn't include SDL.h even tho it is present in the SDL folder.
Also cmd straight out deleted my ''main.cpp' file.
Also tried mingw32-make in the terminal and it also deleted my main.cpp file and found the same errors.
Related
So I am trying to compile a file (main.cpp) that has
#include <SFML/Graphics.hpp>
My main.cpp file is in the directory:
~/"Documents/16_Games/01 Tetris/main.cpp"
The Graphics.hpp file is in the directory:
/Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include/SFML
The error I am receiving is:
/Users/linsu/Documents/16_Games/01 Tetris/main.cpp:1:10: fatal error: 'SFML/Graphics.hpp' file not found
#include <SFML/Graphics.hpp>
^~~~~~~~~~~~~~~~~~~
1 error generated.
Some commands I've tried include:
g++ -I /Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include/SFML ~/"Documents/16_Games/01 Tetris/main.cpp"
g++ -I/Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include/SFML ~/"Documents/16_Games/01 Tetris/main.cpp"
g++ -L /Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include/SFML ~/"Documents/16_Games/01 Tetris/main.cpp"
g++ -L/Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include/SFML ~/"Documents/16_Games/01 Tetris/main.cpp"
g++ -L/Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include/SFML -I/Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include/SFML ~/"Documents/16_Games/01 Tetris/main.cpp"
g++ -L /Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include/SFML -I /Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include/SFML ~/"Documents/16_Games/01 Tetris/main.cpp"
All of them throw the same error; I feel dumb. Am I missing something?
The compiler will only search through the exact path you provided, not through the whole chain of subdirectories. It appends the name you provided (SFML/Graphics.hpp) to all the paths it can look for.
It looks in all the system header locations, in current directory (./SFML/Graphics.hpp) and for a concatenation of path provided with -I and filename provided by the programmer:
/Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include/SFML/SFML/Graphics.hpp
Since none of these locations contains such file, compiler fails.
You want:
g++ -I/Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include ~/"Documents/16_Games/01 Tetris/main.cpp"
Notice that SFML directory is not in the -I option, because it's provided already in your code.
I'm trying to compile a C++ program on my MacBook CLI using:
g++ -o -I/Users/user/SQLAPI/include/SQLAPI.h program driver.cpp
but getting the error:
driver.cpp:3:10: fatal error: 'SQLAPI.h' file not found
#include <SQLAPI.h>
^~~~~~~~~~
I placed the download from https://www.sqlapi.com/Download/ into directory /Users/user/SQLAPI/. I've confirmed that the SQLAPI.h file is in /Users/user/SQLAPI/include/SQLAPI.h, so I'm confused as to why my g++ isn't recognizing the header file. Please help!
The argument for -I is the directory to search for the headers.
The argument for -o is the output file name.
You most probably want to:
g++ -I /Users/user/SQLAPI/include -o program driver.cpp
Which of course most probably will solve only the current include problem and will not link with SQLAPI library.
I am new to programming; I'm starting a new job and I have to resume what the fellow before me did.
So I have to run a program called test.cpp in C++. This code contains a header called misc.hpp located in a subfolder of where test.cpp is called include.
When I open the terminal from where test.cpp is and run g++ test.cpp it tells me that:
test.cpp:4:19: fatal error: misc.hpp: No such file or directory.
I also tried the g++ test.cpp -I include/misc.cpp but same thing
Could you please help me?
The -I (upper-case i) option is to add a directory to search for header files. It's not for including source files.
So if the header file is include/misc.hpp then you should do
g++ test.cpp -Iinclude
-I include/misc.cpp doesn't work because:
The file is misc.hpp, not misc.cpp
You do not include files like this
-I is for include directories
So:
g++ test.cpp -I include
When I try to compile C++ programm in Code::blocks it gives me this error:
-------------- Build: Debug in elcounter (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Weffc++ -Wall -std=c++14 -fexceptions -Weffc++ -std=c++14 -g -I"C:\Users\Zahir\Box Sync\CPP projects\September_2k16\elcounter\" -c "C:\Users\Zahir\Box Sync\CPP projects\September_2k16\elcounter\main.cpp" -o obj\Debug\main.o
mingw32-g++.exe: error: Sync\CPP: No such file or directory
mingw32-g++.exe: error: projects\September_2k16\elcounter\main.cpp -o obj\Debug\main.o: No such file or directory
mingw32-g++.exe: fatal error: no input files
I am using MinGW g++ compiler.
Just for a test, I tried to compile simple "Hello, world" file and it gave me the same error.
Compiled the same "Hello, world" file in a command line using
"g++ test.cpp -o hello.exe" and in worked just fine, so I believe the compiler is installed correctly.
The error seems to be related to spaces in a file path.
C:\Users\Zahir\Box Sync\CPP projects\September_2k16\elcounter\
mingw32-g++.exe: error: Sync\CPP: No such file or directory
mingw32-g++.exe: error: projects\September_2k16\elcounter\main.cpp -o obj\Debug\main.o: No such file or directory
Might be a problem with a build system in Code::blocks? I tried to copy the command code::blocks using to a command line and it gave the same error. (mingw32-g++.exe -Weffc++ -Wall etc.)
EDIT: I don't want to change file path because "Box Sync" is used by the same name app that synchronizes file with a cloud.(box.com) The app doesn't support changing the main folders name and I'd prefer the project files stay synchronized.
Looks like you need to remove all spaces from file and folder names in your project.
In your case it's the 'CPP projects' folder and 'box sync'
Edit: whoops. Forgot to put the correct link while formatting
I'm following this tutorial, but I have gotten an error I can't fixed (I've looked at my code and then back at his for around 25 minutes. I'm sure it's not a typo anywhere)
C:\Users\badfitz66\Rastering>make
g++ makefile.cpp -o makefile
g++: error: CreateProcess: No such file or directory
make: *** [makefile] Error 1
The code of makefile.cpp is:
OBJ = main.o
INC = -I "./"
Rastering: $(OBJ)
g++ $(OBJ) -o Rastering.exe
rm -f $(OBJ)
main.o:
g++ -c main.cpp $(INC)
clean:
rm -f $(OBJ) Rastering
When you write -o makefile it means you want your C++ compiler to write its output to a file named makefile. Since Windows has case-insensitive file systems, that is a very bad idea because you will end up overwriting your Makefile, which should be named Makefile.
Also, you seem very confused about the difference between a Makefile and a C++ file. The file you posted is a Makefile, so it should be named Makefile, not makefile.cpp. You will need to have at least two files: Makefile, and main.cpp. If you want more help, you will have to show us the full contents of both of those files and the exact output you get when you run make.
The error g++: error: CreateProcess: No such file or directory is usually caused by your toolchain not being installed properly. You will need to install a C++ compiler that provides an executable named g++.exe and make sure that you add the directory with g++.exe in it to your PATH environment variable. The tutorial video you linked to ought to tell you how to do that.