-2

This question is similar to the one I asked yesterday

https://stackoverflow.com/questions/24332513/error-lnk2019-fatal-error-lnk1120?noredirect=1#comment37614189_24332513

That was answered very comprehensively (even though it turned out to be duplicate).

To solve round the problem I simply added the missing files to the header files and source files in the project explorer using

add existing item...

(I am using visual studio 2008).

However I would like to be able to add these files in a different way by using:

Project properties->General->Include Additional Directories

And adding the location where BinModel01.h and BinModel01.cpp are stored.

but unfortunately this does not seem to work?

(Obviously for one or two files it doesn't make a lot of difference but for bigger projects it would quickly become a pain!)

I get the same errors that I was getting before? (In fact this was the configuration that caused the original errors).

I am certain that I am adding the correct "Additional Directories"?

So do I have to do anything else other than add the additional directories? (it would seem so).

Thanks

Baz

Community
  • 1
  • 1
Bazman
  • 2,058
  • 9
  • 45
  • 65
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – πάντα ῥεῖ Jun 21 '14 at 12:13
  • _'... but for bigger projects it would quickly become a pain!'_ That's what libraries are for ... – πάντα ῥεῖ Jun 21 '14 at 12:20
  • It seems off to me that you can link the header file in another folder but you have to include the source file locally? That way anyone using the library gets to see the implementation? I don't see the advantage of being able to access header files from different directories but not different source files. If anything I would have thought it would be the other way round? – Bazman Jun 22 '14 at 11:00
  • No, you organize bigger projects as libraries (using a functionally associated subset of all the `.cpp` files). Another program then just specifies a corresponding path to find the includes, and links against the library (no more need to add all the implementation files to the client project)! – πάντα ῥεῖ Jun 22 '14 at 11:05

1 Answers1

2

LNK2019: http://msdn.microsoft.com/en-us/library/799kze2z.aspx

From this site: "unresolved external symbol 'symbol' referenced in function 'function'"

This means that you are using a function or variable that is declared but not defined. So you see the .h file, but not the .cpp. In your situation it likely means you haven't added the .cpp files to the project, or you are not compiling them.

You can't add a whole folder to your project, you need to add each file you need (but you can add more files at once).

"Additional Include Directories" means folders where VS will look in for headers in #include statements.

Zsolt
  • 582
  • 2
  • 5
  • ahhh... so I can add the header files via the "additional directories" but I still have to add the corresponding source file directly to the project? – Bazman Jun 21 '14 at 13:37
  • Yes. Only the .cpp files that are added to the project (and not excluded from the build) are actually compiled. Some further reading: https://stackoverflow.com/questions/1106149/what-is-a-translation-unit-in-c – Zsolt Jun 21 '14 at 13:42