0

I'm using Visual Studio 6.0 for a VC++ project. There are about 38 projects included in the workspace. I need to use the functions present in one of the projects, say X project... in another project say Y.

One way to do is to add all the .cpp files and .h files present in project X to project Y. This works. But I'm looking for a solution where I can include all the files of the project X, in project Y without actually adding the files physically. Some kind of settings must be there which should help me do this. I tried including all the related DLL's and .lib files present in X to Y, and when I execute, I get the error: unresolved external symbol"public:virtual__ blah blah...

2
  • what sort of projects are they? dlls? static libs? exes?
    – StevieG
    May 6, 2011 at 10:36
  • the project files generate a DLL.
    – user741196
    May 7, 2011 at 13:04

2 Answers 2

0

Add the path containing the header file that you want to use (x.h) into

Project->Settings->C/C++->Category(Preprocessor)->Additional Include directories

Then add the path containing the .lib file for the project you want to use (x.lib) into

Project->Settings->Linker->Category(Input)->Additional Library path

Finally, enter the name of the lib you want to use (x.lib) into

Project->Settings->Linker->Category(General)->Object/library modules 

Then just do

#include <x.h> 

at the top of your new file in project Y to use methods from x.h

1
  • For the class redefinition error - this means you're including the same header in more than one other file, this means that the compiler will have multiple copies. To get prevent this, you should use #define in the included header file to ensure its included only once. Something like #ifndef X_H# define X_H <your code> #endif
    – StevieG
    May 10, 2011 at 9:27
0

When you want to use a function of project X in project Y than the project X must be a kind of library (static library or DLL). To do so, you have to

  • change the include search path of project Y so that it includes the directory where the header files of project X reside.

  • add the library X.lib to the linker "additional libaries" of project Y. If X is a DLL project th X.lib import library is added, if X is a LIB project, the project output is immediately the X.lib to be added to project Y.

The latter step can be done be defined "project depencies" in the workspace. But I recommend to do this with linker settings.

Added the .cpp files to the project Y is a bad idea. The project X is designed to compile its files.

Edit: If X is a DLL project then it must export the symbols that you want to use.

2
  • Hi, project X is dll project. So in the project Y Settings-Link-Input-Additional Library path: I entered X.lib, doesnt seem to work.It gives me unresolved external symbol error. However, if I add the .cpp file from X project, the error goes off. What mistake am I doing here ?
    – user741196
    May 10, 2011 at 5:47
  • If Y is a DLL project, the Y.lib will define the exported symbols. Therefore you need to export the symbols that you want to be accessible when the DLL is loaded.
    – harper
    May 10, 2011 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.