pthread static linking with application in visual studio 2013 - visual-studio

I want to pthread lib statically linked with my application so that at other target without install pthread lib my .exe will run.
For that I have add pthreadVC.lib in Linker->input->additional dependency of visual studio and also given correct path for lib.
Also I add this code #define PTW32_STATIC_LIB in my thread.h file before #include <pthread.h>
My application build successfully and running on same machine. But I trying to run on other target I got error pthreadVC.dll is missing .
Please tell me where I am missing.

In my case i was not having static lib and i was trying to do static link with dynamic lib. Following are steps to do static linking .
Download source code of Pthread_Win32 and build it with visual studio.
So now you will have static lib (pthread_lib.lib) probably at path .........\pthread-win32-master\pthread-win32-master\bin\Win32_MSVC2013.Release
In your application go into project properties mainly
Linker->input->additional dependency and add pthread_lib.lib.
Also add path of pthread_lib.lib into visual studio properties Linker->General->Additional Library Directories.
Add this code #define PTW32_STATIC_LIB in header file.

Related

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.

VC++ dependencies linking issue?

My project is using some libs of libavcodec on Visual Studio 2010.
After updating the libs (replacing the lib and includes from Libav) and resolving all Compiler Errors (after 3 years a few things changed in libavcodec), the project compiles without a problem, but my compiled dll does not work.
I am 99% sure it is some dependency problem. Sure i did not only update the linked libs of my project but also placed the correct new dlls into the build folder.
The strange thing i have never seen is that dependency walker detects totally wrong imports from the different dlls, see image.
As you can see, all linked libs seem to indicate the same imports - functions that those libs just don't export.
The only thing i do in that direction besides specifying the libs in the linker section is including the .h files in my program and then of course use them heavily;-)
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavutil/opt.h>
#include <libavutil/imgutils.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libswresample\swresample.h>
}
What i tried:
Make sure the correct libs and headers are used by the project
clean the build path, tried debug und release build
checked if there are new includes that i may have forgotten to link (this would have ended up in a compiler errror anyways)
restart VStudio
built a test program that links to the same dlls, there the correct imports are shown automatically
compiled with VS 2013, no change at all
Custom building binaries depending upon your current project settings is key to avoiding annoying linker errors like the one your are facing.
You can use vcpkg.exe from github to build the ffmpeg project and rebuild binaries for x86 or x64 machine.
After installing vcpkg on your system, goto to the Powershell prompt and enter .\vcpkg install ffmpeg. After completion of installation enter ".\vcpkg integrate install" so that your latest ffmpeg libraries are available for use.

Boost VS2017 linking to the wrong DLL

I have a CMake file which does this:
find_package(Boost COMPONENTS system filesystem)
add_library(MyModule MODULE main.cpp)
target_include_directories(MyModule PUBLIC ${Boost_INCLUDE_DIRS})
target_link_libraries(MyModule Boost::system Boost::filesystem)
I'm using VS 2017 as my generator. When I generate the project file with cmake, it finds boost_system-vc141-mt-1_63.lib and I can see that it is in the linking rules of the vcxproj. However, when I try to compile I get this error:
LINK : fatal error LNK1104: cannot open file 'libboost_system-vc140-mt-1_63.lib
Note the different generators (vc140 vs vc141). I know my compiler has output the right values because I built boost from source, so I tried to just rename vc141 to vc140, but the error stayed the same. I also confirmed that vc140 is not referenced in the project file.
What's going on? How can I force boost to link to the correct version?
When building with Visual Studio, boost has some pragma statements which do the linking for you. This is called "Auto-linking" and it over-rides any command-line arguments you may be passing to the linker.
The solution is to define BOOST_ALL_NO_LIB. This can be done in two ways:
In source code before including boost headers as #define BOOST_ALL_NO_LIB.
It could be added to your cmake file as: add_definitions("-DBOOST_ALL_NO_LIB").
As of CMake 3.5: Use the disable_autolinking imported target:
target_link_libraries(MyModule Boost::system Boost::filesystem Boost::disable_autolinking)

boost library 1.47.1 build 'lib' prefix causing LNK1104 error

