Question:
Can't compile a file in Linux Mint?
Nick
2013-09-03 13:14:19 UTC
I am trying to compile code in linux mint ( a virtual linux environment). I have linux mint saved on my flash drive and VMware on my laptop. When I go to compile the code, it says "make: *** No targets specified and no makefile found. Stop." I have the code saved in the linux mint under documents. I am new to using Linux and any kind of virtual operating system so am I missing something small. Thanks in advance.

The code is
#include
#include
ubsing namespace std;

int main (int argc. char* argv[])
{
int count=1;

cout << "Welcome to the sample C++ program/n";

//show all command line arguments
for (int i=0; i cout << "argv[" << i << "] = " << argv[i] << endl;

//if no argument was given, prompt the user
if (argc==1)
{
cout << Enter number to repeat:";
cin >> count;
}

else
{
count = atoi( argv[1] )
}

// show line a few times
for (int i=0; i cout << "C++ is fun!/n";


return 0;
}
Five answers:
Unca Alby
2013-09-03 14:06:54 UTC
Assuming you have a C++ compiler on your machine



Assuming your file is named with the appropriate extension (.cc, .cpp, .C)



Assuming you are in a COMMAND LINE window



Assuming your file is in the CURRENT DIRECTORY (e.g., if you type "ls *.cpp" your file shows up)



Assuming (for example) the file is named "sample.cpp" (so "ls *.cpp" shows "sample.cpp")



THEN:



You can enter, "make sample"



and it should invoke the C++ compiler to create a binary executable program file named "sample" from the C++ source file named "sample.cpp".



GENERALLY you don't need a "Makefile" if all the above assumptions are valid. The "make" program defaults to looking for a list of possible source files that can be used to create the target, if there is no "Makefile" available. SOMETIMES that's not true, so it never hurts to actually create a "Makefile" for your specific program.



HOWEVER you don't need to use the "make" command either. You can enter:



gcc -o sample sample.cpp



which is essentially what the "make" command will do on your behalf (if all the above assumptions are valid).



BUT you might want to use "make" anyway, in which case, create a file named "Makefile" (no, you can NOT name it anything else -- well you can, but that's a lesson for another day)



Inside the "Makefile" include the following lines:



sample:{TAB}sample.cpp

{TAB}gcc -o sample sample.cpp



Where "{TAB}" is a physical Tab character (no, you can NOT substitute a bunch of spaces)



With those lines, you can fool around with where things are located, if you don't want to be in the same directory where the source is located, for example:



sample:{TAB}{FULL-PATH}/sample.cpp

{TAB}gcc -o sample {FULL-PATH}/sample.cpp



Once you have created your "Makefile" to your satisfaction, THEN your "make" command should work no matter where you placed the source file.
Connie
2013-09-03 20:38:51 UTC
make requires a "makefile" ... a file with instructions of what program to use to compile a file, what the target would be, how to clean up afterwards. So either create a makefile

http://www.network-theory.co.uk/docs/gccintro/gccintro_16.html

or use gcc to compile your program.

Make simplifies the compilation...once you have written your makefile reperat compilation of the program and cleaning up afterwards is easy.



Compiling with gcc is also possible...but is multiple stages first to create object files then to create the actual executable file itself.

gcc
Chris D
2013-09-03 20:38:47 UTC
Congratulations on even attempting to use make - too many people don't know that it even exists.



The program is C++, so it needs to be in a file that has the cc extension. If it's called sample.cc then the command to compile it becomes "make sample".
Aaron
2013-09-03 20:37:13 UTC
Just a couple of thoughts.



Make sure you have the Development Tools group installed if you haven't already.



What command are you using to compile the file?

I would try using gcc if you aren't



#>gcc filename



-HTH
Jim
2013-09-04 02:28:43 UTC
it's been years since I wrote a Makefile...



you need to have a Makefile and in it you need to have a target, like all: foillowed by your dependencies.

your lines to compile should follow with a preceding tab character (must be a tab).



one target you can have to compile .c files is

.c.o:

here's the manual, read it.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...