Well, I've followed all the tutorials and it's still not working. I don't know where else to turn cause google isn't helping much. Tried figuring it out myself but couldn't...
I did sudo apt-get install building essentials
and sudo apt-get install g++
I then proceeded to take a sample program and enter it
Next I proceeded to type
g++ HelloWorld.cpp -o HelloWorld
I'm getting this error
g++: error: HelloWorld.cpp: No such file or directory
g++: fatal error: no input files
compilation terminated...
Anyhelp would be appreciated.
Now i've tried letting it know where my file is Desktop/HelloWorld/HelloWorld.cpp -o HelloWorld.o and it just enters the text and gives me a new line to type in. Nothing happened
no it wouldnt its a wild card variable. its how i used to compile for long names. what it would do is with the first * (in the .cpp) it gets the name of the first .cpp file and then * holds the value. then its still in the second * becuase thats being read in as a wild card thats not a file. i could be completely wrong but it would work for me when i was being lazy and it was the only .cpp file in the dir
¿What shell do you use?
in sh * expands to anything
$ ls
a one.cpp two.cpp
$ g++ *.cpp -o *
# equivalent to
# $ g++ one.cpp two.cpp -o a one.cpp two.cpp
# I guess that -o will only take the first argument
# $ g++ one.cpp two.cpp one.cpp two.cpp -o a
error: multiple definition
$ ls
one.cpp two.cpp
# `a' was overwritten and lost
If you only have 1 cpp then
$ ls
hello.cpp
$ g++ *.cpp -o *
# $g++ hello.cpp -o hello.cpp
$ ls
hello.cpp
$ ./hello.cpp
hello world
# you do have the executable, but lost the source
i just use the normal bash shell, but it just does it to the first one. and no your wrong. if i have *.cpp for a file called one.cpp its not going to expand to one.cpp.cpp its going to expand to one.cpp -o one. if i just did one * like this
g++ * -o * then it expands to g++ one.cpp -o one.cpp and then the exe is named one.cpp.exe
Do that (`script' would be better). Then issue a bug to bash.
> if i have *.cpp for a file called one.cpp its not going to expand to one.cpp.cpp
I never said that. You need to make it parse, so * -> one to form one.cpp
However when you do
g++ *.cpp -o *
It translate to
g++ one.cpp -o one.cpp
because they are independent
Edit:
> it expands to g++ one.cpp -o one.cpp and then the exe is named one.cpp.exe
¿exe? ¿why does it add a suffix?
Firstly you handle your directory to as home
-> in console . > cd home
cd home won't work unless you are in the directory above home. And home is not your directory - /home/halitciftcise is for example
In UNIX / Linux, there are some short cuts to one's home directory. The simplest is just cd., next there is cd ~ , and this is also handy for getting to a subdirectory of your home directory as in cd ~/Desktop
In my mind, one way would be to compile like this:
Edit: And this is done in the directory where the .cpp files are, normally each project would have it's own directory.
As you can see it specifies the name of the executable explicity. Also be aware there are traps in that, what if there are old versions of .cpp files - it will attempt to compile them as well. That leaves you with trying to specify more complicated wild cards (regular expressions) to avoid that.
So the final answer is: Don't use wild cards to compile files unless you know what you are doing. Normally, one uses make files anyway.