Integrating Microsoft Visual C 6 with Code::Blocks IDE

From Code::Blocks

Attaching the compiler framework

You are still using Microsoft Visual C++ version 6 (MSVC6) and want to shift to Code::Blocks? Here are the steps to integrate the (commercial!) Microsoft Visual C++ version 6 compiler into Code::Blocks.

The following steps are required:

  1. Make a copy of the Microsoft Visual C++ Toolkit 2003 as follows:
    • Goto menu "Settings" -> "Compiler and debugger"
    • Select the "Microsoft Visual C++ Toolkit 2003", click the "Copy" Button
    • Save the copy e.g. under "Microsoft Visual C++ 6"
  2. Setup the compiler as follows:
    • The path setup (tab "Programs") should be done as following:
      • The "Compiler's installation directory" should be set to {YOUR_MSVC6}\VC98
      • Under "Additional path's" add:
        • {YOUR_MSVC6_COMMON}\MSDEV98\Bin
        • {YOUR_MSVC6_COMMON}\Tools
    • The compiler/linker setup (tab "Directories) should be done as following:
      • Under the tab "Compiler" add the following path's:
        • {YOUR_MSVC6}\VC98\Include
        • {YOUR_MSVC6}\VC98\MFC\Include
        • {YOUR_MSVC6}\VC98\ATL\Include
      • Under the tab "Linker" add the following path's:
        • {YOUR_MSVC6}\VC98\Lib
        • {YOUR_MSVC6}\VC98\MFC\Lib
      • Under the tab "Resource compiler" add the following path's:
        • {YOUR_MSVC6}\VC98\Include
        • {YOUR_MSVC6}\VC98\MFC\Include
        • {YOUR_MSVC6}\VC98\ATL\Include

That's it.

Working with "legacy" MSVC6 workspaces/projects

Code::Blocks offers the ability to import Visual C++ 6 workspaces and projects. To import a MSVC6 workspace do the following: Menu "Project" -> "Import" -> "MS Visual C++ workspace". Code::Blocks will ask you if it should apply the default compiler or ask for each project which compiler to chose. Choose the second option. Now Code::Blocks will present a compiler selection dialog for each project of the workspace. Choose your newly created compiler ("Microsoft Visual C++ 6") for each project. Usually this should import your workspace just fine.

Now there is some finetuning required:

  1. Code::Blocks may have imported the include path's for compiler and linker as absolute path's. This you should verify and setup to relative apth's where apropriate.
  2. Code::Blocks may have imported the libraries to link against with absolute path's. This you should change to just present the libraries name (e.g. just "MyLib" for the "D:\MyPath\MyOtherPath\MyLib.lib" library). For own libraries there maybe an additional linker include path to be setup for the compiler to find this library.
  3. Code::Blocks usually does not import the "common" MSVC6 libraries you need to link your project against. Thus you will receive linker erros for unresolved symbols. The MSDN will help you to tell which of the "common" library you need to link against. For example: If the linker issues an "unresolved symbol RegCloseKey" a look in the MSDN will reveal that this is part of the "advapi32.lib". Thus just add "advapi32" (without the lib extension) to the libraries to link your project against. This may take a while but if you just start from the first unresolved symbol linking another common library will usually resolve a whole list of unresolved symbols.

Troubleshooting

  1. For troubleshooting enable the "Full command line" Under menu "Settings" -> "Compiler" -> "Other" tab, "Compiler logging".
  2. If you get heaps of warnings, even when compiling a simple Hello World application, you might want to try this. (The error "unrecognized commandline option -g, ignored" should be a hint)
    • Goto menu "Settings" -> "Compiler and debugger"
    • Goto the "Other" tab
    • Hit the "Advanced Options..." button
    • Click OK (you might want to tick the "don't bug me" box)
    • Click the "Compile single file to object file" thingy (if it's not already selected), and, under "Command line macro", replace "$options" with "/nologo /W3 /GX /D "Win32".
      • /GX will fix all the warnings
      • /D "WIN32" will fix your problems if you have a large codebase, with dozens of "#ifdef WIN32" and the like.
      • /W3 you could change ofcourse, to /W1 till /W5, that's all up to you
  3. Why doesn't my VS6 DLL project produce export lib files?
    • Sometimes Code::Blocks doesn't copy the /def:"....def" link options. Just manually type it in.
  4. Why my VS6 projects don't build in the right order?
    • Code::Blocks didn't copy the dependencies from the VS workspace file. So you'll have to manually check the boxes.
  5. During linking it can't find *.obj files but am sure it should be *.lib files?
    • VS6 link lib files has been copied as relative paths without the *.lib extension. Code::Blocks looks for *.obj files because of this. You can either: explicitly browse for the *.lib files (in most cases they haven't been created yet but will be in same place as output dll/exe files) or just type in the name only without the relative path or extension. Though you'll need to set up the correct link paths.
  6. Why am I seeing old link libraries in Code::Block projects that were not even in VS6 project?
    • Code::Blocks naively copies ADD BASE LINK32 lines too.
  7. Can I debug my Visual C++ 6.0 projects?
    • No, there's no command-line debugger with Visual C++ 6.0.