Unable to compile a plugin library in VS2017

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
srini2174
Earned a small fee
Earned a small fee
Posts: 15
Joined: Wed Nov 11, 2015 7:59 am

Unable to compile a plugin library in VS2017

Post by srini2174 »

Hi,
I am trying to build a small plugin demo as a shared library using cmake. I get the following link error in the build process. I have used wxWidgets compiled from source (downloaded from github) using Visual Studio 2017 on a windows 10 machine. The "minimal" sample application and other demo application compile fine.

Thanks in advance for any help in resolving this issue.

Code: Select all

Execute cmake with arguments: --build,c:/users/venkybal/vscode-workspaces/wxmodular2/build,--target,all,--config,Debug,--,-j,6
[vscode] Executing command: C:\ProgramFiles\CMake\bin\cmake.exe --build c:/users/venkybal/vscode-workspaces/wxmodular2/build --target all --config Debug -- -j 6
[1/2  50%] Building CXX object modules\wxNonGuiPluginBase\src\CMakeFiles\wxNonGuiPluginBase.dir\wxNonGuiPluginBase.cpp.obj
C:\Users\venkybal\VSCode-Workspaces\wxModular2\modules\wxNonGuiPluginBase\include\wxModular1/wxNonGuiPluginBase.h(7): warning C4275: non dll-interface class 'wxObject' used as base for dll-interface class 'wxNonGuiPluginBase'
C:\ProgramFiles\wxWidgets\vc15_x64\include\wx/log.h(50): note: see declaration of 'wxObject'
C:\Users\venkybal\VSCode-Workspaces\wxModular2\modules\wxNonGuiPluginBase\include\wxModular1/wxNonGuiPluginBase.h(6): note: see declaration of 'wxNonGuiPluginBase'
[2/2 100%] Linking CXX shared library bin\wxNonGuiPluginBase.dll
FAILED: bin/wxNonGuiPluginBase.dll lib/wxNonGuiPluginBase.lib 
cmd.exe /C "cmd.exe /C "C:\ProgramFiles\CMake\bin\cmake.exe -E __create_def C:\Users\venkybal\VSCode-Workspaces\wxModular2\build\modules\wxNonGuiPluginBase\src\CMakeFiles\wxNonGuiPluginBase.dir\exports.def C:\Users\venkybal\VSCode-Workspaces\wxModular2\build\modules\wxNonGuiPluginBase\src\CMakeFiles\wxNonGuiPluginBase.dir\exports.def.objs && cd c:\users\venkybal\vscode-workspaces\wxmodular2\build" && C:\ProgramFiles\CMake\bin\cmake.exe -E vs_link_dll --intdir=modules\wxNonGuiPluginBase\src\CMakeFiles\wxNonGuiPluginBase.dir --manifests  -- link.exe /nologo modules\wxNonGuiPluginBase\src\CMakeFiles\wxNonGuiPluginBase.dir\wxNonGuiPluginBase.cpp.obj  /out:bin\wxNonGuiPluginBase.dll /implib:lib\wxNonGuiPluginBase.lib /pdb:bin\wxNonGuiPluginBase.pdb /dll /version:0.0 /machine:x64 /debug /INCREMENTAL  /DEF:modules\wxNonGuiPluginBase\src\CMakeFiles\wxNonGuiPluginBase.dir\exports.def  C:\ProgramFiles\wxWidgets\vc15_x64\lib\vc_x64_dll\wxmsw31ud_core.lib C:\ProgramFiles\wxWidgets\vc15_x64\lib\vc_x64_dll\wxbase31ud.lib winmm.lib comctl32.lib oleacc.lib rpcrt4.lib shlwapi.lib version.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib  && cd ."
   Creating library lib\wxNonGuiPluginBase.lib and object lib\wxNonGuiPluginBase.exp
wxNonGuiPluginBase.cpp.obj : error LNK2001: unresolved external symbol "private: static class wxClassInfo * wxClassInfo::sm_first" (?sm_first@wxClassInfo@@0PEAV1@EA)
wxNonGuiPluginBase.cpp.obj : error LNK2001: unresolved external symbol "public: static class wxClassInfo wxObject::ms_classInfo" (?ms_classInfo@wxObject@@2VwxClassInfo@@A)
bin\wxNonGuiPluginBase.dll : fatal error LNK1120: 2 unresolved externals
LINK Pass 1 failed. with 1120
ninja: build stopped: subcommand failed
Srinivasan.B
srini2174
Earned a small fee
Earned a small fee
Posts: 15
Joined: Wed Nov 11, 2015 7:59 am

Re: Unable to compile a plugin library in VS2017

Post by srini2174 »

Hi,

I also have a separate build of wxwidgets using gcc and this same code compiles without any issues in gcc.

Srinivasan.B
srini2174
Earned a small fee
Earned a small fee
Posts: 15
Joined: Wed Nov 11, 2015 7:59 am

Re: Unable to compile a plugin library in VS2017

Post by srini2174 »

Hi,

Any help on this topic will be highly appreciated.

