Warning C4251 'vmime::generationContext::m_epilogText': class 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' needs to have dll-interface to be used by clients of class 'vmime::generationContext' C:\Users\jan\CMakeBuilds\dcecb192-0e0d-463e-864d-109e2007f045\build\x64-Release\vmime.vcxproj c:\users\jan\vmime\src\vmime\generationcontext.hpp 161
The code of a small program I compile in g++ and in Visual Studio is:
#include <iostream>
#include <vmime/vmime.hpp>
int main()
{
vmime::string str("hello world"); // works
std::cout << str; // works
vmime::shared_ptr<vmime::net::session> session = vmime::net::session::create(); // build fails
}
The output from Visual Studio compiler is:
Error LNK2001 unresolved external symbol "__declspec(dllimport) public: static class std::shared_ptr<class vmime::net::session> __cdecl vmime::net::session::create(void)" (__imp_?create@session@net@vmime@@SA?AV?$shared_ptr@Vsession@net@vmime@@@std@@XZ) ConsoleApplication1 C:\Users\jan\source\repos\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.obj 1
Severity Code Description Project File Line Suppression State
Error LNK1120 1 unresolved externals ConsoleApplication1 C:\Users\jan\source\repos\ConsoleApplication1\x64\Release\ConsoleApplication1.exe 1
In Visual Studio, I imported the vmime's cmake project. Visual Studio then generates CMakeSettings.json file in which is the build configuration stored. Content of my configuration file:
{
"configurations": [
{
"name": "x64-Release",
"generator": "Visual Studio 15 2017 Win64",
"configurationType": "RelWithDebInfo",
"inheritEnvironments": [
"msvc_x64_x64"
],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install -DGNUTLS_INCLUDE_DIR=${env.USERPROFILE}\\pathTo\\gnutls\\lib\\includes -DGNUTLS_LIBRARY=${env.USERPROFILE}\\pathTo\\gnutls\\lib\\libgnutls.dll.a -DGSASL_INCLUDE_DIR=${env.USERPROFILE}\\pathTo\\libgsasl-1.8.0\\src\\dist\\include -DGSASL_LIBRARIES=${env.USERPROFILE}\\pathTo\\libgsasl-1.8.0\\build\\src\\.libs\\libgsasl.dll.a -DPKG_CONFIG_EXECUTABLE=${env.USERPROFILE}\\pathTo\\pkg-config\\windows_64\\bin\\pkg-config.exe -DVMIME_CHARSETCONV_LIB=win -DVMIME_BUILD_DOCUMENTATION=OFF -DVMIME_BUILD_SAMPLES=OFF -DVMIME_BUILD_TESTS=OFF -DVMIME_HAVE_MLANG_H=OFF -DVMIME_HAVE_MLANG_LIB=OFF -DVMIME_HAVE_MESSAGING_PROTO_SENDMAIL=OFF -DVMIME_SHARED_PTR_USE_BOOST=OFF -DVMIME_SHARED_PTR_USE_CXX=ON -DVMIME_BUILD_STATIC_LIBRARY=ON -DVMIME_BUILD_SHARED_LIBRARY=ON",
"buildCommandArgs": "",
"ctestCommandArgs": ""
}
]
}
In MINGW / MSYS environment, I built the vmime library with following commands in bash:
cmake .. -G "MinGW Makefiles" -DCMAKE_CXX_COMPILER=/C/mingw/mingw64/bin/g++.exe -DCMAKE_C_COMPILER=/C/mingw/mingw64/bin/gcc.exe \
-DCMAKE_MAKE_PROGRAM=/C/mingw/mingw64/bin/mingw32-make.exe -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/path/to/vmime-0.9.2/install \
-DGNUTLS_INCLUDE_DIR=/path/to/gnutls/windows_64/include -DGNUTLS_LIBRARY=/path/to/gnutls/windows_64/lib64/libgnutls.dll.a \
-DGSASL_INCLUDE_DIR=/path/to/libgsasl-1.8.0/src/dist/include -DGSASL_LIBRARIES=/path/to/libgsasl-1.8.0/build/src/.libs/libgsasl.dll.a \
-DICONV_INCLUDE_DIR=/path/to/iconv/windows_64/include -DICONV_LIBRARIES=/path/to/iconv/windows_64/lib64/libiconv.dll.a \
-DPKG_CONFIG_EXECUTABLE=/path/to/pkg-config/windows_64/bin/pkg-config.exe -DVMIME_CHARSETCONV_LIB=iconv \
-DVMIME_BUILD_DOCUMENTATION=OFF -DVMIME_BUILD_SAMPLES=OFF -DVMIME_BUILD_TESTS=OFF \
-DVMIME_HAVE_MLANG_H=OFF -DVMIME_HAVE_MLANG_LIB=OFF -DVMIME_HAVE_MESSAGING_PROTO_SENDMAIL=OFF \
-DVMIME_SHARED_PTR_USE_BOOST=OFF -DVMIME_SHARED_PTR_USE_CXX=ON
Do I miss any argument to cmake? Is there any easy way how to make the classes exported? I would like to avoid manually hacking all the files of the vmime sources. I need to say that the part of the documentation that refers to building the library is poor. The guide of how to build the library correctly on Windows is missing at all, and when I look to cmake arguments I used above, more half of them aren't documented in the Vmime book. I found them all over the Internet when I searched for more info about the library in threads where other people discussed their problems with building.
Thank you for any help.