0
votes

I have several functions in a .cpp file and I want several of my projects use the same file. So instead of copy them to different directories just add them (from original location) to project file in visual studio and use them.

The problem is #include "stdafx.h" seems to refer to the same directory as the file exist and this causes compiler problems.

Is there a way or workaround or am I doing something conceptually wrong?

(I think making it as a static library is a bit overkill. compiling and building new project and making sure others are using correct DEBUG/RELEASE .lib. Hmmmm. A bit hard for a lazy coder!)

1
Create a static library project with just that file. Have all other projects depend on the library, rather than directly mention the source file.Igor Tandetnik
If you don't need to use precompiled headers for this file, then get rid of #include "stdafx.h". Then right click on the file in the Solution Explorer, select properties, and somewhere in the options pages for C/C++ there's an option to disable precompiled headers. You could also switch them off for the entire project.Praetorian

1 Answers

1
votes

I think what you should do is to include that ".cpp" file in a library (.DLL). Then you can statically load it in your project files by including that library (.LIB) and the header file of the library that exports the functions (.H) into the projects that are using the library. That way you will statically load your (.DLL) into memory using the (.LIB) file and the functions will be available through the (.H) file that you will create when making your library.

I know saying this was is not that obvious, especially if you haven't done it in the past. If you want, you can upload your project files onto some location and give the link. And I can give you a better description of what you need to do.