I am attaching the workspace which I use for reference. The same code works fine in gcc version 7.1. I am using VS 2017 compiler on a Windows 10 machine.

Srinivasan.B
Attachments
wxModular4.zip
(299.91 KiB) Downloaded 86 times
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Unable to compile a plugin library in VS2017

Post by doublemax »

warning C4275: non dll-interface class 'wxObject' used as base for dll-interface class 'wxNonGuiPluginBase'
I'm pretty sure this is the key, but i have no idea what to do about it, especially if it works with GCC.

Did you use the same CRT settings (/MT vs /MD etc.) in your project as in wxWidgets?

As this problem is not really wxWidgets specific, i would also suggest to google for "warning C4275". I found several posts, although i didn't see anything that looked like a solution for your project.
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Unable to compile a plugin library in VS2017

Post by ONEEYEMAN »

Hi,
So you do have the same problem when you try to compile "minimal" sample provided with the library?
Did you try to open the solutiuon inside the IDE right agter you compile the library?

Thank you.
srini2174
Earned a small fee
Earned a small fee
Posts: 15
Joined: Wed Nov 11, 2015 7:59 am

Re: Unable to compile a plugin library in VS2017

Post by srini2174 »

Hi,

The minimal sample compile fine without any problems. The problem happens only when I compile my code as a library.

Srinivasan.B
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Unable to compile a plugin library in VS2017

Post by ONEEYEMAN »

Hi,
Are you trying to build and link with dynamic or static wx configuration?

I believe you should build a dynamic one since it is a plugin...

Thank you.
srini2174
Earned a small fee
Earned a small fee
Posts: 15
Joined: Wed Nov 11, 2015 7:59 am

Re: Unable to compile a plugin library in VS2017

Post by srini2174 »

Hi,

No. The wxwidgets is build with dynamic configuration and the code which I am building is also a dll. So there is no problem with this. The problem seems to be the right way to export and import the symbols in the dll.

Srinivasan.B
srini2174
Earned a small fee
Earned a small fee
Posts: 15
Joined: Wed Nov 11, 2015 7:59 am

Re: Unable to compile a plugin library in VS2017

Post by srini2174 »

Hi,

Finally I was able to resolve this issue. Please find the comment in line 3 of the code below. Once I remove this include I am able to create the dll. I do not understand why it is? Maybe someone can help me in understand this better.

Further I also had to provide the -DWXMAKING_NGUI option in the cmake file while compiling the DLL.

Srinivasan.B

Code: Select all

#pragma once
#if defined(__WXMSW__)
#include <wx/dlimpexp.h>  // This include causes a link error.  I do not know why?
#ifdef WXMAKINGDLL_NGUI
#    define WXDLLIMPEXP_NGUI WXEXPORT
#    define WXDLLIMPEXP_DATA_NGUI(type) WXEXPORT type
#    if defined(HAVE_VISIBILITY)
#        define WXDLLIMPEXP_INLINE_NGUI WXEXPORT
#    else
#        define WXDLLIMPEXP_INLINE_NGUI
#    endif
#elif defined(WXUSINGDLL_NGUI)
#    define WXDLLIMPEXP_NGUI WXIMPORT
#    define WXDLLIMPEXP_DATA_NGUI(type) WXIMPORT type
#    if defined(HAVE_VISIBILITY)
#        define WXDLLIMPEXP_INLINE_NGUI WXIMPORT
#    else
#        define WXDLLIMPEXP_INLINE_NGUI
#    endif
#else
#    define WXDLLIMPEXP_NGUI
#    define WXDLLIMPEXP_DATA_NGUI(type) type
#    define WXDLLIMPEXP_INLINE_NGUI
#endif

#endif

/*
#ifndef _WX_NONGUIPLUGIN_DEF_H_
#define _WX_NONGUIPLUGIN_DEF_H_

#if defined(WXMAKINGLIB_NGUI)
  #define WXDLLIMPEXP_NGUI
#elif defined(WXMAKINGDLL_NGUI)
  #define WXDLLIMPEXP_NGUI WXEXPORT
#elif defined(WXUSINGDLL_NGUI)
  #define WXDLLIMPEXP_NGUI WXIMPORT
#else // not making nor using DLL
  #define WXDLLIMPEXP_NGUI
#endif


//  GCC warns about using __declspec on forward declarations
//  while MSVC complains about forward declarations without
//  __declspec for the classes later declared with it. To hide this
//  difference a separate macro for forward declarations is defined:

#if defined(HAVE_VISIBILITY) || (defined(__WINDOWS__) && defined(__GNUC__))
  #define WXDLLIMPEXP_FWD_NGUI
#else
  #define WXDLLIMPEXP_FWD_NGUI WXDLLIMPEXP_NGUI
#endif

#endif
*/
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Unable to compile a plugin library in VS2017

Post by ONEEYEMAN »

Hi,
I think you might want to post to wx-dev.
You will need to attach the Cmake project file, mention you are creating a plugin dll and what did you do to fix the problem.

It is possible that the author of CMake for wxWidgets will be able to help.

Also, are you sure you are compiling against the DLL setup?

Thank you.
Post Reply