VS2019: Include file as project macro - c

I got a makefile project for Linux and I want to compile it on Win10 with Visual Studio 2019.
There are some paths to files defined in the makefile as preprocessor defines.
I have to replace the paths by own created files because they are a kind of PLATFORM_HEADER and I have to adapt a new one to Windows. In the code it looks like:
#include PLATFORM_HEADER
The onliest I tried is to add a property sheet to my project and add a macro:
macro page of property sheet But this macro is not found in the project.
Changing the code is not possible because it is third party code and it must be able to become updated at later times without doing changes again.
In other instructions there is noted that a line called 'inherited property sheet' has to be modified in the project. But in VS2019 this line does not exist.
Thank you for your help!

This sort of problem will be handled by your compiler suite. Probably you'll deal this with your build process manager (make, bitbake, cmake...). You can ask it to pass these #defines as argument for the compilation (-D name=definition).
Now you've unlocked the "very most of fun" if you compile something meant for linux on windows since there are many way that can go wrong. You might want to do a full check of your environment variable when compiling and make sure they point to the right system librairies.
Probably it's worth giving a try to the windows subsystem for linux and other bindings / emulator. If you want to preview a week of work's outcome, maybe you can do it in a linux VM? or just get rid of windows one good time for all :)

Related

Using Visual Studio 2008 with Code Warrior compiler

New to the site. I am hoping you can help me as I've been beating my head against the wall on this one for a month now.
This is for work, and we are kind of proprietary but I will try to share as much information as possible. We have MPC5674F microcontroller on our main development board. To write code before, we used Microsoft Visual Studio 2008 along with a makefile and gcc compiler to create a .s19 file that is then flashed onto the board. Before, Visual Studio would not recognize make command. I went into C:\MinGW folder and found 3 different make.exe type files. There is gnatmake.exe, mingw32-make.exe and regular make.exe in C:\MinGW\msys\1.0\bin. I also found a regular make.exe in an NXP folder from the S32Design Studio. All of those make commands give me different result. If I change one that is by MinGW, then it gets stuck in the makefile saying The system cannot find the path specified to an echo.exe command, even though I can once again go into command window and type echo and it outputs ECHO is on. If I use just make.exe from either NXP of the other folder from MinGW, it compiles without errors but there is no file output, or even the process of how it compiled. In our makefile we specify to output each file that it compiles and nothing happens. If I use gnatmake.exe It gets stuck at command gcc -c -Ietc\ -I- -x ada etc\makefile where it says there is illegal character and target_name is an Ada 2020 feature. Not sure what any of those mean.
I managed to somehow previously get this to compile before, but since then the PC (Windows 10) had to be wiped and reinstalled. Guys that have set this up are long since retired (before I started) so I am hoping you guys can help me out.
Okay so I managed to get it to work. How, I am not entirely sure. I did wind up editing my commands for linux inside the makefile to have quotes around them because Windows kept removing slashes from the path written in the makefile. Also I provided a path to the Unix utilities and the make.exe to C:\MinGW\msys\1.0\bin instead of C:\MinGW\bin. I also had to add the same path to the $Path variable in Environmental Variable The code compiles now and seems to work after flashing it onto our system. My hope now is the instructions I wrote for anyone else to do this will work and I didn't forget something.

Automatically defining C/C++ include path on WSL Visual Studio Code

When using the C/C++ extension for Visual Studio Code with WSL, it will never refer to /usr/include/ unless you create a project file any time, as you have to allow it to create a local config file called c_cpp_properties.json. This means you simply cannot run standalone C files unless you create a workspace around it.
Is there some way to automate this, even a little? It's very annoying having to redefine my standard includes every time I reopen the program.
Ideally I would like to set this up such that I can just work with my C files standalone rather than as a project as I am frequently using university assets and it's very annoying to have to create a project to work with any demo they give me. I have looked everywhere but just can't find any kind of global setting where I can tell the extension to refer to /usr/include/ - with or without a local config file for the project.
Thanks

how do you create a .c file in Visual Studio 2017 Professional

I am extremely new to programming and have found that a good majority of my mentors use Visual Studio to code in C.
I would like to get an early start using SAMS C Programming.
Can anyone please tell me how to create a .c file in VS 2017? I am only able to create a .cpp file at this time.
Thanks
What you most likely actually want to do is create a project. Go to File-> New-> Project. Most likely, the first programs you will write are console applications (meaning they appear on that screen that resembles an old computer monitor, or what some computer screens look like when booting). If you want to create a console application, go from Project to Visual C++-> Windows Desktop-> Windows Console Application. Ignore any additional pop-up windows and just keep clicking continue. A file called main.cpp will automatically be generated. This is the file you will want to use for your code examples (but DO NOT DELETE the #include "stdafx.h" line, even if your example code does not have it).
Visual Studio compiles both .c and .cpp files as C++ by default. C++ has nearly everything that C has, but may take longer to compile when dealing with huge projects. If you want to use strictly C with no C++, then go to Project (a separate project tab on the same toolbar as the file tab -- it isn't within the file tab)-> ProjectName(Your Project Name) Properties-> Configuration Properties-> C/C++-> Advanced and select "Compile As". You should see a square with a upside-down "^" in it. Click that and select "Compile as C Code (/TC)". The "/TC" is just what you would type in if you were using command-line arguments instead of the convenient window that appears for you to modify everything. Finally, rename main.cpp to main.c.
Since you're learning C, I would also like to mention that I started making a C tutorial on my web site (and if anybody else also happens to see this post and the tutorial, criticize the tutorial as harshly as you can in the comments below).
Click on File, Choose Project --> Visual C++ --> Windows Desktop and under Windows desktop Choose Windows desktop wizard and give project name in the bottom then click on OK. a pop of Windows Desktop Project will come, check empty project and uncheck all options.then click on OK after that in the right side along with your project name more options will come..right lick on source file-> add -> new items -> choose c++ plus file but in bottom give file with extension .c..and you are done .enjoy coding
If you are truly interested in learning to program in C, then leave the VS Code IDE for later and learn to Build C/C++ code on the command line. VS provides a reasonably good compiler (cl.exe) and pre-configured command line (command prompt) windows to build both 32 and 64 bit applications.
The benefit to using the command line is learning what the compiler options are and what they actually do. Simply open a VS command line window and type cl /help. The compiler will list all options along with a short description. There are a great number of resource for command line building that can be accessed through the link above.
A second benefit is you can rapidly compile all your beginning C examples without worrying about projects, etc.. Just cl /nologo /Wall /Ox /Foname.o /Fename.exe /Tc name.c and you are done. (you will want to suppress unneeded warning with individual /wdXXXX options where XXXX is the warning to suppress) 50 Times faster than using the IDE.
Once you are proficient in using the command line, you will have a much easier time transitioning to the IDE -- because you can properly configure the IDE with the appropriate options for your build and you will know what the IDE is doing under the hood (or should be doing under the hood)

C error parsing in Eclipe-Indigo is not functioning

I'm trying to migrate some C programs from Windows Server to Linux. To edit the code, I'm using Eclipse-Indigo. The machine on which I'm working has WinXP on it (not my choice, so no comments please). My eclipse workarea is on a samba shared drive which is in my home directory on the Linux server.
Each C program is in a separate makefile project. I have specified the cygwin gcc compiler/parser in the settings for new CDT Projects and selected all relevant error parsers in the makefile project settings.
There are no syntax errors showing and the errors that are listed seem somewhat bizarre. The first error states:
make: *** No rule to make target `../../../../../fiscus/vo/src/mk/e12_.mk'. Stop.
The make script at the end is wrong. There is a value in the name which comes from an environment variable. The path is correct exactly as shown but the script name has hte variable $(WA_PLATFORM) in it. This is not being resolved although I have specified the value in the build environment variables.
The subsequent errors are even weirder. For each subsequent project I get the message:
Program "make" is not found in PATH
This makes me wonder how the first message was generated. Besides, the path on my winXP environment, which I assume is the relevant one here, does indeed have the directory with the make program in it.
Where have I mucked it up? Any hints?
One last piece of information. When I shut down eclipse I get access violation errors for the following:
<workarea-path>\.metadata\plugins\org.eclipse.debug.ui\launchConfigurationHistory.xml
<workarea-path>\.metadata\plugins\org.eclipse.jdt.core\variablesAndContainers.dat
I find this to be suspicious...
The problem appears to lie in the fact that I was using the samba share as my workarea. Apparently the regular backups made on the server changed something (don't know exactly what, though). The projects were no longer being recognised as makefile projects and certain essential metadata files were not accessible. The permissions certainly were not the problem, since I checked those on the server (everything was set to rwxrwxrwx).
To solve the problem I copied the entire workarea to my local hard drive. I then pointed eclipse at this new workarea. The next step was a bit of a pain, because I had to delete each project (without deleting the source, of course) and then import "Existing code as Makefile Project". This can be done with "File->import..." or with a right-click in the package explorer and select "import...".
The last requirement is to specify the required "include" directories. This can be done with "Project-> Properties-> C/C++ General-> Paths and Symbols". Select the "Includes" tab, choose the language (in this case "GNU C") and add the directories where the headers are defined.
Now it works properly again.

Setting up Netbeans/Eclipse for Linux Kernel Development

I'm doing some Linux kernel development, and I'm trying to use Netbeans. Despite declared support for Make-based C projects, I cannot create a fully functional Netbeans project. This is despite compiling having Netbeans analyze a kernel binary that was compiled with full debugging information. Problems include:
files are wrongly excluded: Some files are incorrectly greyed out in the project, which means Netbeans does not believe they should be included in the project, when in fact they are compiled into the kernel. The main problem is that Netbeans will miss any definitions that exist in these files, such as data structures and functions, but also miss macro definitions.
cannot find definitions: Pretty self-explanatory - often times, Netbeans cannot find the definition of something. This is partly a result of the above problem.
can't find header files: self-explanatory
I'm wondering if anyone has had success with setting up Netbeans for Linux kernel development, and if so, what settings they used. Ultimately, I'm looking for Netbeans to be able to either parse the Makefile (preferred) or extract the debug information from the binary (less desirable, since this can significantly slow down compilation), and automatically determine which files are actually compiled and which macros are actually defined. Then, based on this, I would like to be able to find the definitions of any data structure, variable, function, etc. and have complete auto-completion.
Let me preface this question with some points:
I'm not interested in solutions involving Vim/Emacs. I know some people like them, but I'm not one of them.
As the title suggest, I would be also happy to know how to set-up Eclipse to do what I need
While I would prefer perfect coverage, something that only misses one in a million definitions is obviously fine
SO's useful "Related Questions" feature has informed me that the following question is related: https://stackoverflow.com/questions/149321/what-ide-would-be-good-for-linux-kernel-driver-development. Upon reading it, the question is more of a comparison between IDE's, whereas I'm looking for how to set-up a particular IDE. Even so, the user Wade Mealing seems to have some expertise in working with Eclipse on this kind of development, so I would certainly appreciate his (and of course all of your) answers.
Cheers
Eclipse seems to be pretty popular for Linux kernel development:
http://cdtdoug.blogspot.com/2008/12/linux-kernel-debugging-with-cdt.html
http://jakob.engbloms.se/archives/338
http://revver.com/video/606464/debugging-the-linux-kernel-using-eclipsecdt-and-qemu/
I previously wrote up an answer. Now I come up with all the details of the solution and would like to share it. Unfortunately stackoverflow does not allow me to edit the previous answer. So I write it up in this new answer.
It involves a few steps.
[1] The first step is to modify linux scripts to leave dep files in. By default after using them in the build, those dep files are removed. Those dep files contains exact dependency information about which other files a C file depends. We need them to create a list of all the files involved in a build. Thus, modify files under linux-x.y.z/scripts to make them not to remove the dep files like this:
linux-3.1.2/scripts
Kbuild.include: echo do_not_rm1 rm -f $(depfile);
Makefile.build: echo do_not_rm2 rm -f $(depfile);
The other steps are detailed in my github code project file https://github.com/minghuascode/Nbk/blob/master/note-nbkparse. Roughly you do:
[2] Configure with your method of configuration, but be sure use "O=" option to build the obj files into a separate directory.
[3] Then use the same "O=" option and "V=1" option to build linux, and save make output into a file.
[4] Run my nbkparse script from the above github project. It does:
[4.1] Read in the make log file, and the dep files. Generate a mirroring command.
[4.2] Run the mirroring command to hard-link the relevant source files into a separate tree, and generate a make-log file for NetBeans to use.
Now create a NetBeans C project using the mirrored source tree and the generated log file. NetBeans should be able to resolve all the kernel symbols. And you will only see the files involved in the build.
The Eclipse wiki has a page about this: HowTo use the CDT to navigate Linux kernel source
I have been doing some embedded linux development. Including kernel module development and have imported the entire linux kernel source code into Eclipse, as a separate project. I have been building the kernel itself outside of Eclipse(so far), but I don't any reason why I shouldn't be able to set up the build environment within Eclipse to build the kernel. For my projects, as long as I setup the PATH properties to point to the appropriate linux source include directories, it seems to be pretty good about name completion for struct fields, etc.
I can't really comment, on if it is picking up the correct defines and not greying out the correspond sections, as I haven't really paid to much attention to the files within the kernel itself.(so far)
I was also wondering about using Netbeans as a linux 'C' IDE, as I do prefer Netbean's for Java GUI development.
I think this would work (done each step for various projects):
[1] Modify kernel build scripts to leave .d files. By default they are removed.
[2] Log the build process to a file.
[3] Write a script to parse the build log.
[3.1] From the build log, you know every .c files.
[3.2] From the .c file, you know which is the corresponding .d file.
[3.3] Look into .d files to find out all the included .h files.
[3.4] Form a complete .c and .h file list.
[4] Now create a new dir, and use "ln -s" or "ln" to pick files of interest.
Now, create a Netbeans project for existing source code in the [4].
Configure code assistance to use make-log file. You should see
exactly the effective source code as when you build it at [2].
Some explanations to the above steps:
At [2], do a real build so the log file contains the exact files and flags of interest.
Later netbeans will be able to use the exact flags to parse.
At [4], pick only the files you want to see. Incorporating the whole kernel tree into netbeans will be unpractical.
There is a trick to parsing .d files: Many of the depended items are not real paths to a .h file, they are a modified entry for part of the linux config sections in the auto config file. You may need to reverse the modification to figure out which is the real header file.
Actually there is a topic on netbeans site. This is the discussion url: http://forums.netbeans.org/ntopic3075.html . And there is a wiki page linked from the discussion: wiki.netbeans.org/CNDLinuxKernel . Basically it asks you to prefix make with CFLAGS="-g3 -gdwarf-2" .
I found this link very helpful in setting up proper indexing in Eclipse. It requires running a script to alter Eclipse environment to match your kernel options, in my case
$ autoconf-to-eclipse.py ./include/generated/autoconf.h .
An illustrated guide to indexing the linux kernel in eclipse

Resources