problem with gmp in dev-c++

after reading about the rsa cipher i wanted to make my own version.
it uses the gmp library, i think the code is all correct (except the chartonum, it enciphers each letter seperately making it a simple monalphebetic but will change later)

the problem is a bunch of linker errors if you have used gmp on dev you may have a solution. i've seen this sort of thing when using statics and constants.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <math.h>
#include <cctype>
#include <string.h>
#include <stdio.h>
#include <gmp.h>

using namespace std;

int chartonum(char letter)
{
       int result;
       result = (int)letter;
       return result;
}

int main()
{
    mpz_t key, e, ciphertext[30], value, value2, prime1, prime2;
    mpz_init(key);
    mpz_init_set_ui(e,19);
    mpz_array_init(ciphertext[0],30,512);
    mpz_init(value);
    mpz_init(value2);
    mpz_init_set_ui(prime1,7151);
    mpz_init_set_ui(prime2,8293);
    mpz_mul(key, prime1, prime2);
    string plaintext;
    bool run=true;
    cout.precision(20);
    while(run){
    cin >> plaintext;
    for(int i=0;i<plaintext.length();i++)
    {
           mpz_set_ui(value, chartonum(plaintext[i]));
           mpz_powm(ciphertext[i], e, value, key);
           cout << ciphertext[i] << endl;
    }
}
    return 0;
}



errors
C:\DOCUME~1\***\LOCALS~1\Temp\ccwdcaaa.o(.text+0x197) In function `main':
[Linker error] undefined reference to `__gmpz_init'
[Linker error] undefined reference to `__gmpz_init_set_ui'
[Linker error] undefined reference to `__gmpz_array_init'
[Linker error] undefined reference to `__gmpz_init'
and so on with similar ones...


any help would be apreciated
Linking gmp might help.
the includes, libraries, and binaries are all linked
Hello, hypercube1.

pay attention to Line 37:
cout << ciphertext[i] << endl;
so,you need to add an include "gmpxx.h", and link gmp with -lgmp -lgmpxx

or change this line like this :

gmp_printf("%Zd\n",ciphertext[i]);


cheers
much thanks about the output, however it is linked to those libs, or atleast dev says it is. is there a way to link with specific libs from a preprocessor standpoint? or is there another step to linking in dev other than adding the libs to the directories from compiler options?
Nevermind, i figured it out, i didn't realize that you have to put it into project format and use the project options to link specific libs. if anyone knows a way around that it would be appreciated, i'd rather use individual .cpp files than the pesky .devs
Most IDEs (the ones I've seen) determine which cpps to link together to a single executable by grouping them in a project.
i just haven't used many other libs or done anything with a whole lot of cpps
Should've said so in my first post, but first thing you should do is to ditch Dev-C++ (and make sure the bundled MinGW is fully deleted as well) and install Code::Blocks instead.
Topic archived. No new replies allowed.