Skip to main content
Email Password   helpLost your password?

Introduction

This tool automatically converts Visual C++ 8.0 or 9.0 projects to Linux makefile. Important note, there is no loss during the conversion: source code and .sln/.vcproj files are left unchanged. The tool has been implemented in C# VS 2005.

Why?

Both these reasons force you to create a makefile manually and each small change in your project requires hard physical labor in makefile maintenance.

This tool will do it for you automatically and will provide you with the ability to keep .sln/.vcproj and .mak files synchronized.

Using the Tool

The tool is a command line (console application).
Argument format is like the following:

  1. In case an active project name is similar to solution name:
    sln2mak [Solution_FullPath_File_Name].sln

    Example:

    sln2mak c:/myprojects/test/unit_test.sln
  2. In case an active project name differs from solution name:
    sln2mak -l [Main_Project_Name] [Solution_FullPath_File_Name].sln

    Example:

    sln2mak -l unit_test c:/myprojects/test/test.sln
  3. In case you would like to convert a list of .vcproj files, type in this list, when the first one is the main lead project, and then use -d flag for additional dependencies, like libs, for a main project if it exists.
    sln2mak [Main_Project_FullPath_Name].vcproj [Project_FullPath_Name_2].vcproj ... 
             [Project_FullPath_Name_n].vcproj -d [lib_Name_1] ... [lib_Name_n]

    Example:

    sln2mak c:/myprojects/tets/unit_test.vcproj c:/myprojects/tets/test_lib.vcproj 
        -d mystaticlib1 mystaticlib2 mystaticlib3 

    For usage, call sln2mak with no arguments.

    After application runs, you'll find .mak file in path where .vcproj is located with the same name as the project.

    .mak files have all additional libraries path, sources, flags for compiler, linker, preprocessor and target path. 

In .sln path, you'll find Makefile that will handle all target rules (clean, make) and dependencies.

Makefile.JPG

Points of Interest

Parser Class

This class has a static constructor that aims to be known for all classes without instantiation.

It holds regular expression that serves all other classes for parsing .sln and .vcproj files.

