CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2008
    Posts
    3

    Problems linking my unit test project

    Hi everybody. I have been having problems getting my solution to build. I hope somebody can help me because this problem is really tearing me up.

    Some background info:
    I have a solution with 2 projects - "Client", and "Server". When I started coding, I put all of my unit tests into the Server project because I was too lazy to do it in a more elegant way (right now I have no tests for Client because I haven't really done any development on it). As the project grew in size, this became cumbersome, and it didn't work because the tests and the Server itself both need to build an EXE. So now I'm trying to move all the tests into their own project. By the way, I'm using CppUnit as my testing framework.

    As soon as I moved the files to the new project, I set up the linker references to the proper CppUnit libraries. My client and server projects both built fine. But my Tests project failed to link. It gave me the "LINK2019 unresolved external symbol" error. It gave me this error for each function in the Server project that my unit tests called.

    I attribute this to the fact that the server's CPP files are in a different directory than those of the test. The linker was unable to find the implementation for the included headers.

    Does anyone have a suggestion for a good way to solve this problem?

    Thanks.

  2. #2
    Join Date
    Mar 2001
    Posts
    2,529

    Re: Problems linking my unit test project

    Well if you created a DLL, you have to add the .lib to your linker still. So if you dll name is mydll.dll, your linker stub is mydll.lib, and has to be added.

    So the three files that will be important are mydll.h, mydll.dll and mydll.lib. Only mydll.lib need be added to the inputs link line.

    HTH,
    Last edited by ahoodin; November 22nd, 2008 at 04:27 PM. Reason: added HTH
    ahoodin
    To keep the plot moving, that's why.

  3. #3
    Join Date
    Nov 2008
    Posts
    3

    Re: Problems linking my unit test project

    All of the projects need to build as EXE's, not DLL. The only DLL is the one for the unit testing framework, and that is properly referenced.

  4. #4
    Join Date
    Mar 2001
    Posts
    2,529

    Re: Problems linking my unit test project

    So look at all your externs and make sure that there is a matching symbol without the extern spec.

    http://msdn.microsoft.com/en-us/libr...2z(VS.80).aspx

    here is a simplified example of how to do this:
    Code:
    //inside globals.h 
    //include this file to main with GLOBAL defined, and undefine it for other modules in the project
    #ifdef GLOBAL  
    int global_variable_example;
    #else
    extern int global_variable_example;
    #endif
    Note: Please Don't use global variables, they are hazardous to programming. I only used this as an example.
    Or:
    Code:
    //inside globals.h 
    //include this file to main with GLOBAL defined, and undefine it for other modules in the project
    #ifdef GLOBAL  
    CEnvironment environment;
    #else
    extern CEnvironment environment;
    #endif
    to be more correct.

    Try moving your header files order around as well a bit. It may be just a little trick.
    Last edited by ahoodin; November 22nd, 2008 at 05:19 PM.
    ahoodin
    To keep the plot moving, that's why.

  5. #5
    Join Date
    Nov 2008
    Posts
    3

    Re: Problems linking my unit test project

    Well, here's an update. I managed to get it working by putting the Tests project in the same directory as the Server project. I consider it a suboptimal solution, because I don't like having the source files from multiple projects together in the same directory. But at least now the tests and the server will build into separate EXEs, which is definitely an improvement.

  6. #6
    Join Date
    Mar 2001
    Posts
    2,529

    Re: Problems linking my unit test project

    Good. Sounds like you just need to modify your IDE directories.
    ahoodin
    To keep the plot moving, that's why.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured