Author Topic: Codeblocks 12.11 LNK2005 errors using VS 2010  (Read 16577 times)

Offline Mug

  • Multiple posting newcomer
  • *
  • Posts: 10
Codeblocks 12.11 LNK2005 errors using VS 2010
« on: February 20, 2013, 09:41:08 pm »
I'm attempting to compile the automatic generated wxWidgets program in codeblocks 12.11 with the compiler set to Visual Studio 2010 on Windows 7 but receive loads of link errors:

Code: [Select]
msvcprtd.lib(MSVCP100D.dll)||error LNK2005: "void __cdecl std::_Xlength_error(char const *)" ([email protected]@@[email protected]) already defined in libcpmtd.lib(xthrow.obj)|
msvcprtd.lib(MSVCP100D.dll)||error LNK2005: "void __cdecl std::_Xout_of_range(char const *)" ([email protected]@@[email protected]) already defined in libcpmtd.lib(xthrow.obj)|
msvcprtd.lib(MSVCP100D.dll)||error LNK2005: "public: __thiscall std::_Container_base12::~_Container_base12(void)" ([email protected]@@[email protected]) already defined in Test2App.obj|
msvcprtd.lib(MSVCP100D.dll)||error LNK2005: "public: __thiscall std::_Container_base12::_Container_base12(void)" ([email protected]@@[email protected]) already defined in Test2Main.obj|
msvcprtd.lib(MSVCP100D.dll)||error LNK2005: "public: void __thiscall std::_Container_base12::_Orphan_all(void)" ([email protected][email protected]@@QAEXXZ) already defined in Test2App.obj|
msvcprtd.lib(MSVCP100D.dll)||error LNK2005: "void __cdecl std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)" ([email protected]@@[email protected]) already defined in libcpmtd.lib(stdthrow.obj)|
msvcprtd.lib(MSVCP100D.dll)||error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" ([email protected]@@[email protected]) already defined in libcpmtd.lib(xlock.obj)|
msvcprtd.lib(MSVCP100D.dll)||error LNK2005: "public: __thiscall std::_Lockit::_Lockit(int)" ([email protected]@@[email protected]@Z) already defined in libcpmtd.lib(xlock.obj)|
msvcprtd.lib(MSVCP100D.dll)||error LNK2005: "public: virtual __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::~basic_streambuf<char,struct std::char_traits<char> >(void)" ([email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in libcpmtd.lib(cout.obj)|
msvcprtd.lib(MSVCP100D.dll)||error LNK2005: "protected: __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::basic_streambuf<char,struct std::char_traits<char> >(void)" ([email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in libcpmtd.lib(cout.obj)|
msvcprtd.lib(MSVCP100D.dll)||error LNK2005: "public: void __thiscall std::basic_ios<char,struct std::char_traits<char> >::clear(int,bool)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in libcpmtd.lib(cout.obj)|
msvcprtd.lib(MSVCP100D.dll)||error LNK2005: "public: virtual __thiscall std::basic_ios<char,struct std::char_traits<char> >::~basic_ios<char,struct std::char_traits<char> >(void)" ([email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in libcpmtd.lib(cout.obj)|
msvcprtd.lib(MSVCP100D.dll)||error LNK2005: "public: virtual __thiscall std::basic_ostream<char,struct std::char_traits<char> >::~basic_ostream<char,struct std::char_traits<char> >(void)" ([email protected][email protected]@[email protected]@@[email protected]@[email protected]) already defined in libcpmtd.lib(cout.obj)|
etc.

I've read this can be solved by setting the /NODEFAULTLIB:library flag but I haven't found where to set this in 12.11. How can I get the program to link correctly?

Offline cacb

  • Regular
  • ***
  • Posts: 399
Re: Codeblocks 12.11 LNK2005 errors using VS 2010
« Reply #1 on: February 20, 2013, 11:16:08 pm »
You can do it as shown in the attachment, which shows a Release target. For the Debug target remove the 'd's in the library names.


Offline Mug

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Codeblocks 12.11 LNK2005 errors using VS 2010
« Reply #2 on: February 21, 2013, 09:41:49 am »
Thanks, I'm slowly getting there... However, I'm still getting some errors.

These are my current settings:
Settings->Compiler...->Search Directories->Compiler
  C:\Program Files\Microsoft SDKs\Windows\v7.1\Include
  C:\Program Files\Microsoft Visual Studio 10.0\VC\include

Settings->Compiler...->Search Directories->Linker
  C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib
  C:\Program Files\Microsoft Visual Studio 10.0\VC\lib

Settings->Compiler...->Search Directories->Resource Compiler
  C:\Program Files\Microsoft SDKs\Windows\v7.1\Include
  C:\Program Files\Microsoft Visual Studio 10.0\VC\include
  
Settings->Compiler...->Linker settings->Other linker options:
    /NODEFAULTLIB:libcpmtd.lib
    /NODEFAULTLIB:LIBCMTD.lib

These are my steps to produce the errors
1. Start codeblocks 12.11.
2. Click "Create a new project".
3. Double click "wxWidgets Project".
4. Select wxWidgets 2.9.x (SVN Version).
5. Click "Next".
6. Enter Project title: "Test2".
7. Click "Next".
8. Click "Next*.
9. Select "wxSmith" and "Dialog Based".
10. Click "Next".
11. Accept wxWidgets' location: as "$(#wx)".
12. Click "Next".
13. Compiler is "Microsoft Visual C++ 2010 and both "Release" and "Debug" boxes are checked.
14. Click "Next".
15. Only "Enable Unicode" is checked.
16. Click "Next".
17. On the messagebox, click "No" to continue with Multi-threaded Static CRT mode.
18. Select wxHTML, wxJpeg and wxTiff.
19. Click "Finish".
20. Build the application.

These are the errors I get  ???
Code: [Select]
msvcprtd.lib(MSVCP100D.dll)||error LNK2005: "public: __thiscall std::_Container_base12::~_Container_base12(void)" ([email protected]@@[email protected]) already defined in Test2App.obj|
msvcprtd.lib(MSVCP100D.dll)||error LNK2005: "public: __thiscall std::_Container_base12::_Container_base12(void)" ([email protected]@@[email protected]) already defined in Test2Main.obj|
msvcprtd.lib(MSVCP100D.dll)||error LNK2005: "public: void __thiscall std::_Container_base12::_Orphan_all(void)" ([email protected][email protected]@@QAEXXZ) already defined in Test2App.obj|
bin\Debug\Test2.exe||fatal error LNK1169: one or more multiply defined symbols found|
« Last Edit: February 21, 2013, 10:06:49 am by Mug »

Offline cacb

  • Regular
  • ***
  • Posts: 399
Re: Codeblocks 12.11 LNK2005 errors using VS 2010
« Reply #3 on: February 21, 2013, 07:52:58 pm »
Thanks, I'm slowly getting there... However, I'm still getting some errors.

Because you didn't follow the previous advice as shown.

Offline Mug

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Codeblocks 12.11 LNK2005 errors using VS 2010
« Reply #4 on: February 21, 2013, 08:35:55 pm »

Because you didn't follow the previous advice as shown.

Could you be more specific?
Of course I tried with all the files you showed in the "Other linker options", but since I got the same errors, I see no point in keeping them there. Anyway, I put them back in and I still get the errors.

[attachment deleted by admin]

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6671
    • My Best Post
Re: Codeblocks 12.11 LNK2005 errors using VS 2010
« Reply #5 on: February 22, 2013, 04:14:35 am »
You are supposed to change the Project Options instead of Global Compiler Options in nearly all cases like this.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline cacb

  • Regular
  • ***
  • Posts: 399
Re: Codeblocks 12.11 LNK2005 errors using VS 2010
« Reply #6 on: February 22, 2013, 08:38:57 am »
You are supposed to change the Project Options instead of Global Compiler Options in nearly all cases like this.

Tim S.

And actually exclude the suggested libraries, instead of other ones.

Offline Mug

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Codeblocks 12.11 LNK2005 errors using VS 2010
« Reply #7 on: February 22, 2013, 09:18:17 am »
OK, thanks. That just goes to show that I don't have a clue how to set up code::blocks and really would appreciate some help.

So, I started again from scratch and left the Global Compiler Options alone.
Now, instead of 4 errors I get over 50  ???

Code: [Select]
msvcprtd.lib(MSVCP100D.dll)||error LNK2005: "public: __thiscall std::_Container_base12::~_Container_base12(void)" ([email protected]@@[email protected]) already defined in Test2App.obj|
msvcprtd.lib(MSVCP100D.dll)||error LNK2005: "public: __thiscall std::_Container_base12::_Container_base12(void)" ([email protected]@@[email protected]) already defined in Test2Main.obj|
msvcprtd.lib(MSVCP100D.dll)||error LNK2005: "public: void __thiscall std::_Container_base12::_Orphan_all(void)" ([email protected][email protected]@@QAEXXZ) already defined in Test2App.obj|
wxbase29ud.lib(mimetype.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(ipcbase.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(textfile.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(base64.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(mimecmn.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(fileback.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(dde.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(fileconf.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(languageinfo.obj)||error LNK2019: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z) referenced in function [email protected][email protected][email protected]@@[email protected][email protected]@@[email protected]@[email protected]|
wxbase29ud.lib(regconf.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(stdpaths.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(longlong.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(process.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(debughlp.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(datetimefmt.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(crashrpt.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(stackwalk.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(any.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(xlocale.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(dir.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(wxcrt.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(datetime.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(datstrm.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(mstream.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(convauto.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(timercmn.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(ffile.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(stopwatch.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(variant.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(wfstream.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(hash.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(txtstrm.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(textbuf.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(fmapbase.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(encconv.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(stream.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(platinfo.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(utilsexc.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(registry.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(file.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(filename.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(filesys.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(filefn.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(uri.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(time.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(sysopt.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
wxbase29ud.lib(tokenzr.obj)||error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" ([email protected]@Z)|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 0 warnings (0 minutes, 21 seconds) ===|

Here are my library settings
« Last Edit: February 22, 2013, 09:24:12 am by Mug »

Offline cacb

  • Regular
  • ***
  • Posts: 399
Re: Codeblocks 12.11 LNK2005 errors using VS 2010
« Reply #8 on: February 22, 2013, 06:06:50 pm »
You have got to pay more attention to the basic instructions given. You keep ignoring them, that is why you are having problems.

You were assisted with this
You can do it as shown in the attachment, which shows a Release target. For the Debug target remove the 'd's in the library names.

But you chose to exclude other libraries. When you complained about further errors, you were again hinted at the cause
Because you didn't follow the previous advice as shown.

You then did the opposite of the advice given (observe Release and Debug), and for some unexplained reason chose to explicitely include another MS library and at the same time declare it as excluded from the list of default linked libraries. That makes no sense. Try following the advice given.

I'll gladly assist, but only if you follow the advice.

Offline Mug

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Codeblocks 12.11 LNK2005 errors using VS 2010
« Reply #9 on: February 25, 2013, 09:01:10 am »
For you, this may all seem terribly simple, but I can assure you, I've spent many hours just trying to get a wizard-generated program to compile.
I am completely new to codeblock, and all I expect is to be able to compile the simplest, auto-generated project.

My first mistake was that I did not realize you were using the Project Options instead of the Global Compiler Options. I thought you were using another version of codeblocks because I saw no mention of VC++ 2010 in your screen capture. Also, since I didn't recognize your capture, I thought it was from another version of codeblocks. I think this mistake is easy to oversee, especially if you are completely new to codeblocks.

Anyway, I have now done a fresh install, after first removing codeblocks from %APPDATA%\
I have added EXACTLY what your first screen capture shows, nothing else. As you can see, there is an include file missing, but I don't dare add this for fear of you telling me I have not followed your instructions. So please, tell me what I should do next.

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Codeblocks 12.11 LNK2005 errors using VS 2010
« Reply #10 on: February 25, 2013, 11:50:10 am »
First you have to understand a bit about the different options you have in MSVC.

1) If you use /MT as compiler and linker option, your program is linked statically with MSVC runtime. In this case your program will be linked with libcmt.lib . You MUST use same compiler and linker options (/MT in this case) for all modules/libraries that are being linked.
2) If you use /MD as compiler and linker option, your program is linked dynamically with MSVC runtime. In this case your program will be linked with msvcrt.lib . Again you MUST use same compiler and linker options (/MD in this case) for all modules/libraries that are being linked. In this case you can use /NODEFAULTLIB:/libcmt.lib in the linker option.

Now from the step 17 of your post I see you are using statically linked wxwidgets library, i.e. option 1 above. In that case you should make sure your wxwidgets library has been built with same flag (/MT - statically against MSVC runtime).
Be a part of the solution, not a part of the problem.

Offline Mug

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Codeblocks 12.11 LNK2005 errors using VS 2010
« Reply #11 on: February 25, 2013, 02:08:45 pm »
Thank you for your reply and taking the time to study what I'm trying to do. Yes, I am only interested in a static build. I believe wxWidgets is correctly built.
From within visual studio I used batch build with all selected and repeated compiling until I got no errors. That went very smoothly.

I can also compile a staticly linked wxProject without any problem from within VS2010. That also went very smoothly, thanks to excellent documentation. However, I am at a total loss of how to compile the same files within code::blocks. Believe me, I've spent hours trying to get code::blocks to work, but I'm getting to the point where I'm losing complete interest. I come here for help, get told off for doing something I thaught I was doing right, had everything down to 2 errors, but now can't even compile any more. Yes I know how I can get rid of the include errors, but I was told to only do what I was told. So be it. I just hope someone will be kind enough to help me along. I've also spent days searching for information but have only found outdated documentation which was no help to me at all. I have installed / de-installed code::blocks well over a dozen times. I have never encounted such a badly documented (at least for VS2010) and confusing environment. OK, I know it's free, and from what I've seen I do like wxSmith, but I'm slowly asking myself why I've wasted so many days on trying to get this environment to work with Visual Studio.
« Last Edit: February 25, 2013, 02:10:24 pm by Mug »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6671
    • My Best Post
Re: Codeblocks 12.11 LNK2005 errors using VS 2010
« Reply #12 on: February 25, 2013, 04:03:00 pm »
Read this link; I know it won't help you, much.

http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F

This is really a topic more appropriate to wxForum and this site, together. You almost need two separate threads.
One for wxWidgets questions and one for CB Questions.

http://forums.wxwidgets.org/viewforum.php?f=19&sid=7dd1b87ec298c9720a6da33f1ed3a982

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Codeblocks 12.11 LNK2005 errors using VS 2010
« Reply #13 on: February 26, 2013, 02:31:10 am »
Thank you for your reply and taking the time to study what I'm trying to do. Yes, I am only interested in a static build. I believe wxWidgets is correctly built.
From within visual studio I used batch build with all selected and repeated compiling until I got no errors. That went very smoothly.

If you have used Visual Studio to build wxwidgets then that indicates you have built wxwidgets against dynamic MSVC runtime. To solve this problem Click on the Yes button in step 17. Wizard will do the rest. And DO NOT customise any other compiler/linker options.
Be a part of the solution, not a part of the problem.

Offline Mug

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Codeblocks 12.11 LNK2005 errors using VS 2010
« Reply #14 on: February 26, 2013, 10:10:54 am »
Thank you for your reply and taking the time to study what I'm trying to do. Yes, I am only interested in a static build. I believe wxWidgets is correctly built.
From within visual studio I used batch build with all selected and repeated compiling until I got no errors. That went very smoothly.

If you have used Visual Studio to build wxwidgets then that indicates you have built wxwidgets against dynamic MSVC runtime. To solve this problem Click on the Yes button in step 17. Wizard will do the rest. And DO NOT customise any other compiler/linker options.


Well, thank you very, very much. That was terribly simple after all the frustration I've had over the last few days. You've made my day.  :)

For the time being, that will certainly get me started, but, if I dare ask, what steps do I need to take to use static CRT mode? Or is this a wxWidgets question? I thought if I used batch build in VS2010 to build wxWidgets then all the libraries gets compiled. It certainly took a very long time! Is there any way I can check if the static libraries are there?

Anyway, you can't imagine how happy I am now that I can at last take a look at what code:blocks can do. Thank you.