How to load utilities.hpp in a self-built project

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to load utilities.hpp in a self-built project

ziegele
I tried to use utilities.hpp stored in ...\test-suite\ from Visual-Studio 2015. I tried 3 different ways:

1. Load only boost-library and quantlib directories in Properties -> Configuration Properties -> VC++ Directories. In the main.cpp file, I write:

#include <iostream>
#include <ql\quantlib.hpp>
#include <test-suite\utilities.hpp>
using namespace QuantLib;

int main() {
        std::cout << "Test\n";

        system("pause");
        return 0;
}

2. Load only boost-library and quantlib directories in Properties -> Configuration Properties -> VC++ Directories. In the main.cpp file, I write:

#include <iostream>
#include <ql\quantlib.hpp>
#include "test-suite\utilities.hpp"
using namespace QuantLib;

int main() {
        std::cout << "Test\n";

        system("pause");
        return 0;
}

3. Load boost-library and quantlib directories in Properties -> Configuration Properties -> VC++ Directories. Then load ...\test-suite\ in "Include Directories". In the main.cpp file, I write:

#include <iostream>
#include <ql\quantlib.hpp>
#include "utilities.hpp"
using namespace QuantLib;

int main() {
        std::cout << "Test\n";

        system("pause");
        return 0;
}

However, none of them worked. I got 9 errors for all the 3 ways I tried:



Can anyone please advise how to correctly load utilities.hpp file into a self-built project? The main.cpp file is super simple... (Please also notice that if I comment-out the line #include "utilities.hpp", I will get a valid output).

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: How to load utilities.hpp in a self-built project

Luigi Ballabio
utilities.hpp is just the header and only contains the declarations of the functions.  The implementation is in utilities.cpp, and you need to compile and link it together with your main.

Luigi


On Fri, Feb 24, 2017 at 10:20 PM ziegele <[hidden email]> wrote:
I tried to use utilities.hpp stored in ...\test-suite\ from Visual-Studio
2015. I tried 3 different ways:

1. Load only boost-library and quantlib directories in Properties ->
Configuration Properties -> VC++ Directories. In the main.cpp file, I write:

#include <iostream>
#include <ql\quantlib.hpp>
#include <test-suite\utilities.hpp>
using namespace QuantLib;

int main() {
        std::cout << "Test\n";

        system("pause");
        return 0;
}

2. Load only boost-library and quantlib directories in Properties ->
Configuration Properties -> VC++ Directories. In the main.cpp file, I write:

#include <iostream>
#include <ql\quantlib.hpp>
#include "test-suite\utilities.hpp"
using namespace QuantLib;

int main() {
        std::cout << "Test\n";

        system("pause");
        return 0;
}

3. Load boost-library and quantlib directories in Properties ->
Configuration Properties -> VC++ Directories. Then load ...\test-suite\ in
"Include Directories". In the main.cpp file, I write:

#include <iostream>
#include <ql\quantlib.hpp>
#include "utilities.hpp"
using namespace QuantLib;

int main() {
        std::cout << "Test\n";

        system("pause");
        return 0;
}

However, none of them worked. I got 9 errors for all the 3 ways I tried:

<http://quantlib.10058.n7.nabble.com/file/n18108/angle-bracket.jpg>

Can anyone please advise how to correctly load utilities.hpp file into a
self-built project? The main.cpp file is super simple... (Please also notice
that if I comment-out the line #include "utilities.hpp", I will get a valid
output).

Thanks!



--
View this message in context: http://quantlib.10058.n7.nabble.com/How-to-load-utilities-hpp-in-a-self-built-project-tp18108.html
Sent from the quantlib-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: How to load utilities.hpp in a self-built project

ziegele
Thanks Guigi for your suggestion.

However, I don't know how to "compile and link" both the utilities.hpp and utilities.cpp files in the sample project I created in Visual Studio 2015. I tried 2 different ways:

1. I tried to include the path "...\test-suite\" in "Properties -> Configuration Properties -> VC++ Directories". But how can I let the system know that the utilities.cpp file is also in the same directory?

2. I tried to include the path "...\test-suite\" in "Properties -> Configuration Properties -> C/C++ -> General -> Additional Include Directories". Again, I got the same 9 errors as I mentioned last time;

3. I manually added the utilities.hpp and utilities.cpp files into the project I created.

For all the 3 ways I tried, I got the same 9 errors as I mentioned last time.

At this point, could you please advise how to correctly set up the utilities.hpp and utilities.cpp files so that I can compile?

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: How to load utilities.hpp in a self-built project

Luigi Ballabio
Hi,
    I meant option 3.   The errors you're getting mean that you also have to link the Boost unit-test framework to your project.  However, I don't advise that, since it might try to provide its own main() instead of yours.

The point is, both utilities.hpp and the test cases in test-suite are pretty much coupled to the Boost test-suite framework.  If you want to create an application, you're probably better off steering away from it.  If there is any code in the test cases or the utilities that you want to reuse, I suggest you copy it instead and replace Boost.Test functionality such as BOOST_TEST_MESSAGE with ordinary I/O calls.

Luigi


On Mon, Feb 27, 2017 at 4:43 PM ziegele <[hidden email]> wrote:
Thanks Guigi for your suggestion.

However, I don't know how to "compile and link" both the utilities.hpp and
utilities.cpp files in the sample project I created in Visual Studio 2015. I
tried 2 different ways:

1. I tried to include the path "...\test-suite\" in "Properties ->
Configuration Properties -> VC++ Directories". But how can I let the system
know that the utilities.cpp file is also in the same directory?

2. I tried to include the path "...\test-suite\" in "Properties ->
Configuration Properties -> C/C++ -> General -> Additional Include
Directories". Again, I got the same 9 errors as I mentioned last time;

3. I manually added the utilities.hpp and utilities.cpp files into the
project I created.

For all the 3 ways I tried, I got the same 9 errors as I mentioned last
time.

At this point, could you please advise how to correctly set up the
utilities.hpp and utilities.cpp files so that I can compile?

Thanks!



--
View this message in context: http://quantlib.10058.n7.nabble.com/How-to-load-utilities-hpp-in-a-self-built-project-tp18108p18121.html
Sent from the quantlib-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users