How Do You Troubleshoot the C Error “No such file or directory…compilation terminated”?

Problem scenario
You try to compile a C program, but it fails with “compilation terminated.” The error message says “foobar/foobar.h No such file or directory.” What should you do?

Solution
This solution does not address where should header files for c go. But it addresses the problem.
Find where foobar.h is: sudo find / -name foobar.h

Run the gcc command again,

How Do You Troubleshoot a C Program That Prints a Warning Message like “expects argument of type ‘int’, but argument 2 has type ‘char *’ [-Wformat=]”?

Problem scenario
You compile a C program (with gcc foobar.cc) but you get an error message like this:

basicprog.c:5:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘char *’ [-Wformat=]
printf (“y is a %d\n”,y);

What do you do to not get this error?

Solution
While the code compiles, the executable may not run.  A compilation error can be benign. 

How Do You Troubleshoot Messages about a markupsafe Fatal Error, C Extension Not Being Compiled, And/Or a Syntax Error with async when You Are Trying to Build a Docker Image?

Problem scenario
You wrote a Dockerfile. You are using it to try to create a Docker image. When you run the “docker build” command you get some error messages. The errors include one or more of the following:

1) A MarkupSafe fatal error related to Python.h.
2) A C extension not being compiled.
3) An invalid syntax error related to async (e.g., “Jinja2/jinja2/asyncfilters.py”).

You need to base the image off Ubuntu.

How Do You Find what Version of C++ Is Installed?

Problem scenario
You have C++ installed. You want to know what version it is. What do you do?

Solution
Possible solution #1
Run this command: /usr/bin/cpp -v

Look for the word “version”. Use CTRL-c to exit out.

Possible solution #2
Run these two commands:

. /opt/intel/bin/iccvars.sh intel64
icc -v

(Taken from https://superuser.com/questions/465949/how-to-know-what-version-of-c-compiler-is-installed-on-linux-server)

How Do You Create Your Own RPM Package (Binary File) for Your Own C Program?

Problem scenario
You want to know more about RPM packaging so you can create your own .rpm file (a custom RPM package file).  In other words you want to create your own RPM package (a binary file).  You want it for installing an uncompiled C program you wrote.  The uncompiled C program is one .c file and very simple.  You don’t know how to use a spec (specification) file to create your own RPM package file. 

How Do You Troubleshoot the C Compile-Time Error “gcc: error trying to exec ‘cc1plus’: execvp: No such file or directory”

Problem scenario
You run gcc to compile a C program, but you get this error:
“gcc: error trying to exec ‘cc1plus’: execvp: No such file or directory”

Solution
Install a C compiler.  If you do not know how, see this posting.

How Do You Troubleshoot a C Program That Prints a Warning Message like “expects argument of type ‘char*’, but argument 2 has type ‘int’ [-Wformat=]”?

Problem scenario
You compile a C program (with gcc foobar.cc) but you get an error message like this:

“foofbar1.cc:71…: warning: format ‘%s’ expects argument of type ‘char*’, but argument 2 has type ‘int’ [-Wformat=]
   printf (“y is a %s\n”, y);
                           ^  “

What do you do to not get this error?

Solution
While the code compiles, the executable may not run. 

How Do You Troubleshoot Sonarqube Not Starting with Log Messages about “failed to load plugin”?

Problem scenario
You are using SonarQube Community Edition.  SonarQube will not start.  You recently moved a .jar file into a plugins directory.  You want to use this plugin to analyze code.  

The SonarQube logs may register something like “Background initialization failed. Stopping SonarQube java.lang.IllegalStateException: Fail to load plugin C / C++ / Objective-C [cpp]”

The logs may also say something like this: “Unable to register extension com.A.A.A.B.F from plugin ‘cpp’ or “NoClassFoundError…PropertiesDao”.

How Do You Troubleshoot a C Program Displaying the Error “Segmentation fault” at Run Time?

Problem scenario
Your C program compiles.  But you get the error “Segmentation fault.”  You expect the value of a variable to be printed.  How do you get the value to be printed without this error?

Solution
Does every print function print?  If one print function seems to be displaying the “Segmentation fault” error, look closely at the syntax thereof.  Here is a line that will produce this error:

  

How Do You Create a Function in the C Programming Language?

Problem scenario
You are familiar with functions in programming languages (e.g., Python or SQL).  You like how you can create a modular program with a function.  Functions can allow you to reuse code and do data processing in a way that is readable.  Logic can be created rapidly when you know how to use a function.  How do you write a function in the C?

Solution

Prerequisites
Install the C compiler.