-2

I want to run a program I wrote that uses GMP library at my school, however I need your help getting this to work. The program itself is okay, but I can't figure out how to properly include GMP. I am using Netbeans IDE and cygwin, the program is in c++. Can anybody give me an insight on how to do this? There are a lot of things I'm uncertain about, e.g:

  • Do I need to compile specifically for that computer?
  • Does the OS matter?

I'm sorry if this is question is answered somewhere already. I have googled for quite some time but I can't seem to find anything, not even an example from GMP itself.

Thanks in advance!

Edit:

I really can't find out how to link this. The program crashes instantly and dumps a stacktrace. It says: Exception: STATUS_ILLEGAL_INSTRUCTION. In the folder I have cyggcc_s-seh-1.dll, cyggmp-10.dll, cygstdc++=6.dll, cygwin1.dll, the exe, gmpxx.h, libgmp.a, libgmp.la, libgmp.lai, libgmp.libcmd, libgmpxx.a, libgmpxx.la, libgmpxx.lai, main.cpp, main.o, main.o.d, .dep.inc and some files and folders necessary for my program.

I have included gmp and gmpxx, when I build it gives:

"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/e/Documents/NetBeansProjects/GeneticPrimesFast'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_4.x-Windows/geneticprimesfast.exe
make[2]: Entering directory '/cygdrive/e/Documents/NetBeansProjects/GeneticPrimesFast'
mkdir -p build/Debug/Cygwin_4.x-Windows
rm -f "build/Debug/Cygwin_4.x-Windows/main.o.d"
g++    -c -g -Werror -I../../GMP/gmp-6.0.0 -std=c++11 -MMD -MP -MF "build/Debug/Cygwin_4.x-Windows/main.o.d" -o build/Debug/Cygwin_4.x-Windows/main.o main.cpp
mkdir -p dist/Debug/Cygwin_4.x-Windows
g++     -o dist/Debug/Cygwin_4.x-Windows/geneticprimesfast build/Debug/Cygwin_4.x-Windows/main.o -lgmpxx -lgmp
make[2]: Leaving directory '/cygdrive/e/Documents/NetBeansProjects/GeneticPrimesFast'
make[1]: Leaving directory '/cygdrive/e/Documents/NetBeansProjects/GeneticPrimesFast'

BUILD SUCCESSFUL (total time: 2s)

I'm quite stressed right now, since I need this to work tomorrow. Any help would be very much appreciated!

Edit 2:

I've come to the conclusion that n.m. is probably right: it has to do with the code. What are typical things that cause illegal instructions?

Edit 3:

Thanks for your help! I found out it has to do with the get_str command in gmp (and possibly also get_d). Does anyone know another way of getting a string without this function, or am I using it wrong?

Edit 4:

mpf_set_d also doesn't work. It is essential for the program. Does anyone know how to fix this or where I'm going wrong? Maybe the development tool, and how would I check that?

Jelle
  • 36
  • 6
  • I'm not sure that you can use netbeans and cygwin together, but with cygwin you just need to install libgmp-devel using cygwin's own setup program. – n. m. could be an AI Feb 09 '15 at 16:51
  • Thanks for your fast reply! I am installing it now. Do I just link it normally after it's done installing and compile it? – Jelle Feb 09 '15 at 17:03
  • I have found information about the tool, but I don't know how to link it. Could you maybe give a short explanation @n.m.? – Jelle Feb 09 '15 at 18:38
  • I have no idea about Netbeans, much less about Netbeans in conjunction with cygwin, but if you use cygwin command-line tools, you add `-lgmp` to the linker invocation. – n. m. could be an AI Feb 09 '15 at 18:41
  • I have also linked gmpxx but it's not working. Do you know where I'm going wrong? @n.m. – Jelle Feb 09 '15 at 20:39
  • You have a bug in your program and now you need to debug it. Sorry. – n. m. could be an AI Feb 09 '15 at 22:00
  • @n.m. But that's what is so weird about this, it works on my own computer (where I have GMP installed) but on another computer it throws an error. I really appreciate the time you are putting into this! – Jelle Feb 09 '15 at 22:11
  • Nothing weird whatsoever. Correct programs work, incorrect programs do what they please, such as work on one computer and crash on another. – n. m. could be an AI Feb 09 '15 at 22:16
  • Do you think it might have to do with they way GMP compiles specifically for one computer, and if so, is there a way for me to make it independent? @n.m. – Jelle Feb 09 '15 at 22:20
  • The most probable reason is undefined behaviour in your program. Debug it. – n. m. could be an AI Feb 10 '15 at 04:13

1 Answers1

0

The most likely culprit is a buffer/array overrun somewhere that overwrites a function or return pointer somewhere. A later return or call through the corrupted pointer jumps off to some memory region that is executable but doesn't contain valid instructions, either because it is data or because you jumped into the middle of a multibyte instruction.

If you were using linux I would suggest valgrind for tracking down the memory corruption. There must exist similar tools on Windows.

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226
  • It turns out to be mpf_get_str and mpf_get_d that cause the error. When left out it works, but I need them in my program. The c++ wrapper doesn't work either (since I'm pretty sure it points back to the same functions). Do you know how to fix this? Does this have to do with libgmp-devel? – Jelle Feb 10 '15 at 19:57