wxString already defined in dll Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 462
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

wxString already defined in dll

Post by mael15 » Wed Oct 27, 2010 11:29 am

hi everybody!
i am about to despair over this error:
1>wxbase29ud.lib(object.obj) : error LNK2005: "public: __thiscall wxFormatString::wxFormatString(wchar_t const *)" ([email protected]@[email protected][email protected]) ist bereits in libConfig.lib(libConfig.dll) definiert.
1>wxbase29ud.lib(object.obj) : error LNK2005: "public: __thiscall wxFormatString::operator wchar_t const *(void)const " ([email protected]@QBEPB_WXZ) ist bereits in libConfig.lib(libConfig.dll) definiert.
1>wxbase29ud.lib(object.obj) : error LNK2005: "public: __thiscall wxString::wxString(wchar_t const *)" ([email protected]@[email protected][email protected]) ist bereits in libConfig.lib(libConfig.dll) definiert.
1>wxbase29ud.lib(object.obj) : error LNK2005: "public: __thiscall wxString::~wxString(void)" ([email protected]@[email protected]) ist bereits in libConfig.lib(libConfig.dll) definiert.
1>wxbase29ud.lib(object.obj) : error LNK2005: "public: __thiscall wxFormatString::~wxFormatString(void)" ([email protected]@[email protected]) ist bereits in libConfig.lib(libConfig.dll) definiert.
the list goes on and on, these are only the first five rows.

what i did already:
- check that dll and app are compiled with \MDd
- recompile wxWidgets 2.9.1 with vs2010
- take all settings from http://wiki.wxwidgets.org/Microsoft_Vis ... ct_by_Hand
- change settings "wchar as integrated type" in settings->c++->language because the first error message sais something about wchar_t

can anyone help me?
thanx!

tan
Moderator
Moderator
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Re: wxString already defined in dll

Post by tan » Wed Oct 27, 2010 11:56 am

Hi,
mael15 wrote:hi everybody!
i am about to despair over this error:
1>wxbase29ud.lib(object.obj) : error LNK2005: "public: __thiscall wxFormatString::wxFormatString(wchar_t const *)" ([email protected]@[email protected][email protected]) ist bereits in libConfig.lib(libConfig.dll) definiert.
1>wxbase29ud.lib(object.obj) : error LNK2005: "public: __thiscall wxFormatString::operator wchar_t const *(void)const " ([email protected]@QBEPB_WXZ) ist bereits in libConfig.lib(libConfig.dll) definiert.
1>wxbase29ud.lib(object.obj) : error LNK2005: "public: __thiscall wxString::wxString(wchar_t const *)" ([email protected]@[email protected][email protected]) ist bereits in libConfig.lib(libConfig.dll) definiert.
1>wxbase29ud.lib(object.obj) : error LNK2005: "public: __thiscall wxString::~wxString(void)" ([email protected]@[email protected]) ist bereits in libConfig.lib(libConfig.dll) definiert.
1>wxbase29ud.lib(object.obj) : error LNK2005: "public: __thiscall wxFormatString::~wxFormatString(void)" ([email protected]@[email protected]) ist bereits in libConfig.lib(libConfig.dll) definiert.
the list goes on and on, these are only the first five rows.

what i did already:
- check that dll and app are compiled with \MDd
- recompile wxWidgets 2.9.1 with vs2010
- take all settings from http://wiki.wxwidgets.org/Microsoft_Vis ... ct_by_Hand
- change settings "wchar as integrated type" in settings->c++->language because the first error message sais something about wchar_t

can anyone help me?
thanx!
what is libConfig.lib? Is it your own library?
My most likely guess - you are using static linking with wx libs for the app and libConfig.dll. It is a bad practice using dll in a project and static linking at the same time.
Try one of two options:
- use shared linking with wx libs for the app and the dll
- use static linking, but build libConfig as library, not as dll.
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10

briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 670
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Post by briceandre » Wed Oct 27, 2010 12:10 pm

It is a bad practice using dll in a project and static linking at the same time.
Well, I do not agree. In this case, it is a bad idea because his dll seems to use wxWidgets.

But, if you have a dll that is performing some stuff without using wxWidgets and if you want to use it in your application, there is not problem to statically link your app with wxWidgets.

mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 462
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Post by mael15 » Wed Oct 27, 2010 12:16 pm

hi tan,

yes, configLib.dll is my own library.
this dynamic/static linking with wxlibs is new to me, do you some resource that explains to me what to do?

thanx!

briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 670
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Post by briceandre » Wed Oct 27, 2010 12:30 pm

A dynamic link is a link that is performed at execution time. In this case, the content of the library is not included in the app executable.

There are two advantages : the first is that if you have several applications using the same library, you can store one single copy of this library in your computer. With static link, you would have one version of the lib embedded in each application. The second advantage is that you can update the lib without recompiling your application by simply overriding the lib and relaunching your app.

There are some disadvantages. The major one is that calls to dynamically linked libraries are slighlty slower. You also have to distribute dll with your app, and ensure that the application can find them at execution (wich depends on the OS).

But, what you cannot do is mix static and dynamic link of the same lib within the same app.

So, in your case, either you compile configLib as a static lib, or you link your main app as a dll.

The way to perform that depends on your development environment.

Try to generate configLib as a static lib, it will probably be simpler. Check in the configuration of your project, you should find the proper options.

tan
Moderator
Moderator
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Post by tan » Wed Oct 27, 2010 12:44 pm

