Click here to Skip to main content
Full site     10M members (42.7K online)    

Tool for Converting VC++2005 Project to Linux Makefile

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).

There are three cases for tool use I covered in this article:

  1.  You have a .sln - solution that has one or more .vcproj (projects), among which one of them has the same name as the solution itself and is the main/leading project. This leading project should be a target project that will be compiled into .exe or .dll. Other projects in this solution are dependencies for the leading project. Makefiles will not be generated for those projects that do not have dependencies. Sub-projects can have additional dependencies on external precompiled libraries (libs), stdlib.
  2. You should not sign those dependencies explicitly for a tool; it will be parsed from .vcproj files.

    In this case, the usage:

    sln2mak [Solution_FullPath_File_Name].sln

    Example:

    sln2mak c:/myprojects/test/unit_test.sln
  3. The same case as 1, except that the leading project has a name that is different from the solution name. Flag –l for leading followed by leading project name and then solution fullpath.  
  4. In this case, the usage:

    sln2mak -l [LEADING_Project_Name] [Solution_FullPath_File_Name].sln

    Example:

    sln2mak -l unit_test c:/myprojects/test/test.sln
  5. You'd like to create a makefile from a list of projects without solution "wrapper". For example, you'd like to create a makefile with different structures, not like the one you have for WindowsOS.

    You have a main/leading project and other projects are dependencies of that.

    In addition, you have some precompiled libraries (libs) that you'd like to see them as dependencies for the leading project.  However, they are not listed in the main .vcproj. How can it be, you'll ask? For example, in some solution you have your leading project with all its sub-projects. One of those projects, that the leading project is dependent on, has a dependencies to some precompiled libraries and those are listed within its .vcproj file. So if you use the tool for the whole solution, those dependencies for linker will be parsed from this project and will be listed in its .mak file and then linked by linker to the main/leading project well. But now you'd like to compile only specific list of project that don’t involve  the dependent project, so you  are required to list those libs dependencies manually. Flag –d for dependencies followed by the list of those libs dependencies. 

    sln2mak [LEADING_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.

sln2mak/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.

sln2mak/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  

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search 
Per page   
AnswerRe: Issue when using with VS2005
Amy Phillips 7
4 Nov '11 - 6:09 
QuestionHow can I assign the path for the makefile
hemaolong
22 Jun '11 - 22:45 
AnswerRe: How can I assign the path for the makefile
Maria Adamsky
22 Jun '11 - 23:02 
GeneralFYI, a bug...
SethR
17 May '11 - 16:46 
GeneralRe: FYI, a bug...
Maria Adamsky
17 May '11 - 23:17 
GeneralRe: FYI, a bug...
SethR
28 May '11 - 22:38 
GeneralUnhandled Exception: System.ArgumentOutOfRangeException: Length cannot be less than zero.
Zhijie Wang
29 Apr '11 - 9:53 
GeneralRe: Unhandled Exception: System.ArgumentOutOfRangeException: Length cannot be less than zero.
Maria Adamsky
30 Apr '11 - 1:08 
GeneralRe: Unhandled Exception: System.ArgumentOutOfRangeException: Length cannot be less than zero.
Zhijie Wang
30 Apr '11 - 10:35 
GeneralRe: Unhandled Exception: System.ArgumentOutOfRangeException: Length cannot be less than zero.
Maria Adamsky
30 Apr '11 - 19:32 
GeneralUnhandled Exception: System.Collections.Generic.KeyNotFoundException
Member 7864239
22 Apr '11 - 2:56 
GeneralRe: Unhandled Exception: System.Collections.Generic.KeyNotFoundException
Maria Adamsky
22 Apr '11 - 6:59 
GeneralRe: Unhandled Exception: System.Collections.Generic.KeyNotFoundException
Member 7864239
26 Apr '11 - 11:23 
GeneralRe: Unhandled Exception: System.Collections.Generic.KeyNotFoundException
Maria Adamsky
26 Apr '11 - 22:43 
GeneralHow do I use it in Linux
onlyneerya
13 Apr '11 - 8:32 
GeneralRe: How do I use it in Linux
Maria Adamsky
13 Apr '11 - 21:34 
GeneralThank you for making my life so much easier
MicroImaging
12 Jan '11 - 6:36 
GeneralRe: Thank you for making my life so much easier
Maria Adamsky
12 Jan '11 - 22:23 
QuestionA Bug?
boom_VC
1 Dec '10 - 22:56 
AnswerRe: A Bug?
Maria Adamsky
1 Dec '10 - 23:34 
GeneralGot ArgumentException message
Alexander Lishansky
27 Nov '10 - 21:03 
GeneralGot ArgumentOutOfRangeException message
Alexander Lishansky
27 Nov '10 - 20:47 
GeneralRe: Got ArgumentOutOfRangeException message
Maria Adamsky
27 Nov '10 - 20:58 
GeneralRe: Got ArgumentOutOfRangeException message [modified]
Alexander Lishansky
27 Nov '10 - 21:06 
GeneralRe: Got ArgumentOutOfRangeException message
Maria Adamsky
27 Nov '10 - 21:24 
GeneralRe: Got ArgumentOutOfRangeException message
Alexander Lishansky
27 Nov '10 - 21:27 
GeneralRe: Got ArgumentOutOfRangeException message
Alexander Lishansky
27 Nov '10 - 21:25 
GeneralRe: Got ArgumentOutOfRangeException message
Maria Adamsky
27 Nov '10 - 21:38 
GeneralGot KeyNotFoundException message
Alexander Lishansky
27 Nov '10 - 20:30 
QuestionRuntime exception with VCProjectEngine 10
Edgar Vilela Gadbem
23 Nov '10 - 0:41 
AnswerRe: Runtime exception with VCProjectEngine 10
Maria Adamsky
27 Nov '10 - 21:06 
GeneralRe: Runtime exception with VCProjectEngine 10
Edgar Vilela Gadbem
28 Nov '10 - 7:46 
QuestionSpecified cast is not valid - m_VcProj = (VCProject)vcprojEngine.LoadProject(vcProjFile);
Donald Wickham
15 Nov '10 - 10:49 
AnswerRe: Specified cast is not valid - m_VcProj = (VCProject)vcprojEngine.LoadProject(vcProjFile);
Maria Adamsky
15 Nov '10 - 21:23 
GeneralRe: Specified cast is not valid - m_VcProj = (VCProject)vcprojEngine.LoadProject(vcProjFile);
Donald Wickham
16 Nov '10 - 4:31 
GeneralRe: Specified cast is not valid - m_VcProj = (VCProject)vcprojEngine.LoadProject(vcProjFile);
Maria Adamsky
16 Nov '10 - 4:45 
GeneralKeyNotFoundException
amol9876
18 Oct '10 - 0:52 
GeneralRe: KeyNotFoundException
amol9876
18 Oct '10 - 1:09 
GeneralRe: KeyNotFoundException
Maria Adamsky
18 Oct '10 - 2:53 
GeneralRe: KeyNotFoundException
Pbednaruk
22 Oct '10 - 9:41 
GeneralRe: KeyNotFoundException
Maria Adamsky
23 Oct '10 - 9:17 
GeneralRe: KeyNotFoundException
amol9876
25 Oct '10 - 4:08 
Questionno visual studio?
Kethara
21 Sep '10 - 0:50 
AnswerRe: no visual studio?
Maria Adamsky
21 Sep '10 - 1:02 
Generalwhen I use your Tool,It has exception!
jeckbjy
16 Sep '10 - 18:00 
GeneralRe: when I use your Tool,It has exception!
Maria Adamsky
21 Sep '10 - 1:07 
Questionx64 platforms [modified]
HowitZer26
4 Sep '10 - 4:58 
GeneralMakefile -> VCProj tool
Tercete
30 Jul '10 - 6:15 
GeneralRe: Makefile -> VCProj tool
Maria Adamsky
31 Jul '10 - 9:49 
GeneralMy vote of 3
xComaWhitex
27 Jul '10 - 21:52 

Last Updated 13 Jul 2012 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2013