Pelles C forum

C language => Beginner questions => Topic started by: KKR_WE_RULE on January 19, 2011, 07:17:47 AM

Title: Problem with Miracl Library (Shamus Softwares)
Post by: KKR_WE_RULE on January 19, 2011, 07:17:47 AM
Well, to be frank, I am a newbie with C/C++.
I was trying to use the BigNum Library by Shamus named MIRACL with Pelles C.

But I cant get it to work.

I've included the miracl.h & mirdef.h, but

miracl *mip = mirsys(128, 16) --> gives "POLINK: error: Unresolved external symbol '_mirsys@8'." as error.

Can some 1 help me with this ?

Best Regards
KKR
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: AlexN on January 19, 2011, 07:47:26 AM
I've included the miracl.h & mirdef.h, but

miracl *mip = mirsys(128, 16) --> gives "POLINK: error: Unresolved external symbol '_mirsys@8'." as error.

You added the include files for the compiler, but you must also add the library for the linker. you can do this in the IDE or in the source with #pragma lib "<libraryname>".
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: KKR_WE_RULE on January 19, 2011, 08:41:51 AM
#include "miracl.h"
#include "mirdef.h"

#pragma lib <miracl.lib>

This is what I did.

The error continues to show.

I've attached the project.. It a demo so called keygenme, to get used to the working of miracl.



Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: TimoVJL on January 19, 2011, 09:20:27 AM
#pragma lib "miracl.lib"
or
#pragma comment(lib, "miracl.lib")
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: KKR_WE_RULE on January 19, 2011, 09:25:08 AM
I tried both of them.
But same problem remains.

Miracl library is very important to me.. but I cant get it to work :(

Plz hlp guys .
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: frankie on January 19, 2011, 09:53:48 AM
If you have compiled the library on yourself be sure to have compiled it with the same calling convention of your code.
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: Stefan Pendl on January 19, 2011, 10:06:56 AM
Code: [Select]
#pragma lib <miracl.lib>This assumes your library is located in the library search path defined for the project.

Code: [Select]
#pragma lib "miracl.lib"
// or
#pragma comment(lib, "miracl.lib")
These assume your library is in the folder, where your source code is located.

Did you change the include and library search path of the project to include the path to both files?
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: KKR_WE_RULE on January 19, 2011, 10:15:54 AM
my files (miracl.h) & (mirdef.h) & (miracl.lib) are located in the same dir as the src .

I noticed something.

When I compile the code, it is perfect, but when I try to build it, its then that the IDE starts complaining :(

Any specific way to compile the Miracl library for pelles C ?

I have never used any third party lib in C/C++ & new to C.

Thanx for all your efforts guys :)

Best Regards
KKR
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: Stefan Pendl on January 19, 2011, 10:44:05 AM
The compiler only needs the header files, so this part is working correctly.

The linker needs the library file, so here is the problem.

The library and the resulting program must be of the same bit type:

You can not mix that.
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: KKR_WE_RULE on January 19, 2011, 10:51:13 AM
Right.. but my miracl library is a 32 bit library.

www.shamus.ie

It can be found in the above website.

Its a library built with C :)

So any suggestions on how to fix this mess :D

Thx for the quick reply man :)

Best Regards
KKR
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: TimoVJL on January 19, 2011, 10:59:56 AM
miracl.lib uses msvc libc.lib and is cdecl-lib.
Test this modified project.
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: KKR_WE_RULE on January 19, 2011, 11:11:01 AM
Woah!!!! You are the man!!!
Perfect :)

Would you please explain what was wrong ?
That would help me learn & get a proper conception of it :)

Best Regards
KKR
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: TimoVJL on January 19, 2011, 12:19:11 PM
That miracl.lib is static library for msvc and uses cdecl calling conventions and default library is LIBC.lib (msvc).
Header files doesn't define calling convention so cdecl is expected.
That's why example uses cdecl calling convention and msvcrt.lib.
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: KKR_WE_RULE on January 19, 2011, 12:33:12 PM
I see.
Thanx very much for support guys :)