briceandre,
In this case, it is a bad idea because his dll seems to use wxWidgets.
yes, you are right. I also meant it (probably implicitly)

mael15,
this dynamic/static linking with wxlibs is new to me, do you some resource that explains to me what to do?
first of all, you have to build WX with option SHARED=1.
If you build WX libs with command line (MSW + MSVC)

nmake -f makefile.vc SHARED=1 BUILD={debug|release} UNICODE={0|1}

If you use any IDE it depends on :)

And then you have to link the app with shared wx libs.
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10

mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 462
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Post by mael15 » Wed Oct 27, 2010 1:00 pm

thanx, guys!
i build wx with this guide:
http://wiki.wxwidgets.org/Microsoft_Vis ... 2B.2B_2010

since there is no makefile, would it be enough to open each of the 22 build projects and add a preprocessor symbol SHARED=1?

i would prefer using shared linking.

briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 670
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Post by briceandre » Wed Oct 27, 2010 1:08 pm

No, it will not work. This flag is used inside the makefile.

But, they give you the answer in the link you provided :
In build/wx291_msw_vc10 open wx_vc10.sln, select a configuration (for example "DLL Release") and hit F7 until all 22 projects are built successfully (see below screenshot).

mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 462
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Post by mael15 » Wed Oct 27, 2010 1:27 pm

ok, i did compile wx using "debug dll" and then change the linking from /LIBPATH:"$(WXWIN)/lib/vc_lib" to /LIBPATH:"$(WXWIN)/lib/vc_dll", right?

after that, i get:
error LNK2001: Unresolved external symbol ""bool const wxFalse" ([email protected]@3_NB)".
... followed by lots of similar lines.

sorry for this step-by-step thing, but this is new to me.

briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 670
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Post by briceandre » Wed Oct 27, 2010 1:33 pm

Which option do you use to compile your configLib.dll and your main app ?

briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 670
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Post by briceandre » Wed Oct 27, 2010 1:41 pm

(more complete answer)
In fact, it is important to compile your application (including your configLib.dll) with the same options as the ones used for the compilation of your wxWidgets distrib (not all options need to be the same, but several are really important).

So, if you change from static link to dynamic link, you should also change compiler flags.

Open build/wx291_msw_vc10 open wx_vc10.sln project, select "debug dll" config, check which compiler options are set (the ones related to wxWidgets) and check that you have set the same in your own projects.

mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 462
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Post by mael15 » Wed Oct 27, 2010 1:45 pm

i am not sure what you mean by "option", these are the linker command lines:

libConfig.dll:
/OUT:"E:\libconfig\lib\libConfig.dll" /INCREMENTAL /NOLOGO /LIBPATH:"F:\wxWidgets_2_9/lib/vc_dll"
/DLL "comctl32.lib" "rpcrt4.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib"
/NODEFAULTLIB:"LIBCMTD" /MANIFEST /ManifestFile:"Debug\libConfig.dll.intermediate.manifest"
/ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"E:\libconfig\lib\libConfig.pdb" /SUBSYSTEM:WINDOWS /PGD:"E:\libconfig\lib\libConfig.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE
app:
/OUT:".\Debug\app.exe" /INCREMENTAL /NOLOGO
/LIBPATH:"E:\libconfig\lib" /LIBPATH:"F:\wxWidgets_2_9/lib/vc_dll" "libConfig.lib" "comctl32.lib" "rpcrt4.lib" "winmm.lib" "wsock32.lib" "version.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /NODEFAULTLIB:"LIBCMTD" /MANIFEST /ManifestFile:"Debug\app.exe.intermediate.manifest"
/ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"F:\Debug\app.pdb" /MAP /MAPINFO:EXPORTS /ASSEMBLYDEBUG /SUBSYSTEM:WINDOWS /PGD:"F:\Debug\app.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE

briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 670
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Post by briceandre » Wed Oct 27, 2010 1:56 pm

Well, in fact, when you compile wxWidgets, you shall define several c-preprocessor directives that will select the proper configuration (MSW build, Static vs dynamic, debug version, etc). In your case, the vc++ project contains those options and selects them depending on the chosen configuration.

When you create a project for your own application, you should provide the same preprocessor directives so that your build is compatible with the wxWidgets libs you want to link with.

I cannot give you the exact list of options that you should provide because, first, it depends on your config, and second, I am not familiar with vc++. But, in the wxWidgets project, you should find options of the type :

HAVE_W32API_H __WXMSW__ WX_DEBUG

(Note that I am not sure of values provided).

You must provide the same options in your project. Giving the path to the libraries is not enough.

briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 670
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Post by briceandre » Wed Oct 27, 2010 1:58 pm

Note that I mean compiler options and not linker options

mael15
Super wx Problem Solver
Super wx Problem Solver
Posts: 462
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Post by mael15 » Wed Oct 27, 2010 2:14 pm

ok, i found these preprocessor symbols in the "core" project:
WIN32
_USRDLL
DLL_EXPORTS
_DEBUG
__WXMSW__
_UNICODE
WXBUILDING
WXUSINGDLL
WXMAKINGDLL_CORE
wxUSE_BASE=0
i delete some of them, remaining these for my dll:
WIN32
_USRDLL
DLL_EXPORTS
_DEBUG
__WXMSW__
_UNICODE
wxUSE_BASE=0
the error stays the same... this is really frustrating...

Post Reply