I have a rather large C program I wrote over several years that started as a simple Win32 GUI. I used vi, nmake and microsoft's CL command line compiler as my build environment. It is a reasonably complex GUI with several running threads, network servers a COM port interface, several dialog boxes etc... I hand-built each item in the GUI and my makefile just builds them with the resource compiler (RC) prior to final linkage. Very tedious to change or update especially if it touches the GUI.
Anyway, the program lives on, but I'd really like to transition over to visual studio, and recreate the GUI using up-to-date tools. I don't want to use .NET, and I don't need C++, but I'm assuming I'm stuck with it if I do this (am I?).
Anyone have any suggestions on how to begin this without a lot of C-to-C++ rewriting?
Most C can be ported to C++ with little more than renaming the file extension from .c to .cpp. You get the benefits of C++ (stronger type checking, etc) but you can still write straight C.
But if you don't want to make that change, you can still use Visual Studio. Just create a new C++ project (File/New/From Existing Code) and point it at your existing C files. Visual Studio will happily compile and link your .c and .rc files without forcing you to use C++.
Related
Lets consider a project, with a following structure:
project
--main
--fileX.h
--fileX.cpp
--main.cpp // only file, that guranteed to have main()
--libA
--libA.h
--fileX.cpp
--fileY.cpp If they are outdated/not built - build them first
--libB
--libB.h
--fileZ.cpp
--fileW.cpp
Pretty simple, also lets consider that project must include and link something standart, like OpenGL lib.
On windows, where I came from, there is Visual Studio, and everything was extremely easy and in some kind of "standart" way:
You create solution project. This is like a root, which just incorporates projects, in a single tree
You create projects: main of type "binary" and a couple of libs libA, libB of "library" types (static or dynamic, whatever you require to). That will tell build system how should it glue them together
You edit main settings:
Add external include and lib names, and paths
Add dependencies. main requires libA and libB. That is simultaneously a hint on build order, plus a linkage hint
You add files here and there, code it all, make any changes.
Press debug/run and enjoy. Build system would (re)compile only nesesary files, and link everything needed
Everything involves less than 100 actions, I mean keystrokes and mouse clicks.
VS Commutiny IDE is totally free to use (so no "Use that cool paid IDE" offers could be made in comments and answers)
Now the question. I've installed Ubuntu and vscode, and I am running into wall, trying to setup same project. What actions should be done, so I am able to change any source file in the project, press F5 (Debug), and it would compile and run with same build setup and speed efficiency?
What I've considered?
Makefile: almost same as writing your own shell script. It's like you have to learn whole new language to do small pretty-standart task - build a project. High leven of entrance, to be good at it.
vscode launch.json/tasks.json - another language, with examples availble to compile only single file: main.cpp (or just active file). Hard to create manually, requires good knowledge of internal "env" variables
CMake - another new programming language, different from all others, don't even know how to make vscode and Cmake friends
How a beginner should start C++ debuging with a multi-lib project, without having to waste time maintain that infinite complex build systems?
We works in Visual Studio and write programs on C# .Net ASP.NET
For making a standard in naming text labels to controls (button, options etc.) we think to write some code analizys program which can analize code (before, of after compilation to IL) and can found in code text strings which used for naming labels, titles,. (or if label text is stored in variable, check value and make a decision, correct that name, or not.
What tool can i use for automation like that?
I have looked up internet, and found a StyleCop, FxCom, Code Analizys systems - but i understand that this systems have rules only for variable names, not label of control.
How can i make add-on to Visual Studio, which can read code (edited in this time by programmer) and make a warnings while compiling project to avoid programmer use for label non-appropriate values?
Thanks.
I've inherited some C99 code that I'm planing on reusing in a C++-centric solution. Unfortunately, even Microsoft's latest compiler has virtually no support for non-trivial C99 features.
The code in question has been tested to death and I'd rather not go through the trouble of rewriting it in C++. This means that in order for me to reuse the code verbatim I'll have to rely on a conforming 3rd-party compiler.
After looking around, it appears that the nicest way for me to integrate this code is by adding a "Makefile Project" to my solution. Only one problem. It seems like it is now my responsibility to keep the "Build Command Line" property synchronized with the files that I add to the project through Visual Studio.
At first glance, I couldn't find a way to get a list of files in my project through the usual Visual Studio $()-style macros. I could always write a shell script that would enumerate *.c files in my source tree and pass their paths to the 3rd-party compiler. However, I kind of expected that Visual Studio would do at least that part of the work for me since it already has this information in the relevant *.vc[x]proj file.
It is very unlikely that I'll need to add any new source files to this project, but still, manual synchronization (i.e., without a script) of this sort seems rather fragile to me.
What are my options besides writing a helper script?
From Hans Passant:
"Makefile project" means what it says,
there needs to be another 'agent'
that's responsible for the
dependencies. Like a make file. Rule
files can help you select another
build tool but that's kinda broken
right now in VS2010. Leverage the
original tool that built this C99
code, run it from the makefile
project.
I have a small (<300 lines) C++ file in a C++ CLI project in Visual Studio 2010.
I have crafted some macros which do different things depending on the Debug/Release configurations.
I would like to be able to look at the resulting .obj files (when I compile in Debug and Release) and be able to compare the two. The hard part is that files are binary and I do not understand their format.
I am sure there are other ways to ensure that the macro is not destructive - e.g. try it out at runtime in both modes, but that is a lot more time consuming. Plus, it would be cool to learn what those .obj have in them.
Thanks, let me know if you have questions.
Dumpbin.exe has some options to peek an the .obj file content. Building the final DLL and looking at either the generated machine code with the debugger or the IL with Ildasm.exe or Reflector ought to be a lot more productive.
I would like to use Visual Studio 2008 to the greatest extent possible while effectively compiling/linking/building/etc code as if all these build processes were being done by the tools provided with MASM 6.11. The exact version of MASM does not matter, so long as it's within the 6.x range, as that is what my college is using to teach 16-bit assembly.
I have done some research on the subject and have come to the conclusion that there are several options:
Reconfigure VS to call the MASM 6.11 executables with the same flags, etc as MASM 6.11 would natively do.
Create intermediary batch file(s) to be called by VS to then invoke the proper commands for MASM's linker, etc.
Reconfigure VS's built-in build tools/rules (assembler, linker, etc) to provide an environment identical to the one used by MASM 6.11.
Option (2) was brought up when I realized that the options available in VS's "External Tools" interface may be insufficient to correctly invoke MASM's build tools, thus a batch file to interpret VS's strict method of passing arguments might be helpful, as a lot of my learning about how to get this working involved my manually calling ML.exe, LINK.exe, etc from the command prompt.
Below are several links that may prove useful in answering my question. Please keep in mind that I have read them all and none are the actual solution. I can only hope my specifying MASM 6.11 doesn't prevent anyone from contributing a perhaps more generalized answer.
Similar method used to Option (2), but users on the thread are not contactable:
http://www.codeguru.com/forum/archive/index.php/t-284051.html
(also, I have my doubts about the necessity of an intermediary batch file)
Out of date explanation to my question:
http://www.cs.fiu.edu/~downeyt/cop3402/masmaul.html
Probably the closest thing I've come to a definitive solution, but refers to a suite of tools from something besides MASM, also uses a batch file:
http://www.kipirvine.com/asm/gettingStarted/index.htm#16-bit
I apologize if my terminology for the tools used in each step of the code -> exe process is off, but since I'm trying to reproduce the entirety of steps in between completion of writing the code and generating an executable, I don't think it matters much.
There is a MASM rules file located at (32-bit system remove (x86)):
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\VCProjectDefaults\masm.rules
Copy that file to your project directory, and add it to the Custom Build Rules for your project. Then "Modify Rule File...", select the MASM build rule and "Modify Build Rule...".
Add a property:
User property type: String
Default value: *.inc
Description: Add additional MASM file dependencies.
Display name: Additional Dependencies
Is read only: False
Name: AdditionalDependencies
Property page name: General
Switch: [value]
Set the Additional Dependencies value to [AdditionalDependencies]. The build should now automatically detect changes to *.inc, and you can edit the properties for an individual asm file to specify others.
You can create a makefile project. In Visual Studio, under File / New / Project, choose Visual C++ / Makefile project.
This allows you to run an arbitrary command to build your project. It doesn't have to be C/C++. It doesn't even have to be a traditional NMake makefile. I've used it to compile a driver using a batch file, and using a NAnt script.
It should be fairly easy to get it to run the MASM 6.x toolchain.
I would suggest to define Custom Build rules depending on file extension.
(Visual Studio 2008, at least in Professinal Edition, can generate .rules files, which can be distributed). There you can define custom build tools for asm files. By using this approach, you should be able to leave the linker step as is.
Way back, we used MASM32 link text as IDE to help students learn assembly. You could check their batchfiles what they do to assemble and link.
instead of batch files, why not use the a custom build step defined on the file?
If you are going to use Visual Studio, couldn't you give them a skeleton project in C/C++ with the entry point for a console app calling a function that has en empty inline assembly block, and let them fill their results in it?
Why don't you use Irvine's guide? Irvine's library is nice and if you want, you can ignore it and work with Windows procs directly. I've searching for a guide like this, Irvine's was the best solution.