Cygwin doesn't make an executable when expected - windows

I'm running Cygwin on Windows 7 and trying to build a program I downloaded. I cd to where I have my file.tar.gz and type
tar -xvf file.tar.gz
and Cygwin successfully spits out a list of what's in there. (point of confusion: for some reason, -xvzf doesn't work, even though the file claims to be zipped. Also, I expected there to be an untarred folder put somewhere in my directory, but there's not.)
Then I type
make
and get
c++ -O -c gmm.c -o gmm.o
make: c++: No such file or directory
make: *** [makefile:19: gmm.o] Error 127
I expected this to create a gmm.exe (according to the documentation of this program). What's going on?

As #stark mentioned you are missing the C++ compiler.
To find in which package is, use cygcheck -p to ask the Cygwin Webserver
$ cygcheck -p bin/c++
Found 17 matches for bin/c++
...
binutils-2.35.2-1 - binutils: GNU assembler, linker, and similar utilities
...
gcc-g++-10.2.0-1 - gcc-g++: GNU Compiler Collection (C++)
gcc-g++-7.4.0-1 - gcc-g++: GNU Compiler Collection (C++)
...
After you install the gcc-g++ package, you will have the program c++
in the standard directory for programs
$ cygcheck -l "gcc-g++" |grep "usr/bin/c++"
/usr/bin/c++.exe

Related

CoqIDE Make on Windows

I have GnuWin32 Make and GnuWin32 Coreutils, installed and on my PATH. This works:
coq_makefile -f _CoqProject -o Makefile.coq
make -f Makefile.coq Frap.vo
But if I open Frap.v in CoqIDE, and do Compile > Make, the only output I see is this:
Compilation output:
Is this expected? How can I get Coq to build this?

Compiling OpenSSH on 64-bit machine with debugging symbols

I am trying to compile openssh with debugging symbols, but it is not happening and i have no idea why.
wget "https://ftp.nluug.nl/security/OpenSSH/openssh-7.2p2.tar.gz"
tar xfz openssh-7.2p2.tar.gz
cd openssh-7.2p2
autoconf
./configure --with-audit=debug
make
sudo make install
objdump --syms bin/ssh
bin/ssh: file format elf64-x86-64
SYMBOL TABLE: no symbols
any thoughts why the debugging symbols are not there? please note that when I execute this command as below:
objdump --syms bin/ssh.o
I can see that symbols have been added to the object file, but not in the final executable file when the linker finish up the file.
Thanks in advance.
If you look at what make install does, you'll see
/usr/bin/install -c -m 0755 -s ssh /usr/local/bin/ssh
The -s option causes debug symbols to be stripped, just like the strip command.
Maybe there's a way to disable that?
$ ./configure --help |grep strip
--disable-strip Disable calling strip(1) on install
Oh, there we go.

problems running MAKE utility from DOS command prompt

