new vs2008 user - c++

I am trying to build a release version of my project. Our prof made us create a static library which i built using debug version.
then i made a release version of that static library using /mt as my c runtime
now in my test application (release version) I use the same runtime option and add that static library and also ignore the libcmd.lib in the ignore settings for the linker.
i resolved most of the problem
this is the last part
lnk4075 /edit and continue due to /opt:icf specification compositelib.lib (my staticlib)
lnk2001 unresolved external symbol _winmain#16. libcmtd.lib
these are the last two that i can't seem to figure out.

add libcmt.lib to ignore list for release version.

Related

Static CRT link

im trying to build my project and I want to link the windows CRT statically, but I find some errors trying to linking it,
I've included in the linking list these ones:
libcmt.lib
LIBCPMT.LIB
libucrt.lib
libvcruntime.lib
but I get these linking errors, saying that these symbols are missing:
__imp_copysignf
__imp__aligned_free
__imp__aligned_malloc
__imp_modf
__imp_modff
I've already added libucrt (which is where must be malloc functions but still giving errors), what lib am I missing?
EDIT: Im using Visual Studio 2017 15.4.4 targeting Windows 10 ver.10.0.16299.0
Double-check that you have also set the /MT compiler flag. If it is not set, it is possible that it defaults to dynamic linking setting. In that case, _MT preprocessor define is missing, which causes the compiler to use calls to dynamic runtime functions. You can see the __imp__ prefix that normally comes from DLL import libraries.

Include static library in VS C++ project

Configuration I have
Windows 10 64bit
Visual Studio Community 2017 with Visual C++ 2017
CMake 3.9.0
opencv 3.3.0
Aim
Goal is to build opencv as a static library (.lib) and include into a Visual C++ project which is a DLL. Everything should be compiled for x86 architecture or simply 32bit.
Process
Latest opencv distributive does not contain dll's compiled for 32bit system and therefore, I need to compile own version. According to the opencv 2.4 documentation on "installation in Windows". I have compiled the library with BUILD_SHARED_LIBS option disabled and configured target project as described in "how to build applications with OpenCV inside the Microsoft Visual Studio".
Compilation of my project fails with following errors (totally error count is greater than 800)
Error type 1
LNK2038 mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug'
doesn't match value 'MDd_DynamicDebug' in main.obj
\opencv_core320d.lib(alloc.obj)
Error type 2
LNK2005 "public: void __thiscall std::basic_ostream<char,struct
std::char_traits<char> >::_Osfx(void)" (?_Osfx#?$basic_ostream#DU?
$char_traits#D#std###std##QAEXXZ) already defined in
opencv_core320d.lib(system.obj) \msvcprtd.lib(MSVCP140D.dll)
Error type 3
LNK2001 unresolved external symbol _ippicviHSVToRGB_16u_C3R#24
\opencv_imgproc320d.lib(color.obj)
I believe it may be due to uncoordinated compilation options or erroneous configuration of my project, but because I am heavy Linux user I experience difficulties with setting up these things on Windows.
Update
After I have matched configuration shown in the screen below block of errors about code generation mismatch disappeared, but undefined references are still there.
Thank you for help!
To resolve "Error type 3" add *.lib files from "staticlib" dir to "Linker->Input->Additional Dependencies". For example "_ipp" symbols are defined in "ipp_iw.lib" and "ippicvmt.lib".
Just for info. I successfully built opencv from sources as a static and shared library (as opencv_world3**.lib) using MSVS 2012 and cmake 3.9.0. But also done that with MSVS 2017 community.
PS. Maybe a TYPO but you said that you use opencv 3.3.0 but in error messages there is opencv_core320d.lib
PPS. "Error type 1" is the result of using static debug runtime version in opencv_core (MTd) and dynamic debug runtime in your app (MDd)
I always have the same problems. This is why I have a property sheet ready for use.
The steps to follow for static compilation are:
Remember to Build the INSTALL project in the CMake generated Solution. Let's call $(OPENCV_DIR) the folder where the install happened (usually something like xxx\install). You can create an environment variable for this.
Add in front of [Configuration Properties]->[VC++ Directories]->[Include Directories] $(OPENCV_DIR)\include;. The semicolon is to separate paths.
Add in front of [Configuration Properties]->[VC++ Directories]->[Library Directories] $(OPENCV_DIR)\x86\vc15\staticlib;.
Match the runtime library linkage mode between OpenCV and your project. If you unselect BUILD_SHARED_LIBS by default the CRT is statically linked (/MT for Release or /MTd for Debug). If you want it dynamically linked deselect BUILD_WITH_STATIC_CRT. So, as you already realized, fix it in [Configuration Properties]->[C/C++]->[Code Generation]->[Runtime Library].
Copy all filenames matching *.lib (*d.lib for Debug) and add them in [Configuration Properties]->[Linker]->[Input]->[Additional Dependencies] separated by semicolons.
It's quite painful, so do it once in a Property Sheet and just include it when needed.

How to stop Linking error without changing Runtime Library?