I'm having difficulties generating the correct boost .lib file to compile with a VS project I've been given. It appears that after performing the complete build installation using 'b2.exe' from VS2010 command prompt I'm only able to generate the boost library files that contain the 'lib' prefix.
When I come to compile my project I'm getting the following error message:
"error LNK1104: cannot open file 'boost_signals-vc90-mt-1_47.lib'"
After going through the lib folder I can see that my boost build has only generated 'libboost_signals-vc90-mt-1_47.lib'
The boost documentation gives the following information about the lib prefix:
lib
Prefix: except on Microsoft Windows, every Boost library name begins with this string. On Windows, only ordinary static libraries use the lib prefix; import libraries and DLLs do not.
So far I've attempted the following build options for the msvc-9.0 toolset:
'build-type=complete'
'link=static,shared'
Any advice on how I may be able to generate the required .lib file would be greatly appreciated.
Many Thanks.
link=static should be used whenever you're linking to static version of boost library.
link=shared - should be used whenever you're linking dynamically to boost. It will add extra dependencies on boost dll's.
You can also use link=static,shared to build both versions - static and dynamic.
Define 'BOOST_ALL_DYN_LINK' in project controls how you link to boost.
If it's defined - it's dynamic linking, if not defined - it's static linking.

Compiling FreeType to DLL (as opposed to static library)

I want to use FreeType in a c# project. I found this binding, but I still need a freetype.dll. I usually use a static library in my c++ projects, so I never compiled one. Opening the freetype-solution (VS2010) I noticed that there is no configuration for a dynamic library - just static ones. I tried to make my own configuration and got it to generate a freetype.dll. If I use it with the c#-binding I get an exception, that the FT_Init_FreeType-entry point was not found. Any idea how I must adjust the freetype-project in order to export those functions?
If you're ok with an old version (march 2008), you can go to FreeType for Windows page, download the latest Binaries package, open the .ZIP, and extract FreeType6.dll from the bin directory. Just rename it appropriately.
If you need a more recent version, here is how you can compile the latest:
download the latest source (2.4.6 as of today) from http://sourceforge.net/projects/freetype/files/freetype2/
open Visual Studio 2010, and load freetype.sln from the builds\win32\vc2010 directory.
open the project config, and in the General tab, change Configuration Type to Dynamic Library (.dll)
open the ftoption.h file, and add these lines (near the "DLL export compilation" remarks section for example):
#define FT_EXPORT(x) __declspec(dllexport) x
#define FT_BASE(x) __declspec(dllexport) x
change the project compilation configuration to "Release".
compile the project. You should now have a freetype246.dll in the objs\win32\vc2010 directory.
I'm going to bet that the problem is that your DLL project does not export any symbols, so while all the code is in there the addresses of the symbols are not in the exports table so nobody can get to them from the outside.
This question has a nice solution to export all the symbols in a .dll without having to manually list them.
The future here. This is to future readers of this thread.
FT2 supports creating a static and dynamic library. They have solutions premade and can be found in the builds directory.
If you are forced to use CMAKE, you will have to do what the accepted answer does. However, it is no longer current. I was not able to find said file which references dll (near the "DLL export compilation" remarks section for example):. It is now located at freetype-x.x.x\include\freetype\config\ftconfig.h around line 424. I am using MSVS 2017, so try to follow along.
mkdir build
cd build
cmake -G "Visual Studio 15 2017 Win64" ..
Open freetype-x.x.x\include\freetype\config\ftconfig.h and around line 424, patch the __declspec(dllexport)'s in:
...
/* You can provide your own implementation of `FT_EXPORT` and */
/* `FT_EXPORT_DEF` here if you want. */
/* */
/* To export a variable, use `FT_EXPORT_VAR`. */
/* */
// This is due to FT_EXPORT and FT_BASE not generating a .lib file, just a .dll
#ifdef FT_EXPORT
#undef FT_EXPORT
#define FT_EXPORT(x) __declspec(dllexport) x
#endif
#ifdef FT_BASE
#undef FT_BASE
#define FT_BASE(x) __declspec(dllexport) x
#endif
#ifndef FT_EXPORT
...
Open the solution generated by CMAKE called freetype.sln . Select freetype in the Class View. Project -> Properties -> General -> Target Extension -> set to .dll and under Project Defaults -> Configuration Type -> set to Dynamic Library (.dll)
Make sure Release is select and Build -> Build freetype. In the 'build' directory that has the solutions, in Release you will have your freetype.dll and freetype.lib files for use. You will need those and all of freetype-.x.x.x\include.
Good luck :)

Resources