Regex m_ProjectGuid      = new Regex(@"ProjectGUID=""\{(.*)\}"""        ) ;
Regex m_SlnExtention     = new Regex(@"(.*)(.[Ss][Ll][Nn])$"            ) ;
Regex m_VcprojExtention  = new Regex(@"(.*)(.[Vv][Cc][Pp][Rr][Oo][Jj])$") ;
Regex m_ProjectRegex     = new Regex(@"Project\(""\{(.*)\}""\) = ""(.*)"", ""(.*)"",
   ""\{(.*)\}""") ;

VcSlnInfo Class

This class parses solution file and creates Makefile with target rules.

This class uses stream reader for reading .sln file line by line. During reading .sln file, it recognizes an active project (its name is similar to the solution name) and creates four dictionaries that hold information about all main and dependent projects:

Dictionary<string, string>  m_ProjGuidName = new Dictionary<string, string>() ;

Then method ParseVcproj is called - public VcProjInfo class's function, but first for each .vcproj  instance of VcProjInfo object created with projectName, projectFullPath and projectMakFileName.

VcProjInfo Class

In this class, VCProjectEngine object is used for retrieving all the necessary information about .vcproj, like target type and name, compiler flags, additional libraries, linker flags, sources and filters, preprocessor definitions, configurations, etc.

using Microsoft.VisualStudio.VCProjectEngine;
VCProjectEngine vcprojEngine = new VCProjectEngineObject();
//Init VCProject vcProj object
VCProject m_VcProj = (VCProject)vcprojEngine.LoadProject(vcProjFile);

//Init vcproj configurations list 
IVCCollection m_ConfigCollection = (IVCCollection)m_VcProj.Configurations;

All these helped me to create .mak file with CFLAGS, LDFLAGS, OBJS, etc.

Important Notes

History  

Prior to writing the application, I tried to find a similar tool on the internet, but was only successful in finding other people's questions on online forums regarding the issue.
Then I attempted to understand XML-schema of a VC++8 solution and project, but the schema wasn't clear enough.

Suddenly I found a Microsoft.VisualStudio.VCProjectEngine reference with VCProjectEngine object within .NET components which helped me to understand the structure of a VC++ 2005 project. I used this object in my application for .vcproj parsing instead of using System.Xml for XML tree reading, and this without proper XML schema documentation.

reference.JPG

Disclaimer 

The information provided on this page comes without any warranty whatsoever.  

This tool has been extensively tested before being published, but always there is the possibility to find some weakness. I strongly recommend that you back up your project before using this tool. Moreover, though I am willing to know if there is anything I can do in order to improve it, let me clearly say that it's not my fault if your project is corrupted by this tool.

Update History  

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralMy vote of 1 Pin
xComaWhitex
22:11 6 Nov '09  
QuestionWhy does it not see the static library included in the solution? Pin
phantom22202
8:36 27 Oct '09  
AnswerRe: Why does it not see the static library included in the solution? Pin
Maria Adamsky
0:27 28 Oct '09  
GeneralRe: Why does it not see the static library included in the solution? Pin
phantom22202
5:18 29 Oct '09  
GeneralRe: Why does it not see the static library included in the solution? Pin
Maria Adamsky
10:55 29 Oct '09  
GeneralRe: Why does it not see the static library included in the solution? Pin
phantom22202
6:24 29 Oct '09  
GeneralRe: Why does it not see the static library included in the solution? Pin
Maria Adamsky
10:59 29 Oct '09  
GeneralUnhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly Microsoft.VisualStudio.VCProjectEngine Pin
noobody2
6:03 7 Oct '09  
GeneralRe: Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly Microsoft.VisualStudio.VCProjectEngine Pin
Maria Adamsky
12:31 7 Oct '09  
GeneralRe: Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly Microsoft.VisualStudio.VCProjectEngine Pin
uepelde
0:07 27 Oct '09  
GeneralRe: Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly Microsoft.VisualStudio.VCProjectEngine Pin
Maria Adamsky
0:12 27 Oct '09  
QuestionRe: Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly Microsoft.VisualStudio.VCProjectEngine Pin
uepelde
2:27 27 Oct '09  
AnswerRe: Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly Microsoft.VisualStudio.VCProjectEngine Pin
Maria Adamsky
4:11 27 Oct '09  
GeneralRe: Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly Microsoft.VisualStudio.VCProjectEngine Pin
uepelde
6:50 27 Oct '09  
GeneralRe: Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly Microsoft.VisualStudio.VCProjectEngine Pin
Maria Adamsky
0:37 28 Oct '09  
GeneralRe: Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly Microsoft.VisualStudio.VCProjectEngine Pin
uepelde
2:06 28 Oct '09  
GeneralRe: Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly Microsoft.VisualStudio.VCProjectEngine Pin
Maria Adamsky
2:16 28 Oct '09  
GeneralRe: Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly Microsoft.VisualStudio.VCProjectEngine [modified] Pin
uepelde
2:42 28 Oct '09  
GeneralRe: Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly Microsoft.VisualStudio.VCProjectEngine Pin
Maria Adamsky
3:35 28 Oct '09  
GeneralRe: Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly Microsoft.VisualStudio.VCProjectEngine Pin
uepelde
6:11 28 Oct '09  
GeneralRe: Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly Microsoft.VisualStudio.VCProjectEngine Pin
Maria Adamsky
10:51 28 Oct '09  
GeneralRe: Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly Microsoft.VisualStudio.VCProjectEngine Pin
uepelde
2:01 29 Oct '09  
Question[VS2008] System.IO.IOException unhandled Pin
Daniele Barzotti
22:36 16 Sep '09  
AnswerRe: [VS2008] System.IO.IOException unhandled Pin
Maria Adamsky
4:13 17 Sep '09  
GeneralRe: [VS2008] System.IO.IOException unhandled Pin
Daniele Barzotti
23:18 17 Sep '09  


Last Updated 19 Apr 2009 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2009