Issue with building makefile - c++

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.

Related

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
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.

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.

How to use png++ (C++ library) on Windows?

I am trying to use this C++ library (png++) on Windows, but I unable to compile any program when I use it. Example of Code I am using to test:
#include <png++/png.hpp>
#include <png.h>
int main(){
//anything
}
When I try to compile using g++ -I path/png++ main.cpp -o main, I get
fatal error: png++/png.hpp: No such file or directory
#include <png++/png.hpp>
I understand png++ depends on libpng, I tried adding it as an I- flag, i.e. compile using
g++ -I path/png++ -I path/libpng main.cpp -o main, but it doesn't resolve the issue, png.h is found by the compiler but not png++/png.hpp.
I hope someone will be able to help.
Thanks!

problem with run a c++ code with eclipse che on ubuntu

run eclipse che by browser in ubuntu
when i run this code
#include <iostream>
main() {
std::cout << "Hello World!";
return 0; }
i got this error
cd /projects/my_prj && make && ./a.out
make: *** No targets specified and no makefile found. Stop.
what can i do for solve it?
To test that the required tooling is installed, try running this in the terminal:
cd /projects/my_prj
g++ -o a.out main.cc
(or whatever you called the C++ file you wrote above).
If you want a Makefile to build the project, you will need to specify a target (the default target will be "all") which has a rule for compiling the C++ code into a binary. The minimum would be something like this:
all:
g++ main.cc
Put this in a file called Makefile, and make sure that the 2nd line starts with a real tab, not an expanded one, and you should be good. There is a lot more to learn about Makefiles, but this will get you started.

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.