Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

link error in VS2017 when calling a a function out of the project lib (code under test) #1169

Closed
Hallo-Du-Da opened this issue Aug 11, 2018 · 8 comments

Comments

@Hallo-Du-Da
Copy link

Hallo-Du-Da commented Aug 11, 2018

error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""int __cdecl calc(int,int)" (?calc@@yahhh@Z)" in Funktion ""public: virtual void __thiscall TEST_TEMPLATETestGroup_TEMPLATETest_Test::testBody(void)" (?testBody@TEST_TEMPLATETestGroup_TEMPLATETest_Test@@UAEXXZ)".

Can some help me? I Set the linker options (Additional Linker include paths) and the additional dependencies like I did it for the CppUTest.lib. Without calling the function in the project, everything work fine....

If I include the source and the header directly into the project and delete the lib, the error is still the same.

If I try to set up ceedling UnitTest with the same configuration option like I did it for cppUTest with the same lib, everything works fine. Out of ceedling I could call the application function out of the lib which I like to test....

@Hallo-Du-Da Hallo-Du-Da changed the title link error in VS2017 when calling a a function out of the real project (code under test) link error in VS2017 when calling a a function out of the project lib (code under test) Aug 11, 2018
@basvodde
Copy link
Member

basvodde commented Aug 12, 2018 via email

@Hallo-Du-Da
Copy link
Author

Hallo-Du-Da commented Aug 12, 2018

Yes, it is a function "calc()" in a lib (the production code project which I compile as a static lib). I have added this lib and its output path to the "UTest" Testproject linker settings in VS like I did it for the CppUTest.lib (as described in the WalkThrough_VS21010.docx).

If I add the same lib and path to a ceedling/Unity test project and call this function calc() on the same way form this project, everything compiles and links fine...

How can I link this function in VS ? I don't see my brainless mistakes currently ;)...

@basvodde
Copy link
Member

It is hard to give more info. The linker says it cannot find the calc method. If it is in the static library, then either it isn't linking that library, or it is not in the library, or the link order is wrong, or you have different methods for generating the symbols. The latter 2 are unlikely in VC, so I would assume it is either (1) or (2)

@Hallo-Du-Da
Copy link
Author

What do you mean with:

  • "different methods for linking the name"
  • " latter 2 are unlikely" ... I would assume ... or (2) ?

I had try to add a source and a header directly into the cppUTest project and write a dumme function. This also result in the same linking error.

Could the the problem be, that my lib (and my dummy function source + header) are plain C functions and a plan C project and the linker search for a cpp lib to link? If so, how can I change this and what is the different between a cpp and a c lib? Is it only the file extansion ".cpp" and ".hpp" which corresponds into a cpp lib? Or what are the depandencies to generate a cpp or a c.
Must I "only" use the C Macros?

So much thanks for your help! :)

@jwgrenning
Copy link
Member

jwgrenning commented Aug 15, 2018 via email

@Hallo-Du-Da
Copy link
Author

WOOOWW YMMD !! I never knew that rally before to set the header include in extern "C" braces. I spend so much hours into learning this. And without you I would have spent many more hours searching at wrong places additionally. Thanyou.

@jwgrenning
Copy link
Member

jwgrenning commented Aug 16, 2018 via email

@Hallo-Du-Da
Copy link
Author

Hallo-Du-Da commented Aug 17, 2018

Thank you James, my father of TDD ;)

BTW: Will there be a second edition of your book in the (near) feature? In my impression there are so much (kind of) thinks which had changed or are more complex today than described it in your book. But ok I have not read it completely yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants