开发者

How to use the functions present in a project, in another project without actually adding the header and source files manually?

开发者 https://www.devze.com 2023-03-03 02:24 出处:网络
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

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开发者_JAVA技巧 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...


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号