0

Edit: I think I will implement my own Sobol and/or maybe Halton generator with the help of the book I was told about below. I may not use the implementation I was trying to use. Still it would be good to know the answer to how to tell the linker to look at a(n external) .dll file.

  1. C++ Beginner.

  2. I need Sobol numbers as a minor part in a larger project.

  3. Using an implementation that depends on other libraries that I may have to install/compile makes the number of things I would need to learn and I don't know even larger.

I found this (http://www.broda.co.uk/dl/download.php?f=b0d0839560fd157a3a6fb15cbf2bfc99) implementation of Sobol numbers. The fact that it has a dll (which I am guessing is a compiled library) makes me think that it is probably independent.

I took the contents of their main() in the main.cpp and put it in my main() of a console application. Took also the directives (!?)

#include "sobolseq51.h"
#define n_dimension 1

and put them in my console application outside the main().

Put the other files

SobolSeq51.dll
sobolseq51.H
SobolSeq51.lib

in my console application directory so that they are visible by the rest of the project.

Compiled and got

1>------ Build started: Project: ConsoleApplicationProject4, Configuration: Debug Win32 ------

1> ConsoleApplicationProject4.cpp

1>ConsoleApplicationProject4.obj : error LNK2019: unresolved external symbol "int __cdecl SobolSeq51(long,int,double *)" (?SobolSeq51@@YAHJHPAN@Z) referenced in function _wmain

1>C:\Users\Franklin\Documents\WORK\FinantialMathematics\FinancialC++\Project4\ConsoleApplicationProject4\Debug\ConsoleApplicationProject4.exe : fatal error LNK1120: 1 unresolved externals ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

The code inside their main() is

long i_SobolSeq51 = 1;

int n_total = 64; // Total number of points

double SobolSeqVector[n_dimension];

cout << "Sobol' sequense for n=" << n_dimension << endl;

for (int i = 1; i <= n_total; i++)

{

  SobolSeq51(i_SobolSeq51++, n_dimension, SobolSeqVector);

  cout << " SobolSeq51[" << i << "]=" << SobolSeqVector[0] << endl;

}

return 0;

  • 1
    Are you posting the same question again? – olevegard May 23 '14 at 21:59
  • @olevegard Same general problem, not the same question. This time it is "specific" as they said. – Anna Taurogenireva May 23 '14 at 22:00
  • 2
    But instead of posting a new question every time, you should be updating the already existing question. – olevegard May 23 '14 at 22:01
  • @olevegard It is a problem "by design" of these websites that people with relative low reputation can close questions + closed questions rarely get follow up. This creates a trap for beginners' questions. – Anna Taurogenireva May 23 '14 at 22:04
  • 1
    You need to tell the linker that you need the library file. See http://stackoverflow.com/questions/212492/how-do-you-add-external-libraries-for-compilation-in-vc – T.C. May 23 '14 at 22:17
  • @ABC algorithm for Sobol numbers is described in Numerical Recipes in C – 4pie0 May 23 '14 at 22:18

1 Answers1

2

Did you add the .lib import library file in your VS project? Because it seems you did not, hence the linker errors. You need to tell the linker, to include that DLL too.

Andro
  • 2,232
  • 1
  • 27
  • 40
  • No, I haven't done anything specific to that. Is that done by also adding #include "...." at the beginning with the names of the corresponding files? – Anna Taurogenireva May 23 '14 at 22:22
  • well #include is for headers - but you need the library too -> implementation code resides in that .dll so you linker must know how to link it to your program. – Andro May 23 '14 at 22:24
  • I don't know how is that done. I just put #include for all those files, but as you said, that is not the solution. – Anna Taurogenireva May 23 '14 at 22:25
  • `#include "..."` allows you to use the functions and types that are declared in the `#include`ed file. However, when the compiler gets around to actually creating the `.exe` file it has to link in the actual function implementation. You don't have to worry too much about the details, but you need to tell the compiler about the `.lib` file and make sure the `.dll` file is available when you run the final program. – Max Lybbert May 23 '14 at 22:25
  • @ABC This looks like Visual Studio, so putting `#pragma comment(lib, "SobolSeq51.lib")` in your code should do it. – T.C. May 23 '14 at 22:26
  • Something in the line of Properties - > Linker -> Input and then add you lib to the list of libraries that get linker's attention. – Andro May 23 '14 at 22:27
  • I did put all those files in the directory where the project is. The linker sees that directory because I have put other .h I have created there, and they get seen during compilation and execution. – Anna Taurogenireva May 23 '14 at 22:27
  • forget about the .h, you're problem is not with the '.h' it's with the '.lib'. Use either my or @T.C. way. – Andro May 23 '14 at 22:28
  • @T.C. It is Visual Studio indeed. I just put that in the code. Still not working. Is there a similar command to tell the linker about the dll? – Anna Taurogenireva May 23 '14 at 22:28
  • @ABC Are you still getting the same linker error or a different one? – T.C. May 23 '14 at 22:36
  • It is the same. Sorry. I got distracted with reading the book they linked above. – Anna Taurogenireva May 23 '14 at 22:38
  • Well I deleted the link because I don't know if it is according to SO policy. But anyway, you must be doing something wrong because the methods shown here are the correct ones. – Andro May 23 '14 at 22:41
  • @CandyMan I put the command above for the .lib, but it is not clear to me what should I do about the .dll file? How to tell the linker about it? – Anna Taurogenireva May 23 '14 at 22:54
  • @ABC It works for me. Can you post your whole code file? (The `.lib` file references the `.dll` file, so you don't need to tell the linker about it separately.) – T.C. May 23 '14 at 23:22
  • @T.C. I managed to compile now (in a separate new console application project). I must be doing something wrong when I included in the one I am working on. Thanks. – Anna Taurogenireva May 24 '14 at 01:17