SERVING THE QUANTITATIVE FINANCE COMMUNITY

 
User avatar
MaxCohen
Topic Author
Posts: 511
Joined: June 13th, 2007, 2:44 pm

C++ header/source file best practices

January 2nd, 2012, 8:43 pm

I have created my own qa library with headers and source files arranged in a directory similar to QuantLibs setup. When I create a new project that will call from my qa library I change the project properties Include Directories accordingly so I can write in main.cpp #include <qalib/foo.hpp>Now to get the project to compile I need to add foo.cpp to the project. Is there a way to avoid this last step of adding foo.cpp i.e. some setting in project properties so foo.cpp is automatically picked up. Work arounds I can think of:1. Create header only files i.e. put the function definitions in the foo.cpp in foo.hpp - I am guessing this is bad practice 2. At end of foo.hpp add #include foo.cpp - I think this is probably only best practice when working with templatesI think there is a third alternative as QuantLib does not require .cpp to be added?
 
User avatar
Polter
Posts: 2526
Joined: April 29th, 2008, 4:55 pm

C++ header/source file best practices

January 2nd, 2012, 9:26 pm

If you have compiled your "qualib" to a .lib file and if your compiler supports it, then you can use the auto-linking feature, just like Boost and QuantLib.See the "Auto-Linking" box here:http://www.boost.org/doc/libs/release/m ... linkingand here:http://www.boost.org/doc/libs/release/b ... ce.htmlYou might also find the following helpful:http://old.nabble.com/Compilation-of-si ... .user/4698
 
User avatar
MaxCohen
Topic Author
Posts: 511
Joined: June 13th, 2007, 2:44 pm

C++ header/source file best practices

January 3rd, 2012, 7:04 am

Cool, thanks!
 
User avatar
MaxCohen
Topic Author
Posts: 511
Joined: June 13th, 2007, 2:44 pm

C++ header/source file best practices

January 3rd, 2012, 2:04 pm

I think my question wasn't actually answered on due to my wording of the question. I wanted to know whether it is possible to avoid adding the .cpp associated wth a particular .hpp to a project so long as the .cpp resides in the same directory as the .hpp.I think most probably the answer is no. Anyhow this autolinking stuff is quite useful to me.
 
User avatar
MaxCohen
Topic Author
Posts: 511
Joined: June 13th, 2007, 2:44 pm

C++ header/source file best practices

January 3rd, 2012, 2:14 pm

I have been adivised that in VS2010 I might be able to use 'Source Directories' in project properties help with this.http://blogs.msdn.com/b/vcblog/archive/ ... s2010.aspx
 
User avatar
MaxCohen
Topic Author
Posts: 511
Joined: June 13th, 2007, 2:44 pm

C++ header/source file best practices

January 3rd, 2012, 2:59 pm

Actually it would appear there is no way of doing what I wanthttp://stackoverflow.com/questions/4693951/source-directories-in-visual-studio-2010
 
User avatar
vrat
Posts: 8
Joined: December 6th, 2011, 6:58 am

C++ header/source file best practices

January 7th, 2012, 2:10 am

you need to provide only header and lib file path to compiler and linker.
ABOUT WILMOTT

PW by JB

Wilmott.com has been "Serving the Quantitative Finance Community" since 2001. Continued...


Twitter LinkedIn Instagram

JOBS BOARD

JOBS BOARD

Looking for a quant job, risk, algo trading,...? Browse jobs here...


GZIP: On