- Sep 10, 2005
- 7,458
- 1
- 76
Assuming you're developing on visual studio, how do you normally share code between 2 projects (while only maintaining 1 version of the original code)?
I'm getting a linker error but I'm trying to understand it. Maybe I just forgot a setting in VS. Let's say you have 2 projects. Each has 1 header file and 1 cpp file to implement the functions in their respective headers. Now, you try to use the functions from 1 project in the other. You include the header file that you want and you add the directory to your project. Compile... LNK2019. VS seems to not know where the (.obj) file is for the other project whose function you are trying to use.
Now, where I used to work, every project became a (.dll) and in that sense, it's easy to use code from other projects because VS explicitly asks you where things like the DLL are located. VS doesn't seem to ask where the (.obj) files are located. I also recall there being entire implementations stored in header files (instead of the usual header-cpp pairing), which probably enables you to avoid the LNK2019 problem as well. But VS does this annoying thing where if you implement everything in a header file and 2 cpp files include that header file, the linker will yell at you for having 2 obj files that try to implement the same function.
Anyways, what am I missing? What's the usual procedure for doing this?
I'm getting a linker error but I'm trying to understand it. Maybe I just forgot a setting in VS. Let's say you have 2 projects. Each has 1 header file and 1 cpp file to implement the functions in their respective headers. Now, you try to use the functions from 1 project in the other. You include the header file that you want and you add the directory to your project. Compile... LNK2019. VS seems to not know where the (.obj) file is for the other project whose function you are trying to use.
Now, where I used to work, every project became a (.dll) and in that sense, it's easy to use code from other projects because VS explicitly asks you where things like the DLL are located. VS doesn't seem to ask where the (.obj) files are located. I also recall there being entire implementations stored in header files (instead of the usual header-cpp pairing), which probably enables you to avoid the LNK2019 problem as well. But VS does this annoying thing where if you implement everything in a header file and 2 cpp files include that header file, the linker will yell at you for having 2 obj files that try to implement the same function.
Anyways, what am I missing? What's the usual procedure for doing this?