How to configure vim for embedded programming? - c

I was wondering how to configure vim for embedded programming? Precisely, how to "replace" Atmel studio with vim (I do not want to install Atmel studio with wine)?
Imagine we have only a single main.c file, ALE says that these files cannot be found:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
int main() {
// nothing special
}
And of course it does not compile as compiler can't find those header files.
I think I installed all the necessary libraries. Maybe there is some problem with the path? How do I configure the path?

Actually Vim can replace any IDE regardless of type of programming, it doesn't matter whether it is embedded for AVR, embedded for ARM, C/C++, python, Java...
Vim is just a powerful text editor, so it is not its problem that You cannot compile your project for AVR. It is not the case of Vim. What kind of build system do You use? Is it Make or something else? Or maybe You don't use any of these and You compile straight from command line?
Provide us with more information :)

I was trying to compile main.c with gcc, but then I compiled it with avr-gcc instead. Warnings of "file not found" didn't go away, but it compiled successfully.

Related

Cannot open source file "stdio.h" in Visual Studio Code

I'm new to C and this is my first project using visual studio. I have #include <stdio.h> in the first line of the code but there is an error "cannot open source file "stdio.h" C/C++ (1696)". I have installed the Microsoft C/C++ extension. I am happy to clarify anything. Thank you!
Note:
Be aware that VSCode is simply an editor. With some extensions installed, it may help you code "faster & easier".
Solution:
But in order for you to compile the code it is less beginner friendly than IDEs like CodeBlocks.
The way I do it is by going to :
Terminal > New terminal
cd "the_directory_in_which_the_file.c_exists" (don't forget the double quotes)
gcc "file.c"
./a.out (./a.exe on Windows)
Just in case:
if gcc (the compiler in this case) is not installed, then you can quickly do so by following this article's steps if you use Windows, or this one if you are on Linux.

How to compile C Linux libraries for use in Windows?

I have a C program written on linux that I would like to be able to run and develop on window. The program has a few external dependencies on posix/linux libraries so I'm guessing I would need to somehow compile those libraries under windows too. I'm quite new to the linux workflow, and no expert in C and it's compiler make up either. I know something like cygwin and/or msys2 and/or mingw-w64 might be what I need but I'm not really sure how to get it working in a way that would make sense for me.
My program looks like this (only relevant parts shown), and currently runs under my ubuntu linux VM:
// Build:
// gcc -o disc-identifier main.c `pkg-config --cflags --libs glib-2.0 libmirage libisofs-1`
//
// Run:
// disc-identifier test_image.nrg
#include <glib.h>
#include <mirage/mirage.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <limits.h>
#include <libisofs.h>
...
int main (int argc, char **argv)
{
...
}
My ideal goal is to be able to have this as a visual studio project that I can add to a solution and to be able to link the required dependencies (and compile) from within visual studio. I then want it to compile into a portable 32-bit x86 application (maybe with a few accompanying dll files), no bigger than a few MB. But from my understanding I would first need windows compatible versions of the used libraries (glib, libmirage, libisofs), which is where I am a bit lost as to how I would go about this.
I'm really not an expert of cross-platform development but I already build a cross-platform game (made with Irrlicht) mostly developped on Linux.
Have you heard or maybe already build your project with CMake ?
If not, I really invite you to check this very powerfull tool that CMake is.
Without entering in the details, CMake is a tool for cross-platform development that take care of many things and deliver to you ready-to-use build solutions, including for examples: Makefiles and Visual Studio solution files.
With little setups, you should be able to generate a .sln file for Visual Studio already ready to build your project for you (or require additional setups such as paths or DLL).
Sorry in advance if I misunderstand you question or if I'm not thorough technically.
Please let me know if you want for me to expand my answer ;)
Yes, you are right - if the libraries are not "header-only" you need a platform specific build. But this is really easy right now. For this purpose I can recommend vcpkg.
It supports msbuild and cmake integration - really nice.
To install for example glib you only need to open a cmd in your vcpkg folder and enter
vcpkg install glib
Visual studio supports both "msbuild" and "cmake" very well. Another option is to add dependencies via "NuGet" directly in Visual Studio.
If you use those tools, you don't need to compile the libraries yourself.
But what you have to check is if all your libraries support Windows. If not you can develop with Visual Studio and need to debug with "Remote Debugging". The easiest way is to use Windows Subsystem For Linux (WSL).

regex.h in dev-c++ (windows )

I am trying to use regex in a c program. i am using windows 10 and Dev-C++ . whenever i add header file for regex i.e.
#include <regex.h>
it gives me error
[error] regex.h: NO such file or directory.
i couldn't figure out how to download and install regex library for c in dev-c++. compiler: TDM-GCC 4.9.2 64-bit Release. Thanks for your help.
I assume there something wrong with the include path during the compilation process. There is a nice expanation of the compilation process of c/c++ applications over here, in case you're interested.
Basically, when compiling a c/c++ application, your compiler, in a first step, scans your source files and replaces all #include <file.h> with the content of file.h it finds in its search path.
Dev-c++ uses MinGW and a port of the GNU compiler collection (gcc) for the compilation process.
Now what you have to do:
Figure out whether regex.h is included in your MinGW installation (Check /usr/include.)
Adapt the include path in dev-c++
Sadly I don't have a computer running Windows nearby making it hard to help with these two steps. To install regex on MinGW this package seems promising.

MSP430 (msp430-gcc) linker undefined reference to

I'm trying to compile my MSP430 project using the Linux msp430-gcc compiler.
When I try to compile it using the CCS IDE it works just fine, but when I try to compile it using the msp430-gcc commandline tool, I get linker errors about functions like calloc and __no_operation.
The beginning of my source file looks like this:
#include <stdio.h>
#include <stdlib.h>
I compile the program using the following command:
msp430-gcc -mmcu=msp430g2553 -o test.out source_file.c
So it looks like I include the stdio.h and stdlib.h just fine, but I still get linker errors about functions like calloc.
I also tried using arguments like -lc, but that doesn't seem to help.
I read that both stdio and stdlib get included automatically by the compiler so I guess there is no need to use additional arguments for these files.
Does anyone have any idea how I could fix this?
Thanks.
mspgcc was a fork of gcc; by now, it's horribly outdated.
Nowadays, MSP430 development happens in gcc itself.
You could compile the latest version of gcc yourself, or hope that your distribution has a MSP430 cross compiler, or get it from TI.

How to configure eclipse for C?

I've installed an eclise for C/C++ developers. But unable to compile the code. It doesn't get #include <stdio.h> saying: unresolved inclusion <stdio.h>. I wonder if I have to make some addtional configuration. My OS is Windows 7 32 bit.
Please advise.
Well if such basic things do not work, then you must have missed to install a proper toolchain. Just downloading Eclipse and CDT will not "do" it. So install some usable compiler, linker etc.

Resources