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?
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 03:27 PM.
Reason: added HTH
//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 04:19 PM.
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.
Bookmarks