Ok so I am new to C++ and I am trying to include libcURL. I have created a static library as opposed to using the DLL as I want to be able to reduce my programs dependencies by as much as possible.I have also set my Runtime Library in Visual Studio 2012 to MT and MTd as I understand this removes the need for redistributables to be installed?
Anyway, as soon as I add the line #define CURL_STATICLIB, MSVCR110.dll & LIBCMTD.lib clash with each other. I understand that this is because MSVCR110.dll is built with /MD and LIBCMTD.lib is built with /MT but I need to use the static library AND have the Runtime set to /MT
How can I fix the linking error without changing the Runtime Library? if thats no possible then How can fix this while keeping zero dependencies for my application?
Also, If the linking error only concerns MSVCR110.dll & LIBCMTD.lib, then why does it only occur when #define CURL_STATICLIB is set, and not all the time?
Thanks

Visual Studio C++ - Check the reason of link a specific library

vs report a error such as:
can not find xxx.lib
How do I check out why vs need to link xxx.lib? Is there a trace log? My project have not use boost.regex, but vs report a error says can not find regex.lib. So I want to find out which part of code refer to regex
LNK error: LIBCMT.lib: xxx was already defined in LIBCMTD.lib
How do I check why vs also link yyy.lib even this is a debug build? I have 2 projects, they link to same libs, all libs and project itself was /MTd. But one of them will report above error, I think it shouldn't link LIBCMT.lib because it is a release version lib, and another project is OK so the lib file was build correctly
VS can show the link trace?
1) Let's start with how the linker actually knows what to link with. Basically there are 2 categories:
Libraries specified in the project settings in the linker options as additional inputs
Libraries added in code with precompiler directive #pragma comment (generally the same thing as above but people have different tastes)
Otherwise you just get information about missing symbols but not the actual library they are from. What you can do to help is under visual studio linker options set Show Progress to For Libraries Searched (or just /VERBOSE:LIB linker flag), that will actually show you what dependencies are added after each lib is loaded, this also helps with point 2) to see which library loads which run-time.
2) Already mentioned in 1) that you can make the linker show library load progress, otherwise if a dynamic C run-time is used in the external library you are linking against you could use Dependency Walker to examine the dependencies of the library and find if the C run-time dll that is needed is debug or release by 'd' suffix in the dll name. If the library is already linked with static run-time then I guess only the linker errors will warn you. But I think that most serious libraries are correctly packed and structured so that you will be able to tell which files contain the debug version and which the release. If the library has only release version, well than that's another story. But i mean still, you can reconfigure the Debug configuration of your project to actually link against the release run-time to satisfy the external library, of course this prevents some debugging features, debug heap, etc.
For the missing boost regex library problem, I think the cause is due to boost's default autolink behaviour. If you include one of the headers of some of the boost libraries (not all of them, but regex is one of them), then these will cause Visual Studio to automatically link against the library. It uses a special pragma of the form:
#pragma comment(lib, "regex")
This has the effect of automatically adding a flag to the linker command. However, it's only picked up during compilation and so you won't see it in the project properties. In the case of boost, the solution to this is quite simple - find boost/config/user.hpp and uncomment the line
#define BOOST_ALL_NO_LIB
This will turn off the autolink behaviour for all libraries. Alternatively you can use #define BOOST_REGEX_NO_LIB to change this just for the regex library.
To solve the second problem, you need to find out which library is linking against the release build. Try selecting all projects in the solution and open Properties -> C++ -> Code Generation. You will probably find that the Runtime Library setting will be blank (because the option is different for some of the libraries. Force it to the correct threaded/single-threaded Debug option and rebuild.

Visual Studio .NET 2003 - Ignore Specific Library for libcmt vs libcmtd

I have a template VS .NET 2003 project, which colleagues copy and customise when developing their software.
It appears the template was altered a while back to set the IgnoreSpecificLibrary property to have libcmt.lib for both release and debug builds (i.e. for both release and debug, the build should ignore libcmt.lib in the linker).
Some projects based on this have since been built, with the release build pulling in libcmtd.lib (evident by looking through the project .map file) which appears to have caused some runtime issues (i.e. a dialog window being flashed up as though a breakpoint had been set).
Does setting IgnoreSpecificLibrary to exclude libcmt.lib automatically make the project link against libcmtd.lib?
What is weird is that building the template (with the incorrect setting) links against libcmt.lib whereas some of the customised projects (though not all) link against libcmtd.lib.
Any ideas?
This is what happened:
After compiling the linker takes your object-files and create among others
a symbol table ,which has symol-request that have not been fullfilled.
Then the linker goes through your list of libraries trying resolve those
unfullfilled symbols. Since you ignore libcmt.lib ,your third-party library
has left or added some unresolved symbols and it contains a linker request
to resolve those from licmtd.lib (and maybe other libs as well) ,since it
was compilled with debug option.
If you hadn't ignored libcmt.lib those symbols would most likely be resolved
by libcmt.lib and there was no need to pull in stuff from libcmtd.lib (even though
it would be looked at to resolve other symbols that were still unfullfilled)
You may try to igmore libcmtd.lib also. If you now get unresolvd externals then
it was probebly no a good idea to ignore libcmt.dll.
Many projects ignore the libcmt.lib, because it conflicts with the dynamic version msvcrt.lib.
Ignoring libcmt in the linker make the project compile with msvcrt.lib