I am extremely pleased :)

Best Regards
KKR
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: KKR_WE_RULE on January 20, 2011, 08:45:02 AM
Hey guys.. Again :

POLINK: error: Unresolved external symbol '__allmul'.
POLINK: error: Unresolved external symbol '__aulldiv'.
POLINK: fatal error: 2 unresolved external(s).

The line thats causing it is :
ecurve_init(a, b, p, MR_PROJECTIVE);

What do I need to do to solve it ?

Regards
KKR

*edit*

I've attached the project, in case you need to see the source :)
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: Stefan Pendl on January 20, 2011, 10:27:17 AM
Did you follow the advice of the users manual, which is a separate download?

Quote
To assist with the configuration process, a file config.c is provided. When compiled
and run on the target processor it automatically generates a mirdef.h file and gives
general advice on configuration. It also generates a miracl.lst file with a list of MIRACL
modules to be included in the associated library build. Experimentation with this
program is strongly encouraged. When compiling this program DO NOT use any
compiler optimization.
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: KKR_WE_RULE on January 20, 2011, 10:40:43 AM
I tried to compile it, but it never compiles :(
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: Stefan Pendl on January 20, 2011, 12:05:12 PM
Create an empty "Win32 Console Application (EXE)" project.
Copy config.c into the project folder.
Select "Project => Add files to project" and select config.c
Select "Project => Project options"
Select the Compiler tab
Set Optimizations to None
Hit OK
Build the project and ignore the warning about unused variables
Run the created EXE file and follow the instructions

Now you have build a custom mirdef.tst file, which would be your mirdef.h file.
The miracl.lst file would be used to compile your custom miracl.lib.
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: TimoVJL on January 20, 2011, 12:22:55 PM
Those functions exist in ntdll.dll

ntdll-1.def
Code: [Select]
LIBRARY NTDLL.DLL
EXPORTS
_alldiv
_allmul
_allrem
_allshl
_atoi64
_aulldiv
_aulldvrm

polib.exe /DEF:ntdll-1.def /OUT:ntdll-1.lib /MACHINE :X86

try that library with it.

Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: KKR_WE_RULE on January 20, 2011, 12:28:59 PM
Did exactly as directed in the above post.
I replaced by old mirdef.h file with the newly created one.
I also placed the copied the miracl.lst to the same folder .

But I still get same errors.

Now ?

*edit*

@timovjl : How do I import a dll functions in C ?

I can do it in Delphi, but dunno how to do it in C :(

br
KKR
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: TimoVJL on January 20, 2011, 01:03:18 PM
In this case make that library first to project folder.
Then add that import library to project.

http://forum.pellesc.de/index.php?topic=3272.msg12340#msg12340 (http://forum.pellesc.de/index.php?topic=3272.msg12340#msg12340)

From menu Project -> Project options ... -> Linker tab
add to Library and object files:

Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: KKR_WE_RULE on January 20, 2011, 01:11:56 PM
But this means, my exe wont run without that .dll file .
Thats annoying.
Any work around to it ?

br
KKR
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: TimoVJL on January 20, 2011, 01:25:04 PM
Don't copy that ntdll.dll.
That import library ntdll-1.lib is needed only when linking that program.
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: KKR_WE_RULE on January 20, 2011, 03:17:09 PM
I've added that polib thing, but I am not quite sure, what to do next :(
 To be frank, I am bit confused :(
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: TimoVJL on January 20, 2011, 05:05:26 PM
- copy ntdll-1.lib to project folder
- add ntdll-1.lib to project linker options
  From menu Project -> Project options... -> Linker tab add to Library and object files:
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: KKR_WE_RULE on January 21, 2011, 07:35:31 AM
Alright.. All fixed :)
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: MHX on February 27, 2011, 04:54:53 AM
Hello!
In this library there are two types ECn and Big. As can be established between them to convert?
I have tried:
Code: [Select]
ECn x;
Big y;
y = (Big) x;
x = (ECn) y;
Is NOT running :(

In the archive  big.cpp, big.h, ecn.cpp, ecn.h and  manual.doc.
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: AlexN on February 27, 2011, 01:20:44 PM
In the archive  big.cpp, big.h, ecn.cpp, ecn.h and  manual.doc.

The attached file are C++ source code - Pelles C is "only" a C compiler.
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: MHX on February 27, 2011, 02:37:53 PM
In the archive  big.cpp, big.h, ecn.cpp, ecn.h and  manual.doc.

The attached file are C++ source code - Pelles C is "only" a C compiler.
Sorry, I did not quite understand in English. What do you mean "Pelles C "? Complete library is "MIRACL" from the site http://www.shamus.ie/index.php?page=Downloads (http://www.shamus.ie/index.php?page=Downloads)
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: Stefan Pendl on February 27, 2011, 03:44:53 PM
Files ending in .CPP are C++ source files, which are not compatible with ANSI C.

In rare cases, they are ANSI C file and can be used by Pelles C.

There is a big difference between C and C++.
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: kkwoei88 on February 27, 2011, 04:45:48 PM
Hi there. I'm new in C++ and I just found out the MIRACL library to perform cryptography.
I tried compile the sample code in Visual C++ , in which the code is included inside the library folder (http://www.shamus.ie/index.php?page=Downloads). It end up with some errors. I had add the miracl.lib and the header file big.h, miracl.h, mirdef.h, zzn.h inside the project too. Am I missing out some library which should be included? Or is there anyway to solve this?

Quote
1>sample.cpp
1>Linking...
1>sample.obj : error LNK2019: unresolved external symbol "class Flash __cdecl pow(class Flash const &,class Flash const &)" (?pow@@YA?AVFlash@@ABV1@0@Z) referenced in function _main
1>sample.obj : error LNK2019: unresolved external symbol "class Flash __cdecl exp(class Flash const &)" (?exp@@YA?AVFlash@@ABV1@@Z) referenced in function _main
1>sample.obj : error LNK2019: unresolved external symbol "class Flash __cdecl operator*(class Flash const &,class Flash const &)" (??D@YA?AVFlash@@ABV0@0@Z) referenced in function _main
1>sample.obj : error LNK2019: unresolved external symbol "class Flash __cdecl sqrt(class Flash const &)" (?sqrt@@YA?AVFlash@@ABV1@@Z) referenced in function _main
1>sample.obj : error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class Flash const &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABVFlash@@@Z) referenced in function _main
1>sample.obj : error LNK2019: unresolved external symbol "class Flash __cdecl pi(void)" (?pi@@YA?AVFlash@@XZ) referenced in function _main
1>C:\Users\User\Documents\Visual Studio 2008\Projects\brent\Debug\brent.exe : fatal error LNK1120: 6 unresolved externals
1>Build log was saved at "file://c:\Users\User\Documents\Visual Studio 2008\Projects\brent\brent\Debug\BuildLog.htm"
1>brent - 7 error(s), 0 warning(s)
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: Stefan Pendl on February 27, 2011, 06:48:26 PM
Pelles C does not support C++ at all, it is only supporting plain ANSI C.

You would better ask at a C++ or Visual Studio forum.
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: kkwoei88 on February 27, 2011, 06:51:53 PM
opps my mistake. Thanks anyway!   :)
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: mutluceengineer on December 18, 2012, 09:06:44 PM
Hi,

I m writing some crypto functions using Miracl library.
My problem is about arrays. I want to let user input the
size of the array (type:big). How can I do that?
Title: Re: Problem with Miracl Library (Shamus Softwares)
Post by: CommonTater on December 18, 2012, 10:29:05 PM
I m writing some crypto functions using Miracl library.
My problem is about arrays. I want to let user input the
size of the array (type:big). How can I do that?

Lookup scanf() and malloc() in your help file....