Thursday, June 6, 2013

Link Static Library to Console Project in VSC++

This is the second time I conquer a configuration issue in building my C++ pricing library for quantitative finance. The problem is:

1.   I create a solution named P2 in VS2012 and then add one console project named TestSuite and another static library P2PricingLibrary to the solution. After choosing TestSuite as the startup project and run the whole solution I get fatal error LNK 1120 and LNK2109 unresolved externals.  It seems I have to add additional dependency for my TestSuite. Then I go to Properties->Configuration Properties->Linker->Input->Additional Dependency and enter the full path of P2PricingLibrary.lib.

So, to link your library to other projects, you always need to link the path of the library in addition to the #include statement.

It should be working now.  But it isn't.


2.   I get an fatal errror LNK1104 ": cannot open file  'C:\Users\JinhuaHuang\Desktop\P2\P2PricingLibrary\Date.obj ". This time it turns out to be that  theP2PricingLibrary.lib has been generated yet.
When I build the P2PricingLibrary, the following error pops out:
fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source.  Because I select using Precompiled Header files for the P2PricingLibrary, I need to add #include "stdafx.h" to my cpp files, particularly, the first line of my cpp files. After fixing this. I rebuilt the library and then run the solution. It works!!

No comments:

Post a Comment