Noob noobin'. I would appreciate some very careful handholding in setting up an example in Visual Studio 2010 Professional where I am trying to build a project which links:
a previously built static library, for which the VS project folder is "C:\libjohnpaul\"
a previously built dynamic library, for which the VS project folder is "C:\libgeorgeringo\"
These are listed as Recipes 1.11, 1.12 and 1.13 in the C++ Cookbook. The project fails to compile for me with unresolved dependencies (see details below), and I can't figure out why.
Project 1: Static Library
The following are the header and source files that were compiled in this project. I was able to compile this project fine in VS2010, to the named standard library "libjohnpaul.lib" which lives in the folder ("C:/libjohnpaul/Release/").
void john( ); // Prints "John, "
#endif // JOHN_HPP_INCLUDED
void john( )
std::cout << "John, ";
void paul( ); // Prints " Paul, "
#endif // PAUL_HPP_INCLUDED
void paul( )
std::cout << "Paul, ";
void johnpaul( ); // Prints "John, Paul, "
#endif // JOHNPAUL_HPP_INCLUDED
void johnpaul( )
Project 2: Dynamic Library
Here are the header and source files for the second project, which also compiled fine with VS2010, and the "libgeorgeringo.dll" file lives in the directory "C:\libgeorgeringo\Debug".
void george( ); // Prints "George
#endif // GEORGE_HPP_INCLUDED
void george( )
std::cout << "George
void ringo( ); // Prints "and Ringo\n"
#endif // RINGO_HPP_INCLUDED
void ringo( )
std::cout << "and Ringo\n";
// define GEORGERINGO_DLL when building libgerogreringo.dll
# if defined(_WIN32) && !defined(__GNUC__)
# ifdef GEORGERINGO_DLL
# define GEORGERINGO_DECL _ _declspec(dllexport)
# define GEORGERINGO_DECL _ _declspec(dllimport)
# endif // WIN32
# define GEORGERINGO_DECL
// Prints "George
, and Ringo\n"
# pragma export on
GEORGERINGO_DECL void georgeringo( );
# pragma export off
#endif // GEORGERINGO_HPP_INCLUDED
// libgeorgeringo/ georgeringo.cpp
void georgeringo( )
Project 3: Executable that depends on the previous libraries
Lastly, I try to link the aforecompiled static and dynamic libraries into one project called "helloBeatlesII" which has the project directory "C:\helloBeatlesII" (note that this directory does not nest the other project directories).
The linking process that I did is described below:
To the "helloBeatlesII" solution, I added the solutions "libjohnpaul" and "libgeorgeringo";
then I changed the properties of the "helloBeatlesII" project to additionally point to the include directories of the other two projects on which it depends ("C:\libgeorgeringo\libgeorgeringo" & "C:\libjohnpaul\libjohnpaul");
added "libgeorgeringo" and "libjohnpaul" to the project dependencies of the "helloBeatlesII" project and made sure that the "helloBeatlesII" project was built last.
Trying to compile this project gives me the following unsuccessful build:
1------ Build started: Project: helloBeatlesII, Configuration: Debug
1Build started 10/13/2012 5:48:32 PM.
1 All outputs are
1helloBeatles.obj : error LNK2019: unresolved external
symbol "void __cdecl georgeringo(void)" ([email protected]
referenced in function _main 1helloBeatles.obj : error LNK2019:
unresolved external symbol "void __cdecl johnpaul(void)"
@YAXXZ) referenced in function _main
: fatal error LNK1120: 2 unresolved externals
1Build FAILED. 1
1Time Elapsed 00:00:01.34
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========
At this point I decided to call in the cavalry. I am new to VS2010, so in all likelihood I am missing something straightforward.