Why isn't "mingw32-make.exe" working in a makefile - c++

So I have these three files:
Linking.cpp:
#include "Liking.h"
int main()
{
print();
}
Liking.h (I missed the "h" in the names of the files and I'm afraid to change it and got some problems):
#pragma once
void print();
liking2.cpp:
#include <iostream>
#include "Liking.h"
#include <string>
void print()
{
std::string name;
std::cout << "Insert your name: ";
std::cin >> name;
std::cout << "Your name is: " << name<< std::endl;
}
Now my question is about using makefile in order to link these .cpp files so I made one and it is this:
Linking: Linking.o liking2.o
g++ Linking.o liking2.o -o Linking
Linking.o: Linking.cpp
g++ -c Linking.cpp
Linking.o: liking2.cpp
g++ -c liking2.cpp
clean:
rm *.o Linking
But the problem comes (at least this is what I'm thinking I'm missing) when I try to use this beacuse I don't have any clues. The videos I've watched on youtube showed the "make" word but it doens't seem to work. I've searched a lot and I found the "mingw32-make.exe" but when I open the make file in my Visual Studio code (By the way I'm also using windows) and use this command in the terminal I get this problem:
makefile:8: warning: overriding recipe for target 'Linking.o'
makefile:5: warning: ignoring old recipe for target 'Linking.o'
g++ -c liking2.cpp
g++ Linking.o liking2.o -o Linking
g++: error: Linking.o: No such file or directory
makefile:2: recipe for target 'Linking' failed
mingw32-make: *** [Linking] Error 1
Now I know that this kind of question is asked a lot (I know because I've searched) but the only three question I saw that could clarify had all problems so they didn't help me at all:
Makefile --mingw32-make.exe
mingw32-make.exe : *** missing separator. Stop
mingw32-make.exe: *** [All] Error 2 - Codelite
If you guys could at least put me on the right path about what I'm missing that would be really helpful

Thanks to the explanations in the comments and also following their advice I'll post here the fixed code and I'll explain the differences:
Linking: Linking.o liking2.o
g++ -o Linking Linking.o liking2.o
Linking.o: Linking.cpp
g++ -c Linking.cpp
liking2.o: liking2.cpp
g++ -c liking2.cpp
clean:
rm *.o Linking
Now taking the answer from the question: makefile error no such file or directory I changed the second line of code where I moved the -o Linking to the beginning and also, as it was pointed out in the comments, I did a mistake in the seventh line where I used two recipes to the same target, don't do this with your makefile as well. These changes that I did were enough to make the makefile work and I hope that this answer will be able to help other people as well in the future and thank you for all for the help.

Related

Getting error: fatal error: curl/curl.h: No such file or directory #include <curl/curl.h>

I'm trying to use cURL but every time I try to compile a project with it, I get the same error mentioned in the title. I am aware of the dozen or so post about similar issues. However, most of the solutions I've read so far either don't work or I can't seem to find an analog for me as I'm using mingw32 on a windows 10 OS.
I am trying to use the curl-7.76.1-win32-mingw.zip. I got it from the cURL site, and no matter where I try to stick the files, I can't get anything to compile correctly.
Someone, please explain your solution or ideas to me like I'm 5. My brain has melted.
Here is the actual error:
PS C:\Users\Me> g++ -I "C:\Program Files\Curl\curl-7.76.1-win32-mingw\include\curl" -c "D:\Personal\Projects\#####\#####\#####\#####\main.cpp" -o "D:\Personal\Projects\#####\#####\#####\#####/main"
In file included fromD:\Personal\Projects\#####\#####\#####\#####\main.cpp:4:
D:\Personal\Projects\#####\#####\#####\#####\testapi.hpp:7:10: fatal error: curl/curl.h: No such file or directory
#include <curl/curl.h>
^~~~~~~~~~~~~
compilation terminated.
[Finished in 0.6s]"
Mingw is gcc for windows. Practically everything that applies to gcc applies to mingw.
It's better to use relative paths in your Makefile and with gnu make (which is part of mingw/msys) always use '/' as path separator. If you have to use absolute path like C:\dev\projects\mylib use it this way: C:/dev/projects/mylib.
Back to your curl: curl/curl.h is in C:\path\to\curl-7.76.1-win32-mingw\include\curl\curl.h so you need to add include directory to your gcc command line that points to the right directory, which is C:\path\to\curl-7.76.1-win32-mingw\include because you use "curl/curl.h". If you don't have it (that curl) installed system wide it's also better to use "curl/curl.h" in #include path than <curl/curl.h>.
So all you have to do is add -Ipath/to/curl-7.76.1-win32-mingw/include to your compile line, like:
g++ -O2 -Ipath/to/curl-7.76.1-win32-mingw/include -c -omain.o main.cpp
It can be done automatically in Makefile:
CXX = g++
CFLAGS += -O2
INCLUDES += -Ipath/to/curl-7.76.1-win32-mingw/include
.cpp.o:
$(CXX) -c $(CXXFLAGS) $(INCLUDES) $*.cpp
You write:
g++ -I "C:\Program Files\Curl\curl-7.76.1-win32-mingw\include\curl"
try better:
g++ -I "C:\Program Files\Curl\curl-7.76.1-win32-mingw\include"
as you have written in the code sample:
#include <curl/curl.h>
or conserve the -I option as it was, and change your #include to:
#include <curl.h>
I sincerely hope this will help.

Can't build SSDL from the source code of the book C++ for the Lazy Programmers

I can't compile the SSDL source code from the book C++ for the Lazy Programmers (2019) by Will Briggs on my ubuntu 20x so could you please tell me what goes wrong? I installed SDL2 and it's working but most of the cases I get the following error when I compile an SSDL code;
cpp-for-lazy-programmers/ch1/hello$ make -f Makefile.unix
g++ -c -g sdl2-config --cflags -I…/…/external/SSDL/include main.cpp -o main.o
In file included from …/…/external/SSDL/include/SSDL.h:27,
from main.cpp:7:
…/…/external/SSDL/include/SSDL_display.h:28:10: fatal error: SDL_ttf.h: No such file or directory
28 | #include <SDL_ttf.h>
| ^~~~~~~~~~~
compilation terminated.
make: *** [Makefile.unix:60: main.o] Error 1
I just can't understand why SDL_ttf is a big issue as I see many posts regards to SDL_ttf?
Just because they both have "SDL" in the name does not mean they are part of the same library.
If you search for SDL_ttf.h on packages.ubuntu.com ("contents of packages"), it will tell you that you want the libsdl2-ttf-dev package
This is also mentioned in the accompanying documentation.

Issue with building makefile

I am trying to build a simple makefile for c++ using g++. Even a simple makefile is not working on my computer (MacOS X).
I followed this tutorial
Create the same files and makefile. I just replaced CC=gcc to CXX=g++, in makefile2. I am using c++ format for files.
I can compile it with g++, (in command line)
But when I try to make it by "make" command I get the following error.
make: *** No targets specified and no makefile found. Stop.
Format and directory are correct.
Any help is appreciated.
Here is makefile:
CXX=g++
CFLAGS=-I.
hellomake: hellomake.o hellofunc.o
$(CXX) -o hellomake hellomake.o hellofunc.o
"hellomake.cpp" :
#include "hellomake.h"
int main() {
// call a function in another file
myPrintHelloMake();
return(0);
}
hellofunc.cpp
#include <stdio.h>
#include "hellomake.h"
void myPrintHelloMake(void) {
printf("Hello makefiles!\n");
return;
}
hellomake.h
/*
example include file
*/
void myPrintHelloMake(void);
The issue was about makefile format. Initially it was makefile.rtf. Following comments I changed it to plain text (No extension) and the issue solved.

g++ #include file not found compiler error

I'm currently trying to simply link a file called main.cpp with boost in order to do asio(asynchronous input and output). I'm using a makefile in order to compile the C++ code into executable form. However, despite using the -I modifier on my terminal command in Mac OS X, it still cannot find the appropriate directory to search in. Here is my code in Main
#include <asio.hpp>
int main(){
return 1;
}
and here is the makefile command that I am using
all:
g++ -Iboost_1_60_0/boost/ -o main main.cpp
In my file structure, boost_1_60_0, main.cpp, and makefile are all on the top level, where asio is in the folder boost which is in the folder boost_1_60_0. I'm very confused about this and any help would be appreciated! Thanks!
EDIT: Full error is
1 error generated.
make: *** [all] Error 1
iMats-2:SerialC++ wfehrnstrom$ make
g++ -Iboost_1_60_0 -o main main.cpp
main.cpp:2:10: fatal error: 'asio.hpp' file not found
You should use -Iboost_1_60_0 (or, better still, install Boost properly so that it's found automatically under /usr/include/), and write #include <boost/asio.hpp>.
The include directives inside Boost itself will assume this form, so…
BTW, this has nothing to do with exceptions. Presumably it's a compiler error you've seen.

MathGL libmgl.so.7.2.0 not found

I have downloaded and compiled MathGL following the instructions on sourceforge without any errors occuring.
When I ran my first test-program:
(The <> brackets in line 1 seem so delete it but they are there in the code)
#include mgl2/mgl.h
int main(){
mglGraph gr;
gr.FPlot("sin(pi*x)");
gr.WriteFrame("test.png");
}
the compilation with g++ -lmgl went fine.
When trying to run the programm i get:
./a.out: error while loading shared libraries: libmgl.so.7.2.0: cannot open shared object file: No such file or directory
I triple checked to be sure and libmgl.so.7.2.0 is definetely in /usr/local/lib/.
I tried telling g++ this via the -L option but that didn't work either.
Any help would be greatly appreciated
g++ -lmgl -lpng /shitfile.cpp -o /shitfile
care friend