0

I have solution with two projects- proj_1, proj_2.

proj_1 is lib project and proj_2 is regular project

in proj_2 I have function named static void proj_2_func(). Im trying to call that function from proj_1 (without creating an object) but I get linkage error- unresolved external symbol.

proj_2:

class proj_2_class
{
  public:
   static void proj_2_func();  //the implementation is not relevant
}


proj_1:

in cpp file:

#include proj_2_class.h  // I added the path to "additional include files" in proj_1

void proj_1_class::proj_1_func()
{
  proj_2_class::proj_2_func();
}

Ill be happy for guidance on that error.

thanks.

user1673206
  • 1,671
  • 1
  • 23
  • 43

1 Answers1

0

Because your function proj_1_class::proj_1_func calls the function proj_2_class::proj_2_func, the latter needs to have an implementation provided somewhere - failing to do so is what causes the linker error

Smeeheey
  • 9,906
  • 23
  • 39
  • it has implementation on `proj_2` class.. – user1673206 Nov 29 '16 at 09:07
  • Is the file `proj_2.cpp` (or whatever the file is called which provides said implementation) compiled when building `proj_1`? I suspect not – Smeeheey Nov 29 '16 at 09:08
  • I first compiled `proj_2` and after that- compiled `proj_1` – user1673206 Nov 29 '16 at 09:11
  • Then you're not including the object file produced by `proj_2` during linking. Can you share your linker command line, and also the full linker error (i.e. which exact symbol is it complaining about)? – Smeeheey Nov 29 '16 at 09:12
  • I dont have linking to `proj_2` from `proj_1`because its not dll project (probably this is my error). the only outputs `.pdb` file. how should the linker look like? – user1673206 Nov 29 '16 at 09:38
  • this is the full linker error: LNK2019 unresolved external symbol "public:static void _cdecl proj_2::proj_2_func()" referenced in function "public: void _cdecl proj_1::proj_1_func()" – user1673206 Nov 29 '16 at 09:40
  • Then you need to add `proj_2` as a library used in building `proj_1`. If you were doing this directly on the command line, you would add the option `-lproj_2` at the end of your command line, assuming `proj_2` is built into `proj_2.dll`. – Smeeheey Nov 29 '16 at 09:41
  • Im working on visual studio... I wrote it on the question- `proj_2` is not dll project, its regular project.. should I recompile it as dll project? it has `main` ... – user1673206 Nov 29 '16 at 09:44
  • If `proj_2` is not a library, then how can you 'use' it from `proj_1`? Unless I'm missing something, that doesn't make any sense. If you want say an executable to use code from somewhere else, that 'somewhere else' is either a library (most common case) or manually added object files. You can certainly manually add object files from `proj_2` to `proj_1` using the command line, but if you need to do that then probably you're muddled about what exactly you're trying to do. It would be better to just have `proj_2` be a library instead, or else merge it into `proj_1` so that they're one project – Smeeheey Nov 29 '16 at 09:52