-
Notifications
You must be signed in to change notification settings - Fork 514
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
Comments
It says you are not linking the function calc. AFAIK. That is not in CppuTest, so I guess you have a method called calc somewhere that you aren’t linking?
|
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 ;)... |
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) |
What do you mean with:
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. So much thanks for your help! :) |
It looks like you are calling `calc(int,int)` a C++ stand alone function
(note the parameter types in the link error.
I presume calc is a C function in a .c file. You need to tell C++ that
this is a C function. Something like this:
```
#include "CppUTest/TestHarness.h"
extern "C"
{
#include "calc.h"
}
TEST_GROUP(Calc)
{
};
TEST(Calc, called_with_1_2)
{
calc(1,2);
}
```
The C linker only cares about the function name. It is not concerned
the the parameter types.
HTH, James
…--------------------------------------------------------------------------
James Grenning - Author of TDD for Embedded C - wingman-sw.com/tddec
wingman-sw.com
wingman-sw.com/blog
twitter.com/jwgrenning
facebook.com/wingman.sw
[![wingman
software](http://www.wingman-sw.com/images/wingman.png)](http://wingman-sw.com)
On 11 Aug 2018, at 21:09, Bas Vodde wrote:
Hi,
It says you are not linking the function calc. AFAIK. That is not in
CppuTest, so I guess you have a method called calc somewhere that you
aren’t linking?
Bas
> On 11 Aug 2018, at 6:41 PM, Hallo-Du-Da ***@***.***>
> wrote:
>
> error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""int
> __cdecl calc(int,int)" (?calc@@yahhh ***@***.***)"
> in Funktion ""public: virtual void __thiscall
> TEST_TEMPLATETestGroup_TEMPLATETest_Test::testBody(void)"
> ***@***.***_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....
>
> When I try to set up ceedling UnitTest with the same configuration
> option like I did it for cppUTest, everything works also. Out of
> ceedling I could call the application function out of the lib which I
> like to test....
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <#1169>, or mute the
> thread
> <https://github.com/notifications/unsubscribe-auth/AAfH37I9Y4gtpLa4GcVt4eUh-pqzaDKHks5uPrTsgaJpZM4V5H4R>.
>
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
#1169 (comment)
|
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. |
You are welcome.
I learned that the hard way too. I make a point of that in my TDD for
Embedded C training course. (I have one coming up, maybe you want to
attend).
Cheers and happy you are not stuck!
James
…On 15 Aug 2018, at 18:55, Hallo-Du-Da wrote:
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.
--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
#1169 (comment)
|
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. |
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....
The text was updated successfully, but these errors were encountered: