problem returning a mpz_t value from a function c++

240 views
Skip to first unread message

David edwards jr

unread,
May 4, 2014, 9:22:38 PM5/4/14
to mpir-...@googlegroups.com
in a header file I try to define the following:

mpz_t somefunction();

I have include at the top <mpir.h>
I suspect that mpz_t doesn't have a copy constructor.

and also suspect that it is written in C.

david

Bill Hart

unread,
May 4, 2014, 9:27:58 PM5/4/14
to mpir-devel
There's a long section of the documentation dedicated to how to use the C++ wrapper.

In short, compile with ./configure --enable-cxx, #include "mpirxx.h" and use mpz_class.

Bill.


--
You received this message because you are subscribed to the Google Groups "mpir-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mpir-devel+...@googlegroups.com.
To post to this group, send email to mpir-...@googlegroups.com.
Visit this group at http://groups.google.com/group/mpir-devel.
For more options, visit https://groups.google.com/d/optout.

David edwards jr

unread,
May 5, 2014, 8:55:18 AM5/5/14
to mpir-...@googlegroups.com
thank you!  it now compiles and I must read documentation to see how to use.  I suspect that if you define x by mpz_class x; it will handle the construction and destruction of the object.  hope so anyway.

again my thanks,

david


--
You received this message because you are subscribed to a topic in the Google Groups "mpir-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mpir-devel/VIOP0BoWFVs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mpir-devel+...@googlegroups.com.

David edwards jr

unread,
May 5, 2014, 11:15:20 AM5/5/14
to mpir-...@googlegroups.com

a lot of errors when I compile with visual studio 2012.  the above statement that it compiles was wrong.  it simply meant that it found the symbol mpz_class x.

I guess I am having problems with the following in the header file of

gmpxx

/* the C++ compiler must implement the following features:

- member templates

- partial specialization of templates

- namespace support

for g++, this means version 2.91 or higher

for other compilers, I don't know */

and I guess there is no help for visual studio c++

I think that the unwrapped functions will be sufficient.

thank you


david












Bill Hart

unread,
May 5, 2014, 1:00:39 PM5/5/14
to mpir-devel
On 5 May 2014 17:15, David edwards jr <dej1...@gmail.com> wrote:

a lot of errors when I compile with visual studio 2012.  the above statement that it compiles was wrong.  it simply meant that it found the symbol mpz_class x.

I guess I am having problems with the following in the header file of

gmpxx

/* the C++ compiler must implement the following features:

- member templates

- partial specialization of templates

- namespace support

for g++, this means version 2.91 or higher

for other compilers, I don't know */


That's a very, very old version of g++. Visual Studio certainly supports the recent C++ standard, so if it is not compiling, you might have an error somewhere.

Have you tried something simple from the manual?

David edwards jr

unread,
May 5, 2014, 7:08:59 PM5/5/14
to mpir-...@googlegroups.com
the mpir project compiles. but when I add the header <mpirxx>  very many errors.  I have simply in project/add existing/item added the mpirxx.lib file

i think that i will try to build a simple wrapper for mpir since only a very limited high precision functions will i actually use.

i am quite happy with the state that i am in in being able to use the basic mpir functions.

kind regards

david

Bill Hart

unread,
May 5, 2014, 7:32:58 PM5/5/14
to mpir-devel
One possibility is you have the includes in the wrong order. The C++ wrapper certainly works with MSVC, since the C++ tests pass. They include the mpirxx.h header.

Bill.

David edwards jr

unread,
May 5, 2014, 8:35:17 PM5/5/14
to mpir-...@googlegroups.com
same result either way. the first two errors are:

1>C:\mpir may 5\mpir-2.7.0\dll\x64\Release\mpirxx.h(118): error C4146: unary minus operator applied to unsigned type, result still unsigned


1>C:\mpir may 5\mpir-2.7.0\dll\x64\Release\mpirxx.h(164): error C4146: unary minus operator applied to unsigned type, result still unsigned


could it be that I am using the wrong <mpirxx.h> file

I also note that there is no mpirxx.dll


david






Dann Corbit

unread,
May 5, 2014, 9:08:34 PM5/5/14
to mpir-...@googlegroups.com

Do you have warnings set as errors?

 

Open the mpir solution and then build the project: lib_mpir_cxx

 

You don’t see dll files because normally it builds as a library (at least that is what it does for me).

 

You should see stuff like this (with folders as appropriate for your development platform) if you do a search for mpirxx*:

 

Directory of F:\math\mpir-2.7.0

 

2014-03-28  10:54 AM           121,869 mpirxx.h

               1 File(s)        121,869 bytes

 

Directory of F:\math\mpir-2.7.0\build.vc10\lib_mpir_cxx\x64\Release

 

2014-05-05  06:02 PM             1,441 mpirxx.Build.CppClean.log

               1 File(s)          1,441 bytes

 

Directory of F:\math\mpir-2.7.0\build.vc10\x64\Release

 

2014-05-05  06:02 PM         1,975,030 mpirxx.lib

2014-05-05  06:02 PM           323,584 mpirxx.pdb

               2 File(s)      2,298,614 bytes

 

Directory of F:\math\mpir-2.7.0\dll\x64\Release

 

2014-03-28  10:54 AM           121,869 mpirxx.h

               1 File(s)        121,869 bytes

 

Directory of F:\math\mpir-2.7.0\lib\x64\Release

 

2014-03-28  10:54 AM           121,869 mpirxx.h

2014-05-05  06:02 PM         1,975,030 mpirxx.lib

2014-05-05  06:02 PM           323,584 mpirxx.pdb

               3 File(s)      2,420,483 bytes

 

Since the mpir c++ project builds fine, it should be a simple enough matter to see what is different between your project and the one used to build the mpir c++ project.

David edwards jr

unread,
May 5, 2014, 9:24:19 PM5/5/14
to mpir-...@googlegroups.com
I have those files, sizes close, I build vc11.

also to get mpir to work (no mpirxx included) I must put the mpir.dll in the same folder as the one in which the project dll is located.


what mpirxx.lib do you add to your project via add existing item.

or do  you add mpirxx.lib to  your project via the add existing item

david

Dann Corbit

unread,
May 6, 2014, 1:17:12 AM5/6/14
to mpir-...@googlegroups.com

From: mpir-...@googlegroups.com [mailto:mpir-...@googlegroups.com] On Behalf Of David edwards jr
Sent: Monday, May 5, 2014 6:24 PM


To: mpir-...@googlegroups.com
Subject: Re: [mpir-devel] problem returning a mpz_t value from a function c++

 

I have those files, sizes close, I build vc11.

 

also to get mpir to work (no mpirxx included) I must put the mpir.dll in the same folder as the one in which the project dll is located.

 

 

what mpirxx.lib do you add to your project via add existing item.

 

or do  you add mpirxx.lib to  your project via the add existing item

>> 

Normally, with a library or DLL file you add a reference instead of the library object.

Anyway, you add the 64 bit lib if you are making 64 bit binaries and the 32 bit lib if you are making 32 bit binaries.

You will choose, of course, debug for debug builds and release for release builds.

All that mess is why you add a reference instead, then all of that is handled for you.

http://msdn.microsoft.com/en-us/library/ez524kew.aspx

<< 

Brian Gladman

unread,
May 6, 2014, 2:44:53 AM5/6/14
to mpir-...@googlegroups.com
On 06/05/2014 01:35, David edwards jr wrote:
> same result either way. the first two errors are:
>
> 1>C:\mpir may 5\mpir-2.7.0\dll\x64\Release\mpirxx.h(118): error C4146:
> unary minus operator applied to unsigned type, result still unsigned
>
>
> 1>C:\mpir may 5\mpir-2.7.0\dll\x64\Release\mpirxx.h(164): error C4146:
> unary minus operator applied to unsigned type, result still unsigned
>
> could it be that I am using the wrong <mpirxx.h> file
>
> I also note that there is no mpirxx.dll

Your mpirxx.h is correct for a project that is being built for x64 and
release (assuming you haven't modified the MPIR build outputs since they
were built). But the above errors are normally warnings, not errors,
so it seems that you have set 'treat warnings as errors' in your build.
Is this correct?

In the DLL build the mpir.dll contains both the C and the C++ functions
so there is no mpirxx.dll.

Have you set the define MSC_USE_DLL in your project to tell the compiler
that you are using a DLL library, not a static one? Have you added the
correct export library to your project (mpir.lib in the DLL output folder).

If you can provide a set of files (not too big) to demonstrate the
problems you are having, I may be able to find out what is going wrong.

Brian

David edwards jr

unread,
May 6, 2014, 9:59:05 AM5/6/14
to mpir-...@googlegroups.com
I am using "mfc in a shared dll"

and I am adding the mpir.lib through the project/add existing item.

I am using the same mpir.lib for the project with cxx that I used for the mpir without cxx.



I think that the path I really wish to follow is to make a wrapper for the mpir functions.  I have started on this and the only thing it balks at is returning a mpir struct from a function.  this is not a real problem.

I am most likely going to have problems with mpir itself and would not wish you to spend time on an effort that I may not use.

however I would be very willing to try to straighten this matter out by preparing a bare bones project and send it to you if you wish.

thank you for your very generous help.

david










Brian Gladman

unread,
May 6, 2014, 12:02:16 PM5/6/14
to mpir-...@googlegroups.com
On 06/05/2014 14:59, David edwards jr wrote:

> however I would be very willing to try to straighten this matter out by
> preparing a bare bones project and send it to you if you wish.

Hi David,

This is only a suggestion if you need help with the problem. I don't
think that there is any wider need to do this.

best regards,

Brian

David edwards jr

unread,
May 6, 2014, 1:55:04 PM5/6/14
to mpir-...@googlegroups.com
understand, thanks brian



     Brian

gha.st

unread,
Oct 10, 2014, 10:57:09 AM10/10/14
to mpir-...@googlegroups.com
C4146 is turned into an error by the SDL (Secure Development Lifecycle) checks, as Microsoft seems to consider it a security risk to use the unary minus on an unsigned value.

As I compiled MPIR on MinGW64 and only use the DLL from VS2013, I cannot really comment on how this affects MPIR builds (beyond that a simply switching off the SDL checks will let it compile), but I can hint, that even if it is reported as an error, it can still be switched of like any other warning.

For example, the following is how I include <mpirxx.h> to suppress all warnings from it:

#if defined(_MSC_VER) && _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4146 4244 4800)
#endif
#include <mpirxx.h>
#if defined(_MSC_VER) && _MSC_VER
#pragma warning(pop)
#endif

Reply all
Reply to author
Forward
0 new messages