LabWindows/CVI User Group Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

LabWindows/CVI Tip: Resolving Build Errors Using the LabWindows/CVI Preprocessor

Sometimes the LabWindows/CVI Build Output Window does not provide enough information to identify errors in your source code, but there are LabWindows/CVI development tools that can help you find these errors. One thing I find to be useful when hunting down errors is to examine the output from the LabWindows/CVI Preprocessor.  The CVI Options menu contains an entry that allows a developer to view a source file after it has been run through the CVI preprocessor..

Let's look at a LabWindows/CVI example program that contains an error and use the LabWindows/CVI preprocessor to identify what needs to be corrected. The following is an example of build output information for errors that were detected during compilation of the source file. Notice the error on line 7: syntax error; found ‘int’ expecting ‘{‘.

syntaxerror.png

If you only evaluate the graphs.c file, you would end up banging your head on the wall for hours because the root cause of this syntax error does not reside in this file. When you build your project, each source file in your project will be passed through the preprocessor, in order to resolve preprocessor directives such as #define and #include.  Once the source file has been preprocessed, the resulting source file may look very different from what you started out with. Because of this, it can sometimes be difficult to narrow down an error like the one mentioned above.

So this raises the question: How can I find where the syntax error resides? You can view the output of the LabWindows/CVI preprocessor to look at the code that is compiled at build time. Using this preprocessed source file, you can evaluate all the code that is being compiled and more quickly discover the line of code that is causing the error.

To view the output of the LabWindows/CVI preprocessor, ensure you are editing the source file of interest, and then select Options»Preprocess Source File.

preprocess source file.png

This will generate a source file that is the result running the source file you are editing through the LabWindows/CVI preprocessor.  With this file you can search for the line of code that caused the error and then evaluate the implementation preceding this line.  Using the preprocessed source file, we can see that that the line of code that is called before int handle; is missing a semicolon. The preprocessed source file also indicates the file in which error is coming from. In this case, we see that the line of code with the missing semicolon is in graphs.h.

preprocesssource.png

The preprocessed source file has given us enough information to open the file that is causing the error. This allows us to resolve the syntax error. In this example, we can open graphs.h and include a semicolon on the line of code that is causing the error to occur.

seimcolon.png

Did you find this tip useful? Rate this document or add a comment below.

If you give this a try, share your experience! Add a comment below.

Adri Kruger
National Instruments
LabVIEW Product Marketing
Contributors