'Why isn't "mingw32-make.exe" working in a makefile
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
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Isaias |
