3

I've followed every single guide I could possibly find but to be completely honest I have no idea what some installation 'steps' even mean.

I tried installing Cygwin (and MYSY) and running the commands that the guides told me to, but the terminal either doesn't do anything or it gives me the error: 'no such file or directory'. (I changed the folder directory to where my files where)

Also I'm not entirely sure I installed everything correctly because I should've checked some add-ons during the installation right? I did as in the guide but still I maybe missed something...

Could someone please explain to me step by step how to install it saying explicitly all that has to be done, (I'm running windows 7) considering It's the first time I do such thing and I have no idea what ./configure , make and all the other commands even mean...

asked Oct 7, 2018 at 8:53
6
  • 1
    Whats your usual environment (IDE? compiler?) when doing C++? Commented Oct 7, 2018 at 9:10
  • Please note you have not told us anything clear of what are you doing and where is the problem. Cygwin setup installs as default a minimal set of base programs; compiler, make and other tools must be required specifically. GMP packages are alread available in cygwin: libgmp-devel , libgmpxx4, libgmp10 Commented Oct 7, 2018 at 9:37
  • @matzeri Basically I need gmp to have arbitrary precision on integers for a program i'm writing, I did all the steps of the following video :youtube.com/watch?v=osr1x5F3fmI But at the end when I go to "project" -> "project options" -> "parameters" -> "linker" and i search for "libgmpxx.a" and "libgmp.a" they're not there and #include <gmp.h> and #include <gmpxx.h> result in an error (since clearly the library is not there) that being said, other methods didn't help me whatsoever, as I said, every command I write in cygwin or MYSY give me either no response or that one error Commented Oct 7, 2018 at 10:57
  • "libgmpxx.a" and "libgmp.a" are static library. Cygwin uses shared ones so libgmp-devel contains the .dll.a versions. cygwin.com/packages/x86_64/libgmp-devel/libgmp-devel-6.1.2-1. PS: every command tell me nothing give us some examples and we can guide you. Commented Oct 7, 2018 at 11:07
  • I thought msys2 had pre-built GMP packages... Commented Oct 7, 2018 at 12:13

1 Answer 1

3

The following is a simple step by step using only cygwin tools.

To compile C++ we need the g++ compiler; to locate the correct package to be installed the cygwin tool is cygcheck (that is installed by default), with the -p switch it interrogates the database at https://cygwin.com/packages/:

$ cygcheck -p bin/g++
Found 3 matches for bin/g++
gcc-g++-7.3.0-1 - gcc-g++: GNU Compiler Collection (C++)
gcc-g++-7.3.0-2 - gcc-g++: GNU Compiler Collection (C++)
gcc-g++-7.3.0-3 - gcc-g++: GNU Compiler Collection (C++)

so we need the gcc-g++ package.
To install it, we run the cygwin setup, select the Full view, search the gcc-g to filter the thousands of packages and click on skip at the gcc-g++ row

enter image description here

after complety the installation, to verify we have it correctly installed:

$ cygcheck -c gcc-g++
Cygwin Package Information
Package Version Status
gcc-g++ 7.3.0-3 OK

Installing gcc-g++ will pull also the installation of the C compiler package gcc-core.
To compile a gmp program we need the proper header and shared library; that are usually included in a "*-devel" package:

$ cygcheck -p include/gmpxx.h
Found 9 matches for include/gmpxx.h
libgmp-devel-6.1.0-3p1 - libgmp-devel: Library for arbitrary precision arithmetic (development) (installed binaries and support files)
libgmp-devel-6.1.1-1 - libgmp-devel: Library for arbitrary precision arithmetic (development) (installed binaries and support files)
libgmp-devel-6.1.2-1 - libgmp-devel: Library for arbitrary precision arithmetic (development)
mingw64-i686-gmp-6.0.0a-2 - mingw64-i686-gmp: Multiple Precision arithmetic library for Win32 toolchain (installed binaries and support files)
...

All the packages with mingw64 are for cross compiling and we can ignore, so it is libgmp-devel. Verifying that is properly installed

$ cygcheck -c libgmp-devel
Cygwin Package Information
Package Version Status
libgmp-devel 6.1.2-1 OK

And the package content is the header files and the import libraries

$ cygcheck -l libgmp-devel
/usr/include/gmp.h
/usr/include/gmpxx.h
/usr/lib/libgmp.dll.a
/usr/lib/libgmpxx.dll.a

Now we can program one example, I am taking it from https://gmplib.org/manual/C_002b_002b-Interface-General.html and written in a file called mpz_add.cpp You can use whatever editor you want. The important is that the file follows the Unix line termination standard LF and not the Windows CR+LF (see note below if not)

$ file mpz_add.cpp
mpz_add.cpp: C++ source, ASCII text
$ cat mpz_add.cpp
#include <gmpxx.h>
#include <iostream>
using namespace std;
int main (void)
{
 mpz_class a, b, c;
 a = 1234;
 b = "-5678";
 c = a+b;
 cout << "sum is " << c << "\n";
 cout << "absolute value is " << abs(c) << "\n";
 return 0;
}

To compile our example and test it:

$ g++ mpz_add.cpp -lgmpxx -lgmp -o mpz_add
$ ./mpz_add
sum is -4444
absolute value is 4444

We can also verify which library are linked in the program mpz_add, I added some extra comment:

$ cygcheck ./mpz_add
D:\cyg_pub\tmp\gmp\mpz_add.exe
 D:\cygwin64\bin\cygwin1.dll <= cygwin library
 C:\WINDOWS\system32\KERNEL32.dll <= windows system library
 C:\WINDOWS\system32\ntdll.dll ...
 C:\WINDOWS\system32\KERNELBASE.dll ...
 D:\cygwin64\bin\cyggmp-10.dll <= GMP C library
 D:\cygwin64\bin\cyggmpxx-4.dll <= GMP C++ library 
 D:\cygwin64\bin\cyggcc_s-seh-1.dll <= C library
 D:\cygwin64\bin\cygstdc++-6.dll <= C++ library

If the file has the wrong line termination, the best tool is d2u (Dos to Unix)

$ cygcheck -p bin/d2u
Found 6 matches for bin/d2u
...
dos2unix-7.4.0-1 - dos2unix: Line Break Conversion
$ file mpz_add.cpp
mpz_add.cpp: C++ source, ASCII text, with CRLF line terminators
$ d2u mpz_add.cpp
dos2unix: converting file mpz_add.cpp to Unix format...
$ file mpz_add.cpp
mpz_add.cpp: C++ source, ASCII text

As you added also the tag makefile and autotools, the first is in the package make:

$ cygcheck -p bin/make.exe
Found 6 matches for bin/make.exe
..
make-4.2.1-2 - make: The GNU version of the 'make' utility 

The second is more complex and you need the packages autoconf automake and libtool,

answered Oct 7, 2018 at 21:03
Sign up to request clarification or add additional context in comments.

6 Comments

Everything worked fine untile the "example", '$ file mpz_add.cpp', once I write that in cygwin I get: 'mpz_add.cpp: cannot open `mpz_add.cpp' (No such file or directory)', I don't know anything about editors... I'm really confused! Do I have to "install" mpz_add.cpp separately?
You need to write it, do you expect that the file will appear magically on your PC? Copy and paste the text after $cat.. line in a text file and save as mpz_add.cpp. Any text editor is fine: Notepad (included in Windows) , Notepad++ , ... (google gave me this list lifewire.com/best-free-text-editors-4155819) . I use Vim, but it is probably too different from your know-how baseground
This all is kinda looking like magic to me! Anyway, on a more serious note, I wrote that code on notepad, saved as you told me to but I'm still getting the same error, It created the file, do I have to put it in a specific directory? also, once I want to write a program, can't I go into c++ and just write '#include <gmpxx.h>' to have the library? Or I need to write it on a text file and compile it in a different way? (I'm sorry to ask all this questions, it's just, I'ts the first time I do such thing and forums online are really confusing)
You can to put it where your Mintty shell open (usually C:\cygwin\home\your_user), or you can change your working directory where you put the file . C++ is a language, do not confuse it with the Dev-C++ development enviroment that you have installed.
Okay, the example worked! so, let me try to make sense of what i'm supposed to do now, I write my program, say, in Dev-C++, then I just copy the whole code, paste it in a text file, save it with some name, say, 'prog.cpp', put it in my directory, go into cygwin and do '$ g++ prog.cpp -lgmpxx -lgmp -o prog', then to run it I write '$ ./prog', Does it work this way?
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.