Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classes and methods aren't exported to dll library when building vmime on Windows #214

Open
honza-c opened this issue Apr 17, 2019 · 0 comments

Comments

@honza-c
Copy link

honza-c commented Apr 17, 2019

Hello,
I'm trying to build the vmime library on Windows 10 64bit and then use the built library in a Visual Studio 2017 project. The problem is that classes and methods from the library aren't exported to the dll file, so compiler (both Visual Studio and g++) can't find them in the dll file when I build my program and the build fails. I tried to build vmime library in Visual Studio 2017 64bit and in MINGW / MSYS environments in both last stable 0.9.2 version and in the newest revision from master branch in git, the results are same. Visual Studio generates tons of C4251 warnings like this one:

Warning C4251 'vmime::generationContext::m_epilogText': class 'std::basic_string<char,std::char_traits,std::allocator>' 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 __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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant