I'm trying to learn programming and I'm having some trouble with a makefile;
I'm trying to make a makefile but when I go to compile it this error comes up:
$ g++ -o Makefile Makefile.cpp
Makefile.cpp:2:9: error: stray ‘@’ in program
g++ -o $@
^
Makefile.cpp:1:1: error: ‘line’ does not name a type
line.exe: line.cpp
Also, my program is not called line, if that has anything to do with it!
when I tried to make a new makefile all that poped up was that the command was not found
Also, can someone please tell me what is a makefile with debugging info in it?! I know what it means literally, it's a makefile with debugging information but I mean how do you put this debugging into it
Um, there shouldn't be any file named "Makefile.cpp". A makefile is not C++ code.
Here's a simple example to help get started.
parity.hpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Header file for the parity module
#pragma once
#ifndef PARITY_HPP
#define PARITY_HPP
namespace physicsgirl
{
bool parity( unsignedlonglong n );
// returns TRUE if there are an odd number of bits in n
// returns FALSE if there are an even number of bits in n
} // namespace physicsgirl
#endif
parity.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include "parity.hpp"
namespace physicsgirl
{
bool parity( unsignedlonglong n )
{
unsigned p = 0;
while (n != 0)
{
p++;
n &= n - 1;
}
return p & 1;
}
} // namespace physicsgirl
#include <iostream>
#include <sstream>
#include <string>
#include "parity.hpp"
usingnamespace std;
usingnamespace physicsgirl;
int main()
{
while (true)
{
cout << "Enter a whole number (or nothing to quit)> " << flush;
string s;
getline( cin, s );
if (s.empty()) break;
istringstream ss( s );
unsigned n;
ss >> n;
if (!ss.eof())
{
cout << "That's not a number! Try again.\n\n";
continue;
}
if (parity( n )) cout << "odd bitcount!\n\n";
else cout << "even bitcount!\n\n";
}
return 0;
}
Ok, so now we have two source files and a header. You want to make it easy to compile your program (just type 'make' at the command line). We'll write a makefile to do it:
Left of the colon (:) is the target name. Right of the colon is the files required to make the target. The instructions to make the target come underneath. (Notice how that indent is a HT character, not spaces!)
There is a lot more to learn about how to write makefiles. Google around them for help. One of the best places to learn what you can do is by reading the GNU make documentation.
(Your directory should now contain the files:
main.cpp
makefile
parity.cpp
parity.hpp
Type 'make' or 'gmake' [as appropriate] to build your program.)