MinGW unresolved reference when linking with Visual Studio generated static library - visual-studio

Using gcc 4.5.0 under MinGW, I am trying to build a Windows console executable which links to a static library created with Visual Studio. The static library seems to have dependencies on Visual studio symbols which aren't available under MinGW. Error messages:
undefined reference to `_ftol2_sse'
undefined reference to `_allmul'
Is there a replacement for these functions under MinGW or can this by fixed by setting an additional linker flag?

You will have to explicitly link with the right version of the MSVC runtime. GCC defaults to a different version.

Related

How to get rid of boost library exports in final executable

I'm compiling an executable and I use boost libraries inside that executable.
no matter if i use static linking or dynami linking of boost with "BOOST_ALL_DYN_LINK" , my final executable contains exports from the boost library.
which is very undesirable.
Update: My compiler is Visual studio 2019 and I'm compiling for x86 platform. however it's the same for x64 as well.

linking boost on Windows asks for versioned lib

We have a large cmake based C++ project for Linux where we build boost ourselves via cmake exernal project.
The project used to build also on Windows for the classical Intel compiler. But I have no access to this old running configuration.
I use Intel oneAPI 2023.0 with LLVM based icx compiler (clang 15?) and a current MSVC community edition.
I built boost (1.81.0) without a target (as I still struggle with openAPI target) with --layout=system, hence lib names like libboost_atomic.a
In our C++ we do not let CMake search for boost but add the boost libs via target_link_libraries().
When I compile our application with icx I get a link error
Linking CXX executable ....\bin\cfs.exe LINK: command
"C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin\icx.exe /nologo
#CMakeFiles\cfs.dir\objects1 /Qoption,link, /machine:x64
/INCREMENTAL:NO /Qoption,link,/subsystem:console -Qiopenmp
/Qoption,link,/LIBPATH:C:\PROGRA~2\Intel\oneAPI\compile
r\latest\windows\bin\intel64\ifort.exe
/Qoption,link,/LIBPATH:C:\Users\fabia\code\master\release_icx\lib
[....] ....\lib\libboost_log_setup.lib
....\lib\libboost_serialization.lib [.....] /link
/out:....\bin\cfs.exe /implib:. ...\bin\cfs.lib
/pdb:C:\Users\fabia\code\master\release_icx\bin\cfs.pdb /version:0.0
/MANIFEST /MANIFESTFILE:....\bin\cfs.exe .manifest"
I get
fatal error LNK1104: file
"libboost_serialization-clangw16-mt-x64-1_81.lib" not found.
I have no idea where the string clangw16-mt-x64-1_81 comes from.
You can link the libraries present in the boost library path to your project either from the Command Prompt or within the Visual Studio IDE. Please refer to the below link for more details.
https://www.boost.org/doc/libs/1_81_0/more/getting_started/windows.html
If you do not find any binaries, you can add the macro BOOST_ALL_NO_LIB which tells the config system not to automatically select which libraries to link. Please refer to the below link for more details.
https://www.boost.org/doc/libs/1_81_0/libs/config/doc/html/index.html
Or
You can use the target Boost::disable_autolinking to disable automatic linking. Please refer to the below link for more details.
https://cmake.org/cmake/help/latest/module/FindBoost.html

install wxWidget as static library by Vcpkg

