简体   繁体   中英

Linker error when parameters are passed by reference to C++ dll

In my application, I have a dll which exposes a function that takes two vectors:

static int myFunc( vector<double> vec1, vector<double> &vec2 );

When I changed this declaration to

static int myFunc( vector<double> &vec1, vector<double> &vec2 );

I get a linker error saying this:

error LNK2019: unresolved external symbol "__declspec(dllimport) public: static int __cdecl myFunctions::myFunc(class std::vector<double,class std::allocator<double> > &,class std::vector<double,class std::allocator<double> > &)" (__imp_?myFunc@myFunctions@@SAHAAV?$vector@NV?$allocator@N@std@@@std@@0@Z) referenced in function "public: void __thiscall MainWindow::modelMeanCurve(void)" (?modelMeanCurve@MainWindow@@QAEXXZ)

Why is this behavior and how do I resolve this error so that I can pass the reference to the first argument also?

Thanks,Rakesh.

Well, it is not enough to change the declaration alone. You also have to change the definition of that function and recompile the DLL.

If you simply changed the declaration and left the definition unchanged, you essentially created a new declaration for a function that does not really exist. The DLL still contains the original function with original set of parameters, which is now completely unrelated to you new declaration. This is what the linker is telling you through the above error.

Thank you @Michael Burr, I was referring to a stale copy of the .lib file. I replaced this with the new version and everything built fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM