LNK prob. Wrapping MFC Application with /clr - c++

I have a problem writing wrapper program to use vendor's library in .Net client program(C#).
What the vendor provided are C++ header file and MFC static library file(.lib) built on both release and debug.
The problem is, when I build wrapper program, Visual Studio 2012 spits LNK error out like this:
error LNK2001: unresolved external symbol ___argc nafxcwd.lib(appcore.obj)
error LNK2001: unresolved external symbol ___argv nafxcwd.lib(appcore.obj)
I set up build property with option /clr,
set runtime library as Multi-threaded debug DLL (/MDd),
set using MFC as MFC in shared DLL,
ignored libraries(nafxcwd.lib;msvcrtd.lib;msvcmrtd.lib;libc.lib;libcmt.lib;msvcrt.lib;libcd.lib;libcmtd.lib, see this),
added dependencies(nafxcwd.lib;msvcrtd.lib;msvcmrtd.lib;(vendor's library), for CRT, MFC library order).
What I missed?
I don't know I described enough. If something is ambiguous, please ask to me.
Thanks in advance!
ps. I'm very new to C++(even Visual Studio..). I'm more familiar with Java.

Related

Unresolved external symbol when building in realease mode (LNK2001)

My solution has 3 projects:
native C++ (static lib)
CLI/C++ wrapper (dynamic lib)
C#
In my native C++ project I have some image processing using opencv 3.2. My CLI/C++ project manages the communication between C++ and C#.
As long as I'm in debug mode, I have no trouble, but when I switch to release mode I get a lot of LNK2001 "unresolved external symbol" errors for the opencv functions.
For both, debug and release, I'm using property sheets for opencv and both of them definitely work (I use them in multiple projects). My native C++ project builds in both modes successfully but the build crashes on the CLI/C++ wrapper (this project uses some opencv functions itself).
I already validated the property sheets (corret libs, paths are set).
Maybe there are some additional rules I have to care about in CLI/C++?
Edit
I'm using C++17 with Visual Studio 2017 on Windows 10.

unresolved external symbol _WebPInitUpsamplersSSE2 - why?

I have compiled QT5.6.2 myself with Visual Studio 2015 to compile some other software (Telegram desktop; build instructions are here https://github.com/telegramdesktop/tdesktop/blob/dev/docs/building-msvc.md#setup-gypninja-and-generate-vs-solution ).
Curiously, it seems necessary to state that I know what an unresolved external symbol is - but that I still cannot solve my issue, especially since it lies within a library that is not custom-made by me: QT
Now, when I try to compile Telegram with Visual Studio 2015 which depends on QT5.6.2, I get a weird unresolved symbol:
1>qwebpd.lib(upsampling.obj) : error LNK2019: unresolved external symbol
"_WebPInitUpsamplersSSE2" in Funktion
"_WebPInitUpsamplers".
I could not find anything on this function or in which library it might/should be defined.
It seems that the QT Webkit is built with Chromium and that during QT's compilation I have somehow activated some kind of SSE2 extension which, however, does not seem to be available now in Visual Studio 2015. I have also tried in "Project Settings -> C/C++ -> Code Generation" to explicitly activate SSE2 but without help. I have no clue where this function should actually be defined.
I know in general what an unresolved external symbol is, but I do not know how to resolve this error in my specific case with QT.

_vswprintf unresolved only for x64

I'm writing a right click context menu extension dll for Windows to support functionality in another program.
It's building fine targeting Win32, but when I try to build for x64, I get this
error LNK2001: unresolved external symbol _vswprintf
I am not actually calling it anywhere in my code, so even if it is undefined, that shouldn't be a problem. (I am including stdio.h, stdarg.h, and wchar.h though, so it should be defined.)

LNK2001 Error on basic_istream, basic_ostream

I'm trying to get around these link errors:
error LNK2001: unresolved external symbol "__declspec(dllimport) public void __thiscall std::basic_ostream(char,struc std::char_traits<char>>::_0sfx(void)"
I used Visual Studio C++ 2010, and tried with Visual Studio C++ 6.0, but still the same errors show up.
The object file is found, so I am suspecting that it cannot find the implementation of the std library? I've tried /nodefaultlib option on a few libraries (libc.lib, libcmt.lib, msvcrt.lib, etc) but did not improve the situation at all.
Could someone explain why the error occurs and where I should look ?
Tried the solutions suggested in other similar questions but they either are not applicable or do not resolve the problem.
Thanks
You should remove /nodefaultlib option.
This problem could arise if some of your libraries are linked static while other dynamically.
Basically if you have both codes compiled with the static version of CRT (that's compiler switch /MT and /MTd) and dynamic version of CRT (switch /MD, /MDd).
You can see what your project is using in Project Properies - c++ - Code Generaion - Runtime Library)
Make sure all your libraries are compiled with the same switch as you project.

C++ Linking problem

I have an error in compiling a project.
I'm trying to link to a library I have on windows, using visual studio.
When trying to create the obkect (with new), I get the following error:
Error 2 error LNK2005: "public: __thiscall std::basic_string,class std::allocator >::~basic_string,class std::allocator >(void)" (??1?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##QAE#XZ) already defined in RMLibV053.lib(Inifile.obj) msvcprtd.lib
I used #ifndef
I used disable warning
It may be that your code is set up to use a different run-time environment (single-threaded, multi-threaded, multi-threaded DLL) than your PTLibV002.lib library when it was built.
If PTLibV002.lib was compiled to use C++ library statically linked and your binary uses C++ library as DLL, then this is the linking error you'd receive. This is because PTLibV002.lib will contain the definitions of functions from STL it uses, and your binary contains another definition pointing to the C++ library DLL.
probably you added a similar library to additional libraries.
As Ferruccio explained before.
I used on the visual studio configuration of project: compiled with the setting to use the dynammic linked run time library : Multi-threaded Debug DLL (/MDd) instead of Multi-threaded Debug (/MTd).