-->

How to configuring NTL library in Visual Studio 20

2019-07-12 18:43发布

问题:

I have just installed Visual Studio 2017 and I want to use the NTL library. I have followed the steps described here (for VS2013). Compiling NTL library in Visual Studio 2013

As expected, it compiles (with several, I hope, negligible warnings).

Then, under the same solution, I am doing these consecutive steps: (under the same solution)

  1. Add project -> New project -> Visual C++ -> Win32 Console Appl.
  2. Right click on the created project -> Set as StartUp Project
  3. Right click on the created project -> Add -> Reference -> NTL
  4. Right click on the created project -> Configuration Properties -> C/C++ -> General -> Additional Include Directories -> (NTL includes)
  5. Take/copy some file from folder "tests" (downloaded from the NTL repository)
  6. Remove everything below #include "stdafx.h"
  7. Paste and build

Those steps should work on VS2013 & VS2015, unfortunately when I build I got 4 linker related errors (LNK2019).

They all are similar to the example below:

Error LNK2019 unresolved external symbol "void __cdecl NTL::MatPrime_crt_helper_deleter(class NTL::MatPrime_crt_helper *)" (?MatPrime_crt_helper_deleter@NTL@@YAXPAVMatPrime_crt_helper@1@@Z) referenced in function "public: static void __cdecl NTL::ZZ_pInfoT::MatPrime_crt_helper_deleter_policy::deleter(class NTL::MatPrime_crt_helper *)" (?deleter@MatPrime_crt_helper_deleter_policy@ZZ_pInfoT@NTL@@SAXPAVMatPrime_crt_helper@3@@Z) NTLtest <thePathToTheLib> (ZZ_p.obj) 1

Can you advice how to proceed?

I have tried to built this example -> ZZ_pEXTest.cpp

Thank you in advance!

回答1:

First, I am assuming you get the same 4 errors I do. I get the one you showed in your question, plus three more. In all cases, it involves a forward declaration of a method or function that does actually exist in the code.

However, the types in the declarations are classes and the types in the implementation are structs. The function signature is therefore not the same and the linker can't find the implementation.

So, I simply updated the the forward declarations of the parameter types to be what they should be: structs.

In lip.h, change _ntl_general_rem_one_struct to be a struct. In ZZ_p.h, change MatPrime_crt_helper to be a struct.

I believe this is all I did.

You shouldn't really have to make changes to the code. There may be a compiler switch, or it only fails in VS. I don't know. All I know is it is written by someone a lot smarter than me, and life is too short; I've made my changes and I'm moving on.