How to configuring NTL library in Visual Studio 2017 - static-libraries

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)
Add project -> New project -> Visual C++ -> Win32 Console Appl.
Right click on the created project -> Set as StartUp Project
Right click on the created project -> Add -> Reference -> NTL
Right click on the created project -> Configuration Properties ->
C/C++ -> General -> Additional Include Directories -> (NTL includes)
Take/copy some file from folder "tests" (downloaded from the NTL
repository)
Remove everything below #include "stdafx.h"
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!

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.

Related

Include c++ project in another c++ project from different solution in Visual Studio 2015

I have 2 c++ projects in different solutions. When I built the project B solution's it generated a .dll, .exp, .exe, and .lib files.
How I have to reference the project B in the project A?. I've tried rigth click -> add -> reference -> B.dll.
But it shows me a window error with the following message:
could not add a reference to B.dll for one of the following reasons:
Targets a higher version of the .NET Framework
Not a .NET assembly
Not a registered ActiveX control
I've never worked with visual studio,I'm a little bit lost
Thank you and sorry for my english

Visual Studio C++ Creating a solution with multiple projects. Use Dlls or Libs to talk each other?

Hi I am trying to merge two visual studio solution files into one and I have been having a difficult time calling one project to the other.
I have Solution X which contains Project A, which is a console application to control camera.
I have another solution Y which contains Project B produces a dll for another application to display plots.
After combining these two projects under one solution I made Project A to be a static library for Project B to call functions reside in Project A.
On Project B I added Project A's reference and also added a path to the include files of Project A.
I can build Project A independently, but I cannot build Project B. Visual studio complains as follows:
Severity Code Description Project File Line Suppression State
Error LNK1120 1 unresolved externals XOP3
C:\Users\xxx\Documents\project\pvcam_project\XOP3\VC\XOP3-64.xop 1
Severity Code Description Project File Line Suppression State
Warning LNK4098 defaultlib 'LIBCMT' conflicts with use of other libs;
use /NODEFAULTLIB:library XOP3
C:\Users\xxx\Documents\project\pvcam_project\XOP3\VC\LINK 1
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol pl_pvcam_get_ver referenced in
function "void __cdecl DoWave(void * *)" (?DoWave##YAXPEAPEAX#Z) XOP3
C:\Users\xxx\Documents\project\pvcam_project\XOP3\VC\XOP3.obj 1
I followed this as an example and was able to build https://msdn.microsoft.com/en-us/library/ms235627(v=vs.90).aspx
I would like to know:
Is it a good idea to have project A as a static library for project B to access ? Should the project A be a dll ?
From Solution Y I added a project A and updated the locations of include files and etc by following (How do I merge two different Visual Studio solutions?) Is this the easiest way to merge two solutions ?
Lastly it is the most important one I am not sure how to resolve the compilation error.
Thank you very much for taking a look at my problem.

Cannot include a static library in the project

I am developing a subproject in a solution in MS Visual Studio 2005. The subproject is a Windows CE 6.0 service (as DLL) and it is included in the Windows CE 6.0 OS Project. In the subproject I need to use some functions from "ceosutil.lib" (svsutil.hxx is the header), but I cannot link it to my subproject. When building, I get the following type of errors: "error LNK2019: unresolved external symbol".
What is interesting, when I switch the project type to a static library, it compiles without problems. If I start a new DLL project (standalone one, not as subproject), it also works (the "ceosutil.lib" is already listed in the Additional Dependencies of the project and all configurations).
Please help!
I have found the answer to my own question. The solution is to add the name of the library ("ceosutil.lib", after a space) to Additional Libraries field in the Link tab of the subproject properties:
In MS Visual Studio 2005:
Right Mouse Click on subproject name -> Properties -> Link tab -> Additional Libraries.
default value was: $(_PROJECTROOT)\cesysgen\sdk\lib\$(_CPUINDPATH)\coredll.lib
new value: $(_PROJECTROOT)\cesysgen\sdk\lib\$(_CPUINDPATH)\coredll.lib ceosutil.lib
Update:
It is even easier to open the subproject (right mouse btn -> open) and paste the path to the library in the TARGETLIBS section. The result will be exactly the same:
TARGETLIBS= \
$(_PROJECTROOT)\cesysgen\sdk\lib\$(_CPUINDPATH)\coredll.lib \

building multiple project in visual studio

I have projects A,B in visual studio under the solution AB.
B is a static library with a simple method named "add" which is already declared with __declspec(dllexport)
and A is an application depending on B.
the build order is configured B -> A
B.lib is getting created properly but i am getting "error LNK2019: unresolved external symbol _add referenced in function _main"
I also referenced the B.lib's directory in Additional dependencies in A's Project settings page
Please let me know where i am making the mistake....
sry got the solution to my problem...
C:\Documents and Settings\absasdf\My Documents\Visual Studio 2010\Projects\AB\Debug; added to Linker>General>Additional Library Directories
and
B.lib added to Linker>Input>Additional Dependencies
Now its working fine..

Linker error with debug build with different compiler versions

We have a DLL, built with MS Visual Studio 2010, in release mode. We provide this DLL to different customers, along with a .lib file. The functions in the DLL are exported with:
extern "C" __declspec(dllexport) int analyze(int id);
Our customers have two applications that makes use of this DLL. Both of these applications import the DLL functions using:
extern "C" __declspec(dllimport) int analyze(int id);
One of these applications is built with MS Visual Studio 2010. This application can be built successfully in both debug and release modes.
The other application must unfortunately use MS Visual Studio 2005 as its build environment. In this application, the release build can be built successfully, however, when we try to build in debug mode, we get linker errors:
LNK2019: unresolved external symbol __imp_analyze referenced in function "void __cdecl process(char const *,char const *)" (?process##ABCERFG0#Z)
Can someone help me understand what we are missing here? Are we exporting the functions in a manner that is not portable across compilers? What's the solution?
Regards,
The .obj file format is highly conserved between VS2005 and VS2010. This should not be a problem, especially since it is a simple non-mangled symbol reference. And especially not when it works in the Release configuration but not in Debug. A simple explanation is always better than a convoluted one: your customer simply forgot to add your .lib file to the linker's Additional Dependencies setting.
Beware that the setting change needs to be made for both configurations, use the "Configuration" combo in the upper left corner of the dialog.
You can help your customer fall into the pit of success by using #pragma comment(lib, "mumble.lib") in your .h file.

Resources