How to undecorate linker object names in Visual Studio? - c++

To undecorate mangled C++ names that Visual Studio generates in compiled libraries, one can use undname.exe. However, I am having an issue identifying the unmangled names if the library cannot compile due to unresolved external symbols.
Example:
Error LNK2001 unresolved external symbol __imp_ldap_value_free_len libcurl.lib(ldap.obj)
When try to I undecorate that name, I get the following:
C:\Program Files (x86)\Microsoft Visual Studio 14.0>undname.exe __imp_ldap_value_free_len
Microsoft (R) C++ Name Undecorator
Copyright (C) Microsoft Corporation. All rights reserved.
Undecoration of :- "__imp_ldap_value_free_len"
is :- "__imp_ldap_value_free_len"
This shows that the linker uses a different mangling format for intermediary object files. How do I obtain the original method header?

The important thing to realize about names of the form __imp_ldap_value_free_len is to drop the __imp_ prefix and figure out where the remaining symbol name comes from. And indeed there is a ldap_value_free_len in Wldap32.dll (you link against Wldap32.lib).

Related

C++: Unresolved external symbol _sprintf and _sscanf in Visual Studio 2015

For a research project, I'm writing a C++ add-on to a scientific computing language. Unfortunately the library that allows users to do this is not kept very well up-to-date.
I started the project in XCode, where it built fine. Later I had to move to a PC, so I migrated the code to Visual Studio 2015. Since doing this, I haven't been able to build due to the following errors:
LNK2001 : unresolved external symbol _sprintf
LNK2019 : unresolved external symbol _sscanf referenced in function _GetDDouble
LNK2019 : unresolved external symbol _sprintf referenced in function _CheckRunningInMainThread
An attempted fix was to add the header #define _CRT_SECURE_NO_WARNINGS. However, this a) fixed no errors and b) added the warning C4005 : '_CRT_SECURE_NO_WARNINGS': macro redefinition. I assume the library already defined this macro, anticipating this problem. Regardless, it didn't solve the problem.
How should I proceed?
Add the following library to the linker input files:
legacy_stdio_definitions.lib
VS 2015 now uses inline definitions that call internal functions for many of the stdio.h functions. If an object file (or library member) depends on one of those functions, then the legacy_stdio_definitions.lib provides an externally linkable version of the function that can be linked to.
Your other option is to recompile the unit that depends on those functions with VS 2015 (this is probably the preferred option).
I got this error compiling cycling max plugins against version 5 max sdk (pure c api). The legacy library fix didn't work for me (it should have, and if anyone had any idea why it mightn't I'd be curious), but I defined _NO_CRT_STDIO_INLINE before stdio was loaded and that did do the trick.
I recently encountered this and was able to add User32.lib to Linker > Input > Additional Dependencies.
You could also include #pragma comment (lib, "User32.lib") in your code.

Linker error while linking some windows APIs

I have a makefile project in my system. Recently, I added some new functions which makes use of the following Windows APIs:
RegOpenKeyEx
RegEnumKeyEx
RegCloseKey
RegGetValue
For having those APIS I added the windows.h header file as well.
The code compiles and links fine in my machine. But, linking fails in my colleagues machine. We all are working on 64 bit windows machine.
In his PC I get the error:
error LNK2001: unresolved external symbol __imp_RegOpenKeyExW
error LNK2001: unresolved external symbol __imp_RegGetValueW
error LNK2001: unresolved external symbol __imp_RegCloseKey
error LNK2001: unresolved external symbol __imp_RegEnumKeyExW
What I tried:
Since the library being used was Advapi32.lib in C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\x64
I tried adding following line:
LINKFLAGS += -L "C:\Program Files (x86)\Microsoft
SDKs\Windows\v7.0A\Lib\x64"
I added the path of the library to environment variable PATH
I copied the lib to the output folder.
Nothing worked.
As I said earlier, the code works fine in my PC but fails in another one.
The registry functions require you to pass Advapi32.lib to the linker. This is the step that you have missed.
If you are using visual stdio, check your project property vs your friend's project property and check link library path+ library name with .lib shoul be included. It seems in your friends computer is not getting the library to resolve the symbols. Compile time checking is done only with header files. While linking it should find the definition of yor function in library.
for command line:
from:http://social.msdn.microsoft.com/Forums/vstudio/en-US/6bcae3d1-85b6-471d-a4ee-7b455b21460b/how-do-i-link-libraries-that-are-sitting-in-different-directories-from-the-command-line?forum=vcgeneral
cl main.obj ab1.lib ab2.lib de1.lib de2.lib gh1.lib /Fetestmain.exe /link /LIBPATH:C:\test\ab /LIBPATH:C:\test\de /LIBPATH:C:\test\gh
The "/link" is very important...do not use "/LINK", the uppercase LINK is not recognised.