I have:
fileMainProgram.cpp
fileClassImplementation.cpp
fileClass.h
makefile
in a directory.
Ran cmd and typed
g++ -make -f makefile
got this message after tinkering with it for a while (change file name/extension, tried without -f, used gcc instead of g++, etc)
C:\miscprograms\Dropbox\box\Dropbox\c++\etextbook\e12\progec12\pe1c12romanNumeral>g++ -make -f makefile
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe:makefile.tx
t: file format not recognized; treating as linker script
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe:makefile.tx
t:1: syntax error
collect2: ld returned 1 exit status
This is the makefile, (tried to delete the lines inbetween targets and actions, tried using automatic variables, etc,
I tried to compile the program as
g++ -c fileClassImplementation.cpp
then
g++ fileClassImplementation.o fileMain.cpp
to get an executable and it works fine.
all: a
a: romanNumeralMain.o romanNumeralImp.o
[1 tab]g++ romanNumeralMain.o romanNumeralImp.o -o a
romanNumeralMain.o: romanNumeralMain.cpp
g++ -c romanNumeralMain.cpp
romanNumeralImp.o: romanNumeralImp.cpp
g++ -c romanNumeralImp.cpp
clean:
rm romanNumeralImp.o romanNumeralMain.o a
Ran the whole thing on C4droid for my samsung phone and worked fine as is.
Doesn not work on my Windows7 laptop.
What you appear to have is a GNU Makefile, suitable for running GNU Make. Windows doesn't come with GNU Make, so you'll need to download it yourself.
It appears you've already downloaded MingW, try running the mingw32-make command to execute your makefile.

Hello World in C++ says "Nothing More to be Done" [duplicate]

How can I compile/run C or C++ code in a Unix console or a Mac terminal?
If it is a simple single-source program,
make foo
where the source file is foo.c, foo.cpp, etc., you don’t even need a makefile. Make has enough built-in rules to build your source file into an executable of the same name, minus the extension.
Running the executable just built is the same as running any program - but you will most often need to specify the path to the executable as the shell will only search what is in $PATH to find executables, and most often that does not include the current directory (.).
So to run the built executable foo:
./foo
gcc main.cpp -o main.out
./main.out
This is the command that works on all Unix machines... I use it on Linux/Ubuntu, but it works in OS X as well. Type the following command in Terminal.app.
g++ -o lab21 iterative.cpp
-o is the letter O, not zero
lab21 will be your executable file
iterative.cpp is your C++ file
After you run that command, type the following in the terminal to run your program:
./lab21
Two steps for me:
First:
make foo
Then:
./foo
All application execution in a Unix (Linux, Mac OS X, AIX, etc.) environment depends on the executable search path.
You can display this path in the terminal with this command:
echo $PATH
On Mac OS X (by default) this will display the following colon separated search path:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
So any executable in the listed directories can by run just by typing in their name. For example:
cat mytextfile.txt
This runs /bin/cat and displays mytextfile.txt to the terminal.
To run any other command that is not in the executable search path requires that you qualify the path to the executable. So say I had an executable called MyProgram in my home directory on Mac OS X I can fully qualify it like so:
/Users/oliver/MyProgram
If you are in a location that is near the program you wished to execute you can qualify the name with a partial path. For example, if MyProgram was in the directory /Users/oliver/MyProject I and I was in my home directory I can qualify the executable name like this, and have it execute:
MyProject/MyProgram
Or say I was in the directory /Users/oliver/MyProject2 and I wanted to execute /Users/oliver/MyProject/MyProgram I can use a relative path like this, to execute it:
../MyProject/MyProgram
Similarly if I am in the same directory as MyProgram I need to use a "current directory" relative path. The current directory you are in is the period character followed by a slash. For example:
./MyProgram
To determine which directory you are currently in use the pwd command.
If you are commonly putting programs in a place on your hard disk that you wish to run without having to qualify their names. For example, if you have a "bin" directory in your home directory for regularly used shell scripts of other programs it may be wise to alter your executable search path.
This can be does easily by either creating or editing the existing .bash_profile file in your home directory and adding the lines:
#!/bin/sh
export PATH=$PATH:~/bin
Here the tilde (~) character is being used as a shortcut for /Users/oliver. Also note that the hash bang (#!) line needs to be the first line of the file (if it doesn't already exist). Note also that this technique requires that your login shell be bash (the default on Mac OS X and most Linux distributions). Also note that if you want your programs installed in ~/bin to be used in preference to system executables your should reorder the export statement as follows:
export PATH=~/bin:$PATH
Do all of this in "Terminal".
To use the G++ compiler, you need to do this:
Navigate to the directory in which you stored the *.cpp file.
cd ~/programs/myprograms/
(the ~ is a shortcut for your home, i.e. /Users/Ryan/programs/myprograms/, replace with the location you actually used.)
Compile it
g++ input.cpp -o output.bin (output.bin can be anything with any extension, really. Extension .bin is just common on Unix.)
There should be nothing returned if it was successful, and that is okay. Generally you get returns on failures.
However, if you type ls, you will see the list of files in the same directory. For example, you would see the other folders, input.cpp and output.bin
From inside the directory, now execute it with ./outbut.bin
A compact way to go about doing that could be:
make foo && ./$_
It is nice to have a one-liner so you can just rerun your executable again easily.
Assuming the current directory is not in the path, the syntax is ./[name of the program].
For example ./a.out
To compile C or C++ programs, there is a common command:
make filename
./filename
make will build your source file into an executable file with the same name. But if you want to use the standard way, You could use the gcc compiler to build C programs and g++ for C++.
For C:
gcc filename.c
./a.out
For C++:
g++ filename.cpp
./a.out
Add the following to get the best warnings, and you will not regret it. If you can, compile using WISE (warning is error).
- Wall -pedantic -Weffc++ -Werror
Step 1 - create a cpp file using the command
touch test.cpp
Step 2 - Run this command
g++ test.cpp
Step 3 - Run your cpp file
./a.out
I am on a new MacBook Pro with the Apple M1 Pro chip. I have my Xcode installed - both IDE and command line tools. This is how it worked for me:
g++ one.cpp -o one
./one
Use a makefile. Even for very small (= one-file) projects, the effort is probably worth it because you can have several sets of compiler settings to test things. Debugging and deployment works much easier this way.
Read the make manual. It seems quite long at first glance, but most sections you can just skim over. All in all, it took me a few hours and made me much more productive.
I found this link with directions:
http://www.wesg.ca/2007/11/how-to-write-and-compile-c-programs-on-mac-os-x/
Basically you do:
gcc hello.c
./a.out (or with the output file of the first command)
In order to compile and run C++ source code from a Mac terminal, one needs to do the following:
If the path of .cpp file is somePath/fileName.cpp, first go the directory with path somePath
To compile fileName.cpp, type c++ fileName.cpp -o fileName
To run the program, type ./fileName
Just enter in the directory in which your .c/.cpp file is.
For compiling and running C code.
gcc filename.c
./a.out filename.c
For compiling and running C++ code.
g++ filename.cpp
./a.out filename.cpp
You need to go into the folder where you have saved your file.
To compile the code: gcc fileName
You can also use the g++ fileName
This will compile your code and create a binary.
Now look for the binary in the same folder and run it.
For running C++ files, run the below command, assuming the file name is "main.cpp".
Compile to make an object file from C++ file.
g++ -c main.cpp -o main.o
Since #include <conio.h> is not supported on macOS, we should use its alternative which is supported on Mac. That is #include <curses.h>. Now the object file needs to be converted to an executable file. To use file curses.h, we have to use library -lcurses.
g++ -o main main.o -lcurses
Now run the executable.
./main
Running a .C file using the terminal is a two-step process.
The first step is to type gcc in the terminal and drop the .C file to the terminal, and then press Enter:
gcc /Desktop/test.c
In the second step, run the following command:
~/a.out

Can't output anything using cygwin 1.7 gcc under windows

I just installed cygwin 1.7, and wrote a simple Hello world in test.c
but when I complie, nothing happens, even no error messages
gcc-4 -o test.exe test.c
And there's nothing generated under my folder.
I have included C:\cygwin;C:\cygwin\bin in my PATH
Did I miss something?
EDIT:
for more information, I installed Qt4, tortoiseHg, and mingw before.
Now I had removed mingw. but still got Qt4 and tortoiseHg, is this a problem?
Try doing this from the Cygwin Terminal, not cmd.exe:
$ cd `cygpath -u "$USERPROFILE"`/Desktop/UT
$ gcc -o foo foo.c
$ ls -l foo
-rwxr-xr-x+ 1 yourlogin None 19618 May 10 05:15 foo*
If that works, there's some bogus remnant lying around.
You'll find that the Cygwin experience is generally better running under Bash, in a MinTTY terminal anyway. cmd.exe doesn't understand Cygwinisms, and is a DOS throwback besides.
Note that you don't need to say gcc-4 to get GCC 4.x. gcc is GCC 4.x on Cygwin, and has been for quite some time now.
Also note that you don't need to include .exe in the GCC -o flag, because Cygwin GCC knows to add that already.

Resources