I am trying to build tensorflow as a standalone project and have been following this tutorial
http://www.stefanseibert.com/2017/10/tensorflow-as-dll-into-your-windows-c-project-with-gpu-support-and-cmake-v1-3/
but alternatively with cpu support
My environment setup versions
protobuf 3.6.1
tensorflow 1.10.0
tf.GIT_VERSION = b'v1.10.0-rc1-19-g656e7a2b34'
Here are the steps I used to generate the shared lib
Acquired source code from https://github.com/tensorflow/tensorflow.git
Have installed the dependencies since I do not use the python bindings, there is no need for SWIG, so I installed Git (version 2.15.1.windows.2) and cmake 3.11.1
I used the 64bit tools from Visual Studio 2015 since VS2015 is necessary to build the DLL. I should be able to open the “VS2015 x64 Native Tools Command Prompt”. This is needed so VS uses the 64 bit toolset.
Navigated in the commandline to the “tensorflow/contrib/cmake” subfolder of the source code and create a directory with “mkdir build”. Afterwards navigate to the fresh build folder with “cd build”.
Create a build solution: cmake .. -A x64 -DCMAKE_BUILD_TYPE=RelWithDebInfo -Dtensorflow_BUILD_CC_EXAMPLE=OFF -Dtensorflow_ENABLE_GRPC_SUPPORT=OFF -Dtensorflow_BUILD_CC_TESTS=OFF -Dtensorflow_BUILD_PYTHON_TESTS=OFF -Dtensorflow_ENABLE_GPU=OFF -Dtensorflow_WIN_CPU_SIMD_OPTIONS=/arch:AVX -Dtensorflow_BUILD_SHARED_LIB=ON
Everything went fine till this. To build the tensorflow.dll, I issued the following command: MSBuild /p:Configuration=RelWithDebInfo tensorflow.vcxproj
This throws an error: D:\work\tensorflow\tensorflow/core/lib/core/stringpiece.h(34): fatal error C1083: Cannot open include file: 'absl/strings/string_view.h': No such file or directory (
compiling source file D:\work\tensorflow\tensorflow\core\lib\core\coding.cc) [D:\work\tensorflow\tensorflow\contrib\cmake\build\tf_core_lib.vcxproj].
I fixed the above error with this: https://github.com/tensorflow/tensorflow/issues/22007#issuecomment-424553600.
Doing the above I ended up with this error: path.obj : error LNK2019: unresolved external symbol "void __cdecl absl::base_internal::ThrowStdOutOfRange(char const *)" (?ThrowStdOutOfRange#base_internal#absl##YA
XPEBD#Z) referenced in function "class std::basic_string,class std::allocator > __cdecl tensorflow::io::internal::JoinPathIm
I am not able to proceed further. Any workaround for this? Thanks!
lnk2019 error occurs when your directly you are using in your source code are not linked properly. Please add additional dependencies to your project.
Going to project properties
select C/C++ option
Add aditional dependencies
Go to Linker Option Below C/C++
Add additional Dependencies here.
It might be help full for you from getting out to LNK2019 problem
view this to understand LNK2019 error.
I met same issue, I think tensorflow new version doesn't support CMake, but we can solve the issues.
1. Seems the absl version in project folder is out dated, so I cloned the latest version of abseil-cpp from: https://github.com/abseil/abseil-cpp
2. Use cmake to build the abseil-cpp, it will be fast.
3. Add lib path to tensorflow dependency, the needed one will be D:\git\abseil-cpp\abseil-cpp\build\absl\base\Release\absl_absl_throw_delegate.lib
4. If you meet other linking error, you can find the function name in absl sources and find the library contain it.
Hope this can help you and people who may met this issue in future.
Related
To the best of my knowledge, this isn't a duplicate of an existing question. This question is specifically about Visual Studio's auto-linking SDL2 libraries.
I've installed SDL2 (x64-windows variant) with vcpkg:
vcpkg install sdl2 --triplet x64-windows
And I've made vpkg libraries available to Visual Studio:
vcpkg integrate install
My VS 2019 project is configured to use the Console subsystem, and my main program looks like that:
#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
int main(int, char*[])
{
}
Why do I need to specify SDL_MAIN_HANDLED? It seems that auto-linking with SDLmain2.lib doesn't happen for some reason?
If I don't specify SDL_MAIN_HANDLED, linking fails:
unresolved external symbol main referenced in function "int __cdecl invoke_main(void)" (?invoke_main##YAHXZ)
I've also tried adding extern "C" on main() declaration but to no avail.
I've written many apps with SDL2 but this is the first time I'm using vcpkg to locate it.
It appears to be a deliberate decision made by those who created the package.
If you look at the package description file, you can see that SDL2main.lib is being moved into the manual-link directory. I'm not familiar with vcpkg, so I don't know how exactly you can "manually link" against it, but I assume it's possible.
Linking SDL2 manual-link libraries while using vcpkg with VS
My answer is a follow-up to #HolyBlackCat, thanks for help.
In your case, the directory is x64-windows, by default it is x86-windows.
Right-click on your project -> Properties -> Configuration Properties
First step
Go to: VC++ Directories -> Library Directories
For Debug configuration, add:
$(VCPKG_ROOT)\installed\x64-windows\debug\lib\manual-link
For Release configuration, add:
$(VCPKG_ROOT)\installed\x64-windows\lib\manual-link
Second step
Go to: Linker -> Input -> Additional Dependencies
For Debug configuration, add:
SDL2maind.lib
For Release configuration, add:
SDL2main.lib
Now you should not be bother by "main() redefinition" errors.
I have been trying to build a cmake c++ project. More specifically I am trying to use the gdal library in this project. In the CMakeLists.txt it says find_library(GDAL gdal) after doing some research i found, that visual studio can open cmake files by default as mention in this thread: https://learn.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=vs-2019.
Moreover, visual studio should also automatically include the gdal library once i have set it up with vcpkg correctly. I've already downloaded the x64-windows version of the library (vcpkg install gdal:x64-windows) in order to build for the right architecture and made it available via vcpkg integrate install on a user-wide scope.
After some trial and error, everything works fine now, the toolchain gets included accordingly and the library is found automatically, resulting in a configuration like that:
However, when trying to include the header files (or anything else; see code snippet), visual studio does not seem to link the library correctly as it will result in the error message: cannot open source file "gdal/gdal.h".
#include <gdal/ogrsf_frmts.h>
#include <gdal/gdal.h>
#include <gdal>
Where should I further investigate?
As others have said vcpkg integrate install and vcpkg.cmake don't work together the reason being:
set_target_properties(${name} PROPERTIES VS_USER_PROPS do_not_import_user.props)
set_target_properties(${name} PROPERTIES VS_GLOBAL_VcpkgEnabled false)
this deactivates the integration. The reason to deactivate the integration is so that you don't write an incomplete CMakeLists.txt (e.g. missing the include directory or not linking all required libraries).
As such replace find_library(GDAL gdal) with find_package(GDAL REQUIRED) and target_link_libraries against the target GDAL::GDAL (https://cmake.org/cmake/help/v3.17/module/FindGDAL.html)
#include "pch.h"
#include <iostream>
#include <openssl\ssl.h>
#include <openssl\err.h>
#include <openssl\conf.h>
int main()
{
SSL_library_init();
SSL_load_error_strings();
}
OpenSSL DLL Throws some errors
Getting the following error after built openssl in vs2017
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol _OPENSSL_init_ssl referenced in function _main
For OpenSSL 1.0, building a program on Windows require linking with libeay32.lib and ssleay32.lib. You can find these libraries in the out32dll or out32 folder of your OpenSSL folder depending on how you built it. OpenSSL 1.1 might have a different lib name for these libraries.
Also, if you built these libraries as DLLs, you need to copy over libeay32.dll and ssleay32.dll into the same folder as your EXE or have them in your PATH in order for the program to run.
Source : Building libcurl with SSL support on Windows
Thanks Mr. https://stackoverflow.com/users/519376/vtellier
I have followed the following instructions with slight modifications and it worked fine for VS2017 with latest OpenSSL
In my case follow the curl README file was enough.
My configuration is the following:
Visual Studio 2017
Static library
Win64
curl version 7.57.0
OpenSSL 1.0.2
Compilation of libCurl
Download libcurl source there: https://curl.haxx.se/download.html
compress the file and go to the folder curl-7.57.0\projects
Open the README file and follow the instructions, this lead me to do the following:
Downloaded OpenSSL
Extract it and rename it to openssl, put it aside the curl folder, this is important as you'll open the VS project that expect
to find openssl there.
Install Perl
Execute the utility build-openssl.bat to perform the compilation of openSSL. With my settings this became the following:
\build-openssl.bat vc14 x64 release ....\openssl\
just runs .\build-openssl.bat -help to know more about the parameters.
After that you can see OpenSSL has been compiled as you got a new folder here: openssl\build\Win64
Open the Visual Studio project
curl-7.57.0\projects\Windows\VC14\curl-all.sln
Be sure to set the visual studio project to the build configuration
you need (LIB Release - LIB OpenSSL in my case)
Build all . The library is located at
curl-7.57.0\build\Win64\VC14\LIB Release - L
I have downloaded the latest release version of Openssl from http://www.openssl.org/source/
I would like to use it in Visual Studio 2012, especially getting the md5/sha-1 hash of a file, but I can not include / setup the environment with the openssl library. To be honest I got confused what to include, and where, however I have read the README-s.
I'm getting this error.
Error 1 error LNK2019: unresolved external symbol _MD5_Init referenced in function _main
So my question is, I have downloaded the latest release (openssl-1.0.1e.tar.gz), what should I config in VS2012 to be able to use the lib? Thanks!
UPDATE
This question helped me also in finding the solution. Boost SSL with Visual Studio 2010 and OpenSSL
The steps required to use the openSSL lib with VS2012:
download and install a version (I have 64bit OS, however I installed 32bit openssl) from http://slproweb.com/products/Win32OpenSSL.html.
New project in VS, then Configuration Properties/C/C++/General/Additional Include Directories: openssl include folder (C:\OpenSSL-Win32\include)
Linker/General/Additional Library Directiories: C:\OpenSSL-Win32\lib
Linker/Input/Additional Dependencies :
libeay32.lib libeay32MTd.lib libeay32MT.lib libeay32MDd.lib
libeay32MD.lib ssleay32.lib ssleay32MTd.lib ssleay32MT.lib
ssleay32MDd.lib ssleay32MD.lib
(It was written that I need to only add that one which matches with C/C++/Code Generation/Runtime Library, but It works me this way.)
Copy theese files into current VS folder /VC/lib
What compiler did you use to compile OpenSSL? Did you use MinGW? If so, make sure you don't strip them (or just with --strip-unneeded) otherwise import symbols will be stripped. Do the header and lib version match?
Maybe you want to try pre built ones from: http://slproweb.com/products/Win32OpenSSL.html those work for sure.
I'm developing a native C++ application using Qt 4.8.3 and VS2008. Since clients run the application on their naked machines, they need to install VC++ 2008 Redistribution package. So I decided to make it statically linked.
I changed my project settings (C/C++ > Code Generation > Runtime Library) to /MTd. Also
I compiled Qt again, this time using following commands for a static building; originally found on this blog Static Qt with static CRT (VS 2008)
1- replaced -MD with -MT in lines QMAKE_CFLAGS_RELEASE and QMAKE_CFLAGS_DEBUG in %QDIR%\mkspecs\win32-msvc2008\qmake.conf
2- nmake confclean
3- configure -static -platform win32-msvc2008 -no-webkit
4- nmake sub-src
I compiled Qt successfully. But when I tried again to compile my application, it gave me some strange errors.
1>Linking...
1>qtmaind.lib(qtmain_win.obj) : error LNK2005: "public: bool __thiscall QBasicAtomicInt::deref(void)" (?deref#QBasicAtomicInt##QAE_NXZ) already defined in QtCored4.lib(QtCored4.dll)
1>qtmaind.lib(qtmain_win.obj) : error LNK2005: "public: bool __thiscall QBasicAtomicInt::operator!=(int)const " (??9QBasicAtomicInt##QBE_NH#Z) already defined in QtCored4.lib(QtCored4.dll)
1>qtmaind.lib(qtmain_win.obj) : error LNK2005: "public: __thiscall QString::~QString(void)" (??1QString##QAE#XZ) already defined in QtCored4.lib(QtCored4.dll)
I changed some lib files but with each change, situation got worse; for example I tried to use QtCored.lib instead of QtCored4.lib because it is newly created after compilation.
I think I've missed something in building static Qt libs.
Although this question has remained unanswered since late 2012, I thought it might be a good idea to further populate the general knowledge on this issue in order for each thread to display at least one response.
The problem stems from the inclusion of the QtCored4.dll and QtGuid4.dll during the link process when building Qt statically. To exclude these from the build process, simply add QT_NODLL as a preprocessor directive when configuring Makefile. For instance, this may be achieved using the following command (for Microsoft Visual Studio 2008):
configure -static -debug -D QT_NODLL -platform win32-msvc2008
prior to running NMAKE.
A good practice when building static Qt applications using the Visual Studio IDE is to modify the project configuration type to Makefile using the Configuration Properties->General->Configuration Type drop-down menu. Once these settings have been applied, the user may also specify qmake and nmake steps to perform for Build and Rebuild All options under Configuration Properties->General->NMake.
For instance the build command-line for static debug configuration would be:
nmake debug
And the rebuild-all equivalent:
qmake app_debug.pro && nmake debug
I hope this helps!