how can i solve the link error My visual C++ 2008 with OpenCV?

I am the very bignner for the OpenCV.
I’ve just install the OpenCV and make the C++ program as follow.
My compiler is visual C++ 2008.
# include "highgui.h"
void main() {
IplImage* img = cvLoadImage("C:/OpenCV/samples/cpp/tutorial_code/images/lena.png",-1);
cvNamedWindow("lena",0);
cvShowImage("lena",image);
cvWaitKey(0);
cvReleaseImage(&image);
}
But it could not be built with the error message, and I cannot solve this problem.
The error message is as follow.
(My compiler is Korean Version and I translate the error message into English.
And the English is poor, but you may understand how it was processed.)
1>------ begin build: project: image1st,: Debug Win32 ------
1> compiling)
1>image1st.cpp
1>c:\vs2008\ccp_file\image1st\image1st.cpp(17) : warning C4700: not inetialized ‘image’ use local variable
1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>linking
1>image1st.obj : error LNK2019: _cvReleaseImage External Symbol(refrence positon: _main function) not defined.
1> image1st.obj : error LNK2019: _cvWaitKey External Symbol(refrence positon: _main function)not defined.
1> image1st.obj : error LNK2019: _cvShowImage External Symbol(refrence positon: _main function)not defined.)
1> image1st.obj : error LNK2019: _cvNamedWindow External Symbol(refrence positon: _main function)not defined.)
1>image1st.obj : error LNK2019: _cvLoadImage External Symbol(refrence positon: _main function)not defined.)
1>project: warning PRJ0018 : can not find the next environment variable.
1>$(OPENCV_DIR)
1>image1st – errors: 6, warning: 1
And I modified the visual c++ environment are modified as follow.
And I input “$(OPENCV_DIR)\include” in the “Additional Include Directories” entry,
and make the “Additional Dependencies” entry to include the next .lib file as the OpenCV Tutorials
Release 2.3 guides.
‘opencv_core231d.lib’
‘opencv__imgproc231d.lib’
‘opencv__highgui231d.lib’
‘opencv__ml231d.lib’
‘opencv__video231d.lib’
‘opencv__features2d231d.lib’
‘opencv__calib3d231d.lib’
‘opencv__objdetect231d.lib’
‘opencv__contrib231d.lib’
‘opencv__legacy231d.lib’
‘opencv__flann231d.lib’
And the include and library directories of visual c++ environment are modified as follow.
For library:
$(VSInstallDir)lib
$(VSInstallDir)
$(FrameworkSDKDir)lib
$(WindowsSdkDir)\lib
$(VCInstallDir)atlmfc\lib\i386
$(VCInstallDir)atlmfc\lib
$(VCInstallDir)lib
C:\opencv\build\x86\vc10\lib // modified
C:\opencv\build\x86\vc9\lib // modified
C:\opencv\build\x64\vc10\lib // modified
C:\opencv\build\x64\vc9\lib // modified
C:\opencv\build\gpu\x86\lib // modified
C:\opencv\build\gpu\x64\lib // modified
For include:
$(VCInstallDir)atlmfc\include
$(WindowsSdkDir)\include
$(FrameworkSDKDir)include
$(VCInstallDir)include
C:\OpenCV\build\include\opencv // modified
C:\OpenCV\build\include\opencv2 // modified
C:\opencv\build\include // modified
It's seems that your processor can't recognize the user vairble OPEN_CV
first, make sure that the system\user vairble is correct.
in order to do that go to system properties --> on advance menu --> to go Enviroment variables --> make sure your system variable is correct , if not please create one with the path to your open cv library location.
it's seems like you are doing everything right ,
I believe your problem is that you have missed some at the post build step ...
Second , you'll have to copy the dll files from the openCV library to the location of your project.
in order to do so , please include an appropriate path on the post build step on your project.
go to your project : properties ... watch the picture
and include the command:
copy "C:\OpenCV2.31\CMake_Build\bin\Debug\*.dll"
copy "C:\OpenCV2.31\CMake_Build\bin\Debug\*.pdb"
Good luck
S
Basically it seems, that the compiler cannot find the OpenCV libraries or has trouble identifying the right one.
Make sure, that the needed libraries (i.e. opencv__xxx.lib) can be found in the directories you specified in the library directories (C:\opencv\build\x86\vc10\lib etc.) Also, you should only specify the directories for your platform, i.e. only vc9 (since you're using VS2008) and x86/x64 depending on your architecture.
The PRJ0018 warning indicates, that the OPENCV_DIR environment variable is not set. You can do this in the System properties dialog (usually you get it by right-clicking on "My Computer" and select "Properties", in Win7/Vista you have to go to "Extended System settings") on the "Extended" Tab, there's a Button "Environment variables". But if you already modified the include directories, you can omit the "Additional include directories" setting anyway.
may be it can help you.
Using OpenCV 2.1 with MS Visual Studio
OpenCV 2.1.0 with Visual Studio 2008

resolve link errors for __imp__open and other similarly named functions using Microsoft Visual C++ 6.0

Link errors like this sometimes occur when compiling C++ using Microsoft Visual C++ 6.0:
error LNK2001: unresolved external symbol __imp__close
error LNK2001: unresolved external symbol __imp__read
error LNK2001: unresolved external symbol __imp__lseek
error LNK2001: unresolved external symbol __imp__open
My fix, which I found after searching fruitlessly using Google for a long time, is this:
Do NOT disable language extensions. In the Project Settings dialog, in the C/C++ tab, make sure that the 'Disable language extensions' checkbox is not checked.
The functions close, read, lseek, open, etc., are not standard parts of the C library and the declarations are skipped by conditional compilation using #if !__STDC__ in <io.h>. This happens if you disable language extensions.
The answer is that the __imp prefix refers to function stubs in the OBJ library for the DLL version of the CRT. This means your linker options are incompatible with your compiler options (linker set to static CRT or no CRT and compiler set to dynamic CRT).
In your case rather than the CRT itself it is another library, but the same idea.

static library works in console but not in GUI app - strange

I have a strange error that has bothered me all day. I have a library function that I have compiled. I statically link the library to test it in a separate console application and everything builds and works ok. It is just a simple sqrt function called sqrtval at the moment. However, when I include this library in a larger graphical project then I get linker errors. I have set the Additional library directories and Additional dependency settings identically in both the console app (that works) and the graphical main app (that does not work). The error is as follows.
1
Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
1>Copyright (C) Microsoft Corporation.
All rights reserved. 1>Linking...
1>MainAppWindow.obj : error LNK2019:
unresolved external symbol "double
__cdecl sqrtval(double)" (?sqrtval##YANN#Z) referenced in
function "public: virtual void
__thiscall MainComponent::sliderValueChanged(class
juce::Slider *)"
(?sliderValueChanged#MainComponent##UAEXPAVSlider#juce###Z)
1>....\bin\Debug\tutorial.exe : fatal
error LNK1120: 1 unresolved externals
If your library is written in plain C, you have to declare sqrtval as:
extern "C" double sqrtval(double);
What does the linker command line look like? Is your library listed on the linker command for the GUI application?