I'm using Visual studio 2019
I followed this link to install wxWidget using vcpkg install wxwidgets
https://www.wxwidgets.org/blog/2019/01/wxwidgets-and-vcpkg/
and read this link
https://computingonplains.wordpress.com/using-visual-studio-2017-to-build-wxwidgets/
and this
https://devblogs.microsoft.com/cppblog/vcpkg-updates-static-linking-is-now-available/
the problem after installing wxWidget using vcpkg the result build is Dynamic library and I want to compile my project as static library to run exe file on other users pc .
I want to change from Dynamic lib compilation to static due to :
users on another PCs get VCRUNTIME error so they have to install VC++ runtime library as I read in
How to fix a missing vcruntime140 clr 400 dll error
Summary of the problem :
vcpkg installation wxwidgets result is dynamic lib configuration and I need to install static one .
Instead of just doing vcpkg install wxwidgets
use vcpkg install wxwidgets:x64-windows-static
This will install wxwidgets and all it dependencies with static runtime and library linkage.
You can also define your custom triplet if you want to customize your build setup (see https://github.com/microsoft/vcpkg/blob/master/docs/users/triplets.md)
#MohmmedAlaa,
You are better off compiling the library yourself.
There is a big difference between compiling the project with wxWidgets being dynamic vs static and VC++ RT dynamic vs static.
Also, keep in mind that some VC++ RT is not licensed to be distributable.
So all in all - get the wxWidgets sources, install MSVC, build static libraries (possibly with the compiler switch to use "static RT) and compile your software.

Compiling FFMpeg libraries for Visual Studio

I'm trying to use the FFMpeg libraries in a Windows application. I use MingW-w64 to compile FFMpeg with static libraries with architecture once with x86 and once with x86_64.
Currently I'm trying to link the 32bit x86 libraries with my VS2008 application.
The libraries are added to the library path and VS does not complain about being unable to load a .a file.
However I get several uneresolved symbol errors like
ait_rtp_receiver.lib(ait_decoder_lib.obj) : error LNK2001: unresolved external symbol _av_free
I import the FFMpeg header files as extern C and I can see the symbols in the .a without the leading underscore.
What can I do to make the name decoration of Mingw-w64's gcc and of the VS compiler suite compatible?
After spending miserable days trying to get the GCC-Mingw based version of building FFMpeg to work, I reverted to using the Visual Studio or Windows SDK compiler and linker. Using the --toolchain=msvc of the configure script made the build process generate static .a files that are basically .lib files that can be loaded within Visual Studio projects.
I wrote the build steps up and here is a link

Link problems on Release x64

I have a Visual Studio 2010 C++ project that links statically to tinyxmlSTL 2.5.5 (tinyxmlSTL.lib) and zlib 1.2.7. (zlibstat.lib). There are 4 builds in total covering both x86 and x64 as well as Debug and Release.
All combinations produce working builds except for Release x64 which gets a bunch of errors like this:
MSVCRT.lib(MSVCR100.dll) : error LNK2005: free already defined in LIBCMT.lib(free.obj)
...and a single warning:
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
If I add /NODEFAULTLIB:MSVCRT to linker options for the application then I get this:
zlibstat.lib(ioapi.obj) : error LNK2001: unresolved external symbol __imp__ftelli64
zlibstat.lib(ioapi.obj) : error LNK2001: unresolved external symbol __imp__fseeki64
Basically, all the projects (app and two libs) are set to use Multi-threaded (/MT) option in Release builds and yet x86 builds just fine while x64 suffers from above issues.
Any help or idea is highly appreciated.
You need to double check your settings for x64. One of the projects is using the /MD flag rather than /MT.
As per the MSVC docs, The MSVCRT.lib is invoked by using /MD.
EDIT :
As per your comments, it sounds like zlib is the likely culprit.
zlib has both a static and dll version, but both of these use the /MD flag by default, so unless you changed that while building zlib - that's your issue.
To build zlib using /MT:
If you've not already done so, install CMake
Download and extract zlib to e.g. C:\devel. The download links are about halfway down the homepage. Currently this provides zlib version 1.2.7.
To work around this CMake bug, add
if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND MSVC)
set_target_properties(zlibstatic PROPERTIES STATIC_LIBRARY_FLAGS "/machine:x64")
endif()
to the end of C:\devel\zlib-1.2.7\CMakeLists.txt
In a VS10 command prompt, cd C:\devel\zlib-1.2.7
cmake -H. -Bbuild -G"Visual Studio 10 Win64"
This gets you a VS sloution C:\devel\zlib-1.2.7\build\zlib.sln which you can open. Change the settings for the "zlibstatic" target to /MT and /MTd for Release and Debug respectively.
Building each will yield zlibstatic.lib in a subdirectory of build; either "Release" or "Debug".
In the project properties for ALL projects, check that they all use the same runtime type: either DLL or static
This can be found under Project Properties -> C/C++ -> Code Generation -> Runtime Library. Make sure you have the Release x64 build selected.
The particular value isn't very important (in terms of compile errors) but they should all be the same
I know you say that all your libs are linking with /MT but that error suggests that one of them isn't. Re-check that the correct libs are being linked with the x64 Release build.

Resources