locked
Project Dependencies RRS feed

  • Question

  • Hello,

    I'm working on a VS2010 / C++ project containing one executable and one library. The project wasn't imported from a previous version of VS.

    I've right-clicked on the executable project and selected 'Project Dependencies', and then put a check next to the library project. I also checked that 'Link Library Dependencies' is Yes under Configuration Properties->Linker->General.

    When I build the solution the library file is built but not automatically linked with the executable, so I get a load of errors regarding unresolved externals.

    Am I doing something wrong? I'm fairly sure this used to work with VS2005/8.

    Thanks! :)


    James
    Thursday, September 29, 2011 12:59 PM

Answers

  • You may add reference to your static lib through Project->References... (not 'Project Dependencies') "Property Pages".
    Walkthrough: Creating and Using a Static Library (C++)
    http://msdn.microsoft.com/en-us/library/ms235627.aspx

    With kind regards

    • Marked as answer by Jesse Jiang Monday, October 10, 2011 6:09 AM
    Thursday, September 29, 2011 4:54 PM
  • Hi James,
     
    The error occurs because the project dependencies have not been added successfully .
     
    I suggest you add project dependency as follows:
     
    1->Right-click the executable project , select "References.." , then you will see the property pages is opened . Or you can display property pages from Project->Properties .
     
    2-> Expand  Common Properties and click "Add New Reference.." . On the Projects tab, select the static library project and click OK .
     
    3->from Configuration Properties->C/C++->General->Additional Include Directories add the directory of lib.h and click OK to save all the changes .
     
    At last rebuild the project and run it .
     
    Hope this helps . If you have any concerns , please let me know.
    Best regards

    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Jesse Jiang Wednesday, October 5, 2011 8:24 AM
    • Marked as answer by Jesse Jiang Monday, October 10, 2011 6:09 AM
    Friday, September 30, 2011 6:25 AM

All replies

  • Here are the steps to reproduce, if it helps :)

     

    1. Create a new VS2010 Win32 Console Application project - empty project.

    2. Right-click solution and add a Win32 Project (Library) - empty project.

    3. Add these two files to the library:

    lib.h

    void test();
    


    lib.cpp

    #include "lib.h"
    #include <iostream>
    
    void test()
    {
       std::cout << "Hello\n\n";
    }
    


    4. Add this file to the executable:

    main.cpp

    #include "../Lib/Lib.h"
    
    int main(int argc, char *argv[])
    {
       test();
    }
    


    5. Right click on the executable project, and choose 'Project Dependencies'. Put a check next to the library project, to indicate that it is required by the executable.

    6. Right click on the executable project, and choose 'Properties'. Go to Configuration Properties->Linker->General and verify that Link Library Dependencies is Yes.

    If you build the project, you will see:

    2>main.obj : error LNK2019: unresolved external symbol "void __cdecl test(void)" (?test@@YAXXZ) referenced in function _main

    I'm pretty sure I'm using this correctly.


    James
    Thursday, September 29, 2011 1:15 PM
  • Hello,

    just use the hello_world sample for creating DLL.

    your function has to be exported using declspec(export) and should be imported using declspec(import).

    regards,

    Christophe PICHAUD

    MCSD, MCSD.NET, MCTS NET 2.0

    www.christophep.com

     


    Christophe Pichaud
    Thursday, September 29, 2011 3:16 PM
  • Hiya,

     

    Thanks - I'm creating a static library, not a DLL - so the storage class attribute shouldn't be necessary.


    James
    Thursday, September 29, 2011 3:41 PM
  • You may add reference to your static lib through Project->References... (not 'Project Dependencies') "Property Pages".
    Walkthrough: Creating and Using a Static Library (C++)
    http://msdn.microsoft.com/en-us/library/ms235627.aspx

    With kind regards

    • Marked as answer by Jesse Jiang Monday, October 10, 2011 6:09 AM
    Thursday, September 29, 2011 4:54 PM
  • Hi James,
     
    The error occurs because the project dependencies have not been added successfully .
     
    I suggest you add project dependency as follows:
     
    1->Right-click the executable project , select "References.." , then you will see the property pages is opened . Or you can display property pages from Project->Properties .
     
    2-> Expand  Common Properties and click "Add New Reference.." . On the Projects tab, select the static library project and click OK .
     
    3->from Configuration Properties->C/C++->General->Additional Include Directories add the directory of lib.h and click OK to save all the changes .
     
    At last rebuild the project and run it .
     
    Hope this helps . If you have any concerns , please let me know.
    Best regards

    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Jesse Jiang Wednesday, October 5, 2011 8:24 AM
    • Marked as answer by Jesse Jiang Monday, October 10, 2011 6:09 AM
    Friday, September 30, 2011 6:25 AM