Error in Visual Studio - c++

I get this error in visual studio and I don't know the reason. It doesn't even show the line number. Any clue?
Error 1 error LNK2028: unresolved
token (0A000041) "void __cdecl
free_img(struct Image *)"
(?free_img##$$FYAXPAUImage###Z)
referenced in function "double *
__cdecl calc_zernike_moments(struct Image const *,int,struct ZernikeBasis
const *)"
(?calc_zernike_moments##$$FYAPANPBUImage##HPBUZernikeBasis###Z) zernike_moments.obj TestLibrary

You have a routine
double * __cdecl calc_zernike_moments(struct Image const *foo,
int baz,
struct ZernikeBasis const *bar)
that calls a routine
void __cdecl free_img(struct Image *foo)
and you didn't supply the free_img() routine that matched to the linker.

free_img() is a function that is either defined in a .cpp file that you haven't included in the project, or it is in a DLL or static library that you haven't linked against. If it is the former, you need to search for the function in your source files and then add that .cpp file to the project. If it is the latter, then you need to identify which library provides free_img() and then locate the .lib file for that library. Then you can do this:
To add .lib files as linker input in the development environment
Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.
Click the Linker folder.
Click the Input property page.
Modify the Additional Dependencies property.
(from http://msdn.microsoft.com/en-us/library/ba1z7822(VS.80).aspx)

You need to link the library. Where is the definition of free_img()?
You are just including the .h and not linking lib

The error is a linker error, not a compiler error, so there won't be a line number associated with it. Rather the error is telling you that your function calc_zernike_moments is calling another routine, free_img, that isn't defined in any of TestLibrary's compiled sources, so you need to provide it by other means. Typically what's missing here is the third-party library need be included in the project so the linker can bring in free_img's implementation.

Related

LNK2019 : unresolved external symbol, searched for in a non-existing *.obj file

Good morning,
I have just inherited an application from a collegue who has left, and I'm already in trouble: the last thing we have done is porting the solution from Visual Studio 2010 to 2013.
Now while building one of the projects in the solution, I get following error message:
1>usharedmemory.obj : error LNK2019: unresolved external symbol "public: __cdecl C_NamedSemaphore::C_NamedSemaphore(char const *,unsigned int)" (??0C_NamedSemaphore##QEAA#PEBDI#Z) referenced in function "public: __cdecl C_RecursiveNamedSemaphore::C_RecursiveNamedSemaphore(char const *,unsigned int)" (??0C_RecursiveNamedSemaphore##QEAA#PEBDI#Z)
This error seems to be caused within the file "Y:\Ucam5\ucm\x\rip_mlfdpf\usharedmemory.obj" (within the project's directory), but after having a quick look, it seems that this *.obj file does not even exist.
Hence the next question: what can I do in order to be sure that the *.obj file gets created? I have already verified that the "usharedmemory.cpp" file is present in the directory of the main project (the corresponding *.h files is located in the "External Dependencies" chapter, which makes me believe that the *.obj file will be created during the build of the main project.
You see my problem: my project refers to a file which the project needs to create, but as the project does not create the file, he obviously can't refer to it, you see the circle I'm running in :-)
(for your information, I have no idea on how to generate an "*.obj" file)
Can anybody help me?
Thanks
Object files (*.obj) are created directly from source files (*.cpp) by the compiler at compilation time, for each source file in your project.
The error you are receiving is not caused by usharedmemory.obj not existing; it should be created in the Debug or Release folders.
The error you are getting is because usharedmemory.cpp uses the C_NamedSemaphore(char const *,unsigned int)-constructor of C_NamedSemaphore and the definition of the constructor can not be found in any of the source files. This constructor is used in the C_RecursiveNamedSemaphore(char const *,unsigned int)-constructor defined in usharedmemory.cpp. This is what the error message reads.
To solve this, you need to find out where the constructor of C_NamedSemaphore is defined (which source file) and ensure that this source file is included in your project. Or, if it is in a library file (static or dynamic), verify that this library file is included as an Additional Dependency (under project Properties -> Linker -> Input -> Additional Dependencies; ensure you set this for all builds, not just the currently active one).
Good morning,
I have finally solved my issue. As a good citizen, I will describe how I have done it :-), but as a less good programmer, I need to admit that I don't understand how my actions solve the problem ;-(
I have done a file comparison of both *.vcxproj Visual Project files (the old one from VC2010 and the new VC2013 one). In that way I have seen that the "umultiproc.cpp" entry was missing in the VC2013 one:
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
...
<ItemGroup>
...
<ClCompile Include="..\..\mp\umultiproc.cpp" /> <!-- missing -->
Summary: In the error message, there was an unresolved symbol (C_Semaphore constructor), which was defined in *.cpp/*.h source/header file. In order to solve the error, I have added a reference to the *.cpp source file into the VC2013 project file.

Google Protocol buffer c++ link error when trying to use it in project

I am trying to get protocol buffer to work but linking problems occurs.
All the errors looks something along like this
error LNK2019: unresolved external symbol "public: bool __cdecl google::protobuf::MessageLite::ParseFromArray(void const *,int)" (?ParseFromArray#MessageLite#protobuf#google##QEAA_NPEBXH#Z) referenced in function "void __cdecl ReceiveRequest(bool *)" (?ReceiveRequest##YAXPEA_N#Z)
I am using visual studio pro 2013 and this is what I have done:
I compiled the protocol buffer and added the libprotobuf.lib to the project(Add->Existing Item->libprotobuf.lib)
I've added the header files in C/C++ -> General -> "Additional Include Directories"
I have tried to add the library all the different ways I know but I still get these linking errors...
Any idea what I might have done wrong?
// Eric
You need to include the generated protocol buffer .cc (and maybe the .h) file (ie the file with the specific getters and setters for your specific proto) in your VS project (ie there has to be a little icon for them in the solution explorer) or else visual studio won't generate the code for it and thus there's nothing to link to.
Make sure you have the correct libraries for your architecture (e.g. x86 / x64).
That has caught me out a few times.

LNK2019 error One DLL linking wih MFC DLL

I'm new to MFC.
I'm trying to make a DLL in MFC, which links to another DLL.
The problem is when I try and compile, I get a LNK2019 error thrown at me for a function present in the DLL which I'm trying to link.
LNK2019 is when the DLL or the function inside the DLL is not being found.
I've taken all steps, the DLL is placed in a known location, the lib is placed in a known location too, it's been added in the additional dependencies, all correct switches have been applied ( ones I know of anyway ).
I've used Dependency walker and I know the DLL, to which I'm trying to link, exposes this function.
I've other examples of use of the function, and I'm trying to use it exactly like it.
The .lib and .dll are in agreement, i.e., they're consistent with each other.
But still the error persists.
EDIT
This is the error message :
Error 2 error LNK2019: unresolved external symbol
"__declspec(dllimport) public: bool __thiscall
PwServer::Connect(wchar_t const *,unsigned long,unsigned long *)"
(_imp?Connect#PwServer##QAE_NPB_WKPAK#Z) referenced in function
"public: bool __thiscall CPwServer::Connect(class
ATL::CStringT > >,unsigned long,unsigned long *)"
(?Connect#CPwServer##QAE_NV?$CStringT#_WV?$StrTraitMFC_DLL#_WV?$ChTraitsCRT#_W#ATL#####ATL##KPAK#Z)
And this is the call I use to access the DLL.
bool conn = PwSrv->Connect(_T(""));
Dumpbin Export of the function :
25BE6 ?Connect#PwServer##QAE_NPBGKPAK#Z 25BE6 __imp_?Connect#PwServer##QAE_NPBGKPAK#Z
Is there something else which needs to be dine in case of linking a MFC DLL with a regular one, like adding AFX_EXT_ or something?
Kindly advise in this.
Thank you.
UPDATE
Seems all that was required was to toggle the flag set in Project Properties>>C/C++>>Language>>Treat wchar_t as a built in type to NO. I'd never bothered with the flag before, so didn't know. The Linker error was there...
OK. Now I've another problem. The toggling of wchar_t solved the problem of the DLL linking with another MFC DLL, but now my application cannot find the entry point in my DLL. In dependency walker, it shows a mismatch between CString which the application is sending, and the Unsigned Short..which my DLL is accepting ( as a result of thewchar_t turned off, presumably )
Assuming you correctly included the .lib file for the DLL (most of the time this is down to differences in the compiler settings. e.g. UNICODE setting).
Check that the .lib is actually being loaded by setting the 'Show Progress' Linker settings to VERBOSE.
Run DUMPBIN on the LIB file to check that the exported functions are the same as the ones the linker is trying to import.
ie
dumpbin /ALL mylib.lib > exports.txt
If the name decoration is slightly different that'll give you a clue as to the problem.

Wrong function name mangling

I have a static library exporting the function
time_t SomeClass::getTime();
After compilation its name is mangled as
?getTime#SomeClass##QAE_JXZ
When I try to use it, VS returns an error
error LNK2001: unresolved external symbol "public: long __thiscall SomeClass::getTime(void)" (?getTime#SomeClass##QAEJXZ)
And I don't know what is wrong. Why the same function is mangled differently? I've compiled both projects with the same Visual Studio, class has a single header.
Please, help.
The problem was in difference in time_t declarations. Library means it is 64-bit, but application waits for 32-bit value.
The remaining question is "why there is no good documentation for MSVS name mangling"? I've read a lot, but didn't find what is the underline in parameters list.
Have you included the .lib file in your linker INPUT property?
In the case you have both two projects in the same solution, you can add the library as a reference to the main project: right click in the main project, and References.
Cheers,
Try to rebuild the whole project.
If this does not work, check your Visual Studio Directories (header, libs)

Building and linking test code for Crypto++

I'm trying to write some simple test code for the Crypto++ library for a project. I have yet to manage to get my own code to build though. It compiles fine, the problem comes in linking. I'm still pretty new to Visual Studios, but I'm using VS10. The errors I'm getting are:
1>sec_test.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall CryptoPP::DES::Base::ProcessAndXorBlock(unsigned char const *,unsigned char const *,unsigned char *)const " (?ProcessAndXorBlock#Base#DES#CryptoPP##UBEXPBE0PAE#Z)
1>sec_test.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall CryptoPP::DES::Base::UncheckedSetKey(unsigned char const *,unsigned int,class CryptoPP::NameValuePairs const &)" (?UncheckedSetKey#Base#DES#CryptoPP##UAEXPBEIABVNameValuePairs#3##Z)
I've tried everything I can find in the documentation in terms of linking. I've never linked against a DLL before, but these are the errors I get when I try to. If I try to do what I think is linking against the static library version, I get even more.
I should note, I'm trying to test pure DES at the moment. In particular, here are the API calls I'm making, just to be safe:
DES::Encryption DES_encrypt;
DES_encrypt.SetKey(key, 64);
DES_encrypt.ProcessAndXorBlock(plaintext, NULL, ciphertext);
DES::Decryption DES_decrypt;
DES_decrypt.SetKey(key, 64);
DES_decrypt.ProcessAndXorBlock(ciphertext, NULL, decrypted);
If anyone can help, or point me in the right direction, I'd be much obliged.
First thing to check is your project properties (right click on project, click Properties).
External libraries need to be specified in the Linker->Input->Additional Dependencies field, either by absolute path or in conjunction with the other VS path properties.
You can look in Linker->Command Line and check that the .lib files you want are actually being passed to the linker.
An alternate method is to turn off the Suppress Startup Banner option in the Linker->General options, and then check the build output to make sure it has what you want.
If you know that the libraries you want are being linked, another useful trick is to check the output of the strings command (in linux or cygwin) or dumpbin /HEADERS in the VS command prompt. You can look through the output of these commands for the symbol VS claims is missing to verify that it really is defined in the .lib file. Sometimes larger software packages have multiple .lib files, so this can help make sure you are linking the one that has the symbol you want.