Click here to Skip to main content
15,125,273 members
Articles / Programming Languages / C#
Posted 28 Aug 2008


159 bookmarked

Tool for Converting VC++2005 Project to Linux Makefile

Rate me:
Please Sign up or sign in to vote.
4.86/5 (69 votes)
13 Jul 2012CPOL6 min read
Convert .sln/.vcproj (VC++2005) to Linux makefile


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.


  • Your application is cross-platform based.
  • Now you are facing a decision to migrate from Visual C++ 6 to 8 or 9.

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


    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


    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]


    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.


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:

  • Key = Guid number , Value = ProjectName
  • Key = ProjectName , Value = ProjectFullPath
  • Key = ProjectName , Value = MakeFileName
  • Key = ProjectName , Value = ProjectDependencies
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

  • There is no loss during the conversion: source code stays unchanged.  
  • Probably I did not cover all flags during parsing from .vcproj to .mak, but now you have all necessary information to be able to add anything I've missed.
  • During my work I inspect that there are few differences between VC++ 8 solution/vcproj and VC++ 9, so you can use this tool for both.
  • If you convert this source code to Visual Studio 2008, please use proper Microsoft.VisualStudio.VCProjectEngine reference version instead of


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.



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  

  • 20/4/2009 Bug fixes (sorry for long delay)
    • Added some spaces in dependencies
    • Removed a loop which was creating multiple rules for a single project
    • Added uppercase WIN32 to be replaced by uppercase LINUX
    • Removed -o option for CPP files
    • Removed printing of "else"
    • Full path for dependent project fixed.

    Especially thanks to Ahmad and Adrej, who helped me to find and fix all listed bugs.

  • 6/9/2008 Bug fixes
    • Uses sln2mak.exe from the same path as .sln/.vcproj.
  • 16/9/2008 Bug fixes 
    • Handles null reference for VC compiler tool, recursive file filters expanding during sources list creation


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Maria Adamsky
Software Developer EFC Real Solutions on Time,LTD
Israel Israel
Software developer at EFC Real Solutions on Time,LTD(Israel) in infrastructure team.
Developing Grid computing application for data communication simulations.
Writing Cross-Platform Software (Windows and Linux).

Comments and Discussions

GeneralRe: Unhandled Exception: System.ArgumentOutOfRangeException: Length cannot be less than zero. Pin
Maria Adamsky30-Apr-11 20:32
MemberMaria Adamsky30-Apr-11 20:32 
GeneralUnhandled Exception: System.Collections.Generic.KeyNotFoundException Pin
Member 786423922-Apr-11 3:56
MemberMember 786423922-Apr-11 3:56 
GeneralRe: Unhandled Exception: System.Collections.Generic.KeyNotFoundException Pin
Maria Adamsky22-Apr-11 7:59
MemberMaria Adamsky22-Apr-11 7:59 
GeneralRe: Unhandled Exception: System.Collections.Generic.KeyNotFoundException Pin
Member 786423926-Apr-11 12:23
MemberMember 786423926-Apr-11 12:23 
GeneralRe: Unhandled Exception: System.Collections.Generic.KeyNotFoundException Pin
Maria Adamsky26-Apr-11 23:43
MemberMaria Adamsky26-Apr-11 23:43 
GeneralHow do I use it in Linux Pin
onlyneerya13-Apr-11 9:32
Memberonlyneerya13-Apr-11 9:32 
GeneralRe: How do I use it in Linux Pin
Maria Adamsky13-Apr-11 22:34
MemberMaria Adamsky13-Apr-11 22:34 
GeneralThank you for making my life so much easier Pin
MicroImaging12-Jan-11 7:36
MemberMicroImaging12-Jan-11 7:36 
After following the directions in the application about including a reference to the Vcengine version 9.00 and compiling, everything worked fine on Studio 2008 SLN file.
Thank you for making my life so much easier.
GeneralRe: Thank you for making my life so much easier Pin
Maria Adamsky12-Jan-11 23:23
MemberMaria Adamsky12-Jan-11 23:23 
QuestionA Bug? Pin
boom_VC1-Dec-10 23:56
Memberboom_VC1-Dec-10 23:56 
AnswerRe: A Bug? Pin
Maria Adamsky2-Dec-10 0:34
MemberMaria Adamsky2-Dec-10 0:34 
GeneralGot ArgumentException message Pin
Alexander Lishansky27-Nov-10 22:03
MemberAlexander Lishansky27-Nov-10 22:03 
GeneralGot ArgumentOutOfRangeException message Pin
Alexander Lishansky27-Nov-10 21:47
MemberAlexander Lishansky27-Nov-10 21:47 
GeneralRe: Got ArgumentOutOfRangeException message Pin
Maria Adamsky27-Nov-10 21:58
MemberMaria Adamsky27-Nov-10 21:58 
GeneralRe: Got ArgumentOutOfRangeException message [modified] Pin
Alexander Lishansky27-Nov-10 22:06
MemberAlexander Lishansky27-Nov-10 22:06 
GeneralRe: Got ArgumentOutOfRangeException message Pin
Maria Adamsky27-Nov-10 22:24
MemberMaria Adamsky27-Nov-10 22:24 
GeneralRe: Got ArgumentOutOfRangeException message Pin
Alexander Lishansky27-Nov-10 22:27
MemberAlexander Lishansky27-Nov-10 22:27 
GeneralRe: Got ArgumentOutOfRangeException message Pin
Alexander Lishansky27-Nov-10 22:25
MemberAlexander Lishansky27-Nov-10 22:25 
GeneralRe: Got ArgumentOutOfRangeException message Pin
Maria Adamsky27-Nov-10 22:38
MemberMaria Adamsky27-Nov-10 22:38 
GeneralGot KeyNotFoundException message Pin
Alexander Lishansky27-Nov-10 21:30
MemberAlexander Lishansky27-Nov-10 21:30 
QuestionRuntime exception with VCProjectEngine 10 Pin
Edgar Vilela Gadbem23-Nov-10 1:41
MemberEdgar Vilela Gadbem23-Nov-10 1:41 
AnswerRe: Runtime exception with VCProjectEngine 10 Pin
Maria Adamsky27-Nov-10 22:06
MemberMaria Adamsky27-Nov-10 22:06 
GeneralRe: Runtime exception with VCProjectEngine 10 Pin
Edgar Vilela Gadbem28-Nov-10 8:46
MemberEdgar Vilela Gadbem28-Nov-10 8:46 
QuestionSpecified cast is not valid - m_VcProj = (VCProject)vcprojEngine.LoadProject(vcProjFile); Pin
Donald Wickham15-Nov-10 11:49
MemberDonald Wickham15-Nov-10 11:49 
AnswerRe: Specified cast is not valid - m_VcProj = (VCProject)vcprojEngine.LoadProject(vcProjFile); Pin
Maria Adamsky15-Nov-10 22:23
MemberMaria Adamsky15-Nov-10 22:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.