0

Facing not referenced issue for the function prototyping using pc-lint. IDE : keil

external symbol 'test' was defined but not referenced [CERT C Recommendation MSC12-C]

714 Informational
The named external variable or external function was defined but not 
referenced.
Error in function.h file

header declaration for symbol 'test()' could be moved from header to module

Project Folder structure

->Inc
   --extern.h
   --function.h
->Src
   --main.c
   --test.c

CODE

extern.h

//include other header files
include "function.h"

#ifndef EXTERN_H_
#define EXTERN_H_

//other declaration

#endif /* EXTERN_H_ */

function.h

#include <stdint.h>

#ifndef FUNCTION_H_
#define FUNCTION_H_

void test(void);

#endif /* FUNCTION_H_ */

main.c

#include "extern.h"

int main(void) {
    test();
}

test.c

#include "extern.h"

void test(void) {
    //do something
}

Tried moving function declaration to extern file same issue.

Above is an example of how the code part is implemented and issue is that there are multiple file like test.c which are throwing the same issue.

Output LOG for PC-Lint using Vector Cast. I have masked the personal details of licensing part only.

2023-07-25 16:59:04,280 - pclp:60 [INFO] Parsed Args: Namespace(debug_level='DEBUG', pclp_cmd='D:\\pc_lint\\pclp\\pclp64.exe', compiler_options_file='D:\\pc_lint\\pclp\\config\\co-keil.lnt', options_file=['D:\\pc_lint\\pclp\\lnt\\project_vcast.lnt'], xml_input='D:\\keil_project\\test-uc\\TEST_UC\\build\\4026334200\\CARD_TEST\\generic-analysis_code_analysis.xml')
2023-07-25 16:59:04,280 - pclp:91 [INFO] Using PCLP: D:\pc_lint\pclp\pclp64.exe
2023-07-25 16:59:04,280 - analysis_request:55 [INFO] Parsing File: D:\keil_project\test-working\TEST_FILE_CHECK\build\4026334200\CARD_TEST\generic-analysis_code_analysis.xml
2023-07-25 16:59:04,280 - analysis_request:65 [INFO] Analysis Name: code_analysis
2023-07-25 16:59:04,280 - analysis_request:71 [DEBUG] Checking './include-paths/search-include-path'
2023-07-25 16:59:04,280 - analysis_request:73 [DEBUG] Adding Search Include Path: D:\keil_project\test-working\board
2023-07-25 16:59:04,280 - analysis_request:73 [DEBUG] Adding Search Include Path: D:\keil_project\test-working\Inc
2023-07-25 16:59:04,280 - analysis_request:73 [DEBUG] Adding Search Include Path: D:\keil_project\test-working\Src
2023-07-25 16:59:04,280 - analysis_request:76 [DEBUG] Checking './include-paths/type-include-path'
2023-07-25 16:59:04,280 - analysis_request:81 [DEBUG] Checking './include-paths/lib-include-path'
2023-07-25 16:59:04,280 - analysis_request:83 [DEBUG] Adding Lib Include Path: C:\VCAST\DATA\keil\LPC54606\Core\Include
2023-07-25 16:59:04,280 - analysis_request:83 [DEBUG] Adding Lib Include Path: C:\VCAST\DATA\keil\LPC54606\LPC54606_DFP\16.0.0
2023-07-25 16:59:04,280 - analysis_request:83 [DEBUG] Adding Lib Include Path: C:\VCAST\DATA\keil\LPC54606\LPC54606_DFP\16.0.0\drivers
2023-07-25 16:59:04,280 - analysis_request:83 [DEBUG] Adding Lib Include Path: C:\VCAST\DATA\keil\LPC54606\RTE\_Target_1
2023-07-25 16:59:04,280 - analysis_request:83 [DEBUG] Adding Lib Include Path: C:\Keil_v5\ARM\ARMCLANG\include
2023-07-25 16:59:04,280 - analysis_request:86 [DEBUG] Checking './sources/source'
2023-07-25 16:59:04,280 - analysis_request:88 [DEBUG] Adding Source Path: D:\keil_project\test-working\Src\test.c
2023-07-25 16:59:04,280 - analysis_environment:23 [INFO] Initializing AnalysisEnvironment For: code_analysis
2023-07-25 16:59:04,280 - analysis_environment:25 [INFO] Working Dir: D:\keil_project\test-working\TEST_FILE_CHECK\build\4026334200\CODE_TEST
2023-07-25 16:59:04,280 - analysis_environment:63 [INFO] Analysis Dir: D:\keil_project\test-working\TEST_FILE_CHECK\build\4026334200\CODE_TEST\code_analysis
2023-07-25 16:59:04,280 - analysis_environment:75 [DEBUG] Creating analysis dir
2023-07-25 16:59:04,280 - pclp_analysis:228 [INFO] Lint file: C:\VCAST\StaticAnalysisTools\pclp\vectorcast.lnt
2023-07-25 16:59:04,280 - pclp_analysis:229 [INFO] List file: D:\keil_project\test-working\TEST_FILE_CHECK\build\4026334200\CODE_TEST\code_analysis\vcast_code_analysis_fileList.lnt
2023-07-25 16:59:04,280 - pclp_analysis:230 [INFO] Analysis file: D:\keil_project\test-working\TEST_FILE_CHECK\build\4026334200\CODE_TEST\code_analysis\vcast_code_analysis_analysis.xml
2023-07-25 16:59:04,280 - pclp_analysis:231 [INFO] Result file: D:\keil_project\test-working\TEST_FILE_CHECK\build\4026334200\CODE_TEST\vcast_code_analysis.xml
2023-07-25 16:59:04,280 - pclp_analysis:234 [INFO] Compiler options file: D:\pc_lint\pclp\config\co-keil.lnt
2023-07-25 16:59:04,280 - pclp_analysis:240 [INFO] Options file: D:\pc_lint\pclp\lnt\code_analysisssdac_project_vcast.lnt
2023-07-25 16:59:04,280 - pclp_analysis:247 [INFO] Running Analysis: D:\pc_lint\pclp\pclp64.exe -b +b -os["D:\keil_project\test-working\TEST_FILE_CHECK\build\4026334200\CODE_TEST\code_analysis\vcast_code_analysis_analysis.xml"] --i"D:\pc_lint\pclp\config" D:\pc_lint\pclp\config\co-keil.lnt C:\VCAST\StaticAnalysisTools\pclp\vectorcast.lnt D:\pc_lint\pclp\lnt\code_analysisssdac_project_vcast.lnt D:\keil_project\test-working\TEST_FILE_CHECK\build\4026334200\CODE_TEST\code_analysis\vcast_code_analysis_fileList.lnt
PC-lint Plus 2.0 for Windows, Copyright Vector Informatik GmbH 1985-2022
licensed to **************************** (***********************************)
25-jul-2023, license expires ************* (**************)
2023-07-25 16:59:06,201 - pclp_messages:33 [INFO] Requesting Messages
PC-lint Plus 2.0 for Windows, Copyright Vector Informatik GmbH 1985-2022
licensed to **************************** (***********************************)
25-jul-2023, license expires ************* (**************)
2023-07-25 16:59:06,436 - pclp_messages:58 [INFO] Parsing Message File: D:\keil_project\test-working\TEST_FILE_CHECK\build\4026334200\CODE_TEST\code_analysis\msg.xml
2023-07-25 16:59:06,436 - analysis_environment:119 [DEBUG] Creating TEXT docs dir: D:\keil_project\test-working\TEST_FILE_CHECK\build\4026334200\CODE_TEST\code_analysis\docs\text
2023-07-25 16:59:06,436 - analysis_environment:142 [DEBUG] Creating TITLE docs dir: D:\keil_project\test-working\TEST_FILE_CHECK\build\4026334200\CODE_TEST\code_analysis\docs\title
rock123A
  • 82
  • 2
  • 11
  • Your sources as shown look good. Are you sure you saved all files before running PC-Lint? – the busybee Jul 24 '23 at 05:42
  • @thebusybee Yes i have saved, compiled the file before running PC-Lint. – rock123A Jul 24 '23 at 06:09
  • Is it possible that some optimization stage removed the call and implementation of `test()`, because it has no effect at all? – the busybee Jul 24 '23 at 06:18
  • No this file being called from multiple source file and performing actions. I don't think so that call is removed in any optimization stage. – rock123A Jul 24 '23 at 06:25
  • Also the in function.h getting following issue header declaration for symbol 'test()' could be moved from header to module. – rock123A Jul 24 '23 at 06:26
  • This second message tells me that `test()` is actually _not called_ in `main()` or, more generally, in another module. Are the sources really the ones you check? If not, please [edit] your question and provide the [mre]. – the busybee Jul 24 '23 at 06:34
  • @thebusybee since PC-Lint is a _source code_ static analysis tool, optimisation is not in play. – Clifford Jul 24 '23 at 10:08
  • @Clifford Correct, but assuming the provided source are the ones that are checked, there might be an unseen step on the source level. Currently the OP did not tell us more on the process. I'm sure that is some [layer-8](https://en.wikipedia.org/wiki/Layer_8) error. – the busybee Jul 24 '23 at 10:11
  • You should post the entire lint analysis log so we can see exactly what it is processing. – Clifford Jul 24 '23 at 12:40
  • When I see a `extern.h` with `//include other header files include "function.h"`, then I doubt, they understand what headers are for and what they are not for. Also make sure, the usage of test() is not optional (compiler switch) and also let pclint analyse the using .c files (e.g. main.c in your code example). – kesselhaus Jul 24 '23 at 19:53
  • I guess the issue is that it is processing a single .c file at a time along with the function declaration due to which it is not able to find the reference of the function used in the main.c file. Will need some time to look into it. – rock123A Jul 25 '23 at 04:10
  • @thebusybee comment "This second message tells me that test() is actually not called in main()" got me thinking regarding the same and I guess this can be the cause. – rock123A Jul 25 '23 at 04:13
  • So you urgently need to [edit] your question and show us _how_ you let PC-Lint analyze your code. – the busybee Jul 25 '23 at 05:18
  • @thebusybee have updated the same – rock123A Jul 26 '23 at 04:18
  • Thanks for the log, but this is only the output. We still cannot see _how_ you analyze, the input. The error message makes only sense, if you are not giving the complete project to PC-Lint, that's why we ask for "_how_". This would be the command line, the content of configuration files and so on. Your provided sources are so simple that we can assure you there is nothing wrong with it, in contrast to the shown error messages. Therefore, it has to be a issue of the usage of PC-Lint. – the busybee Jul 26 '23 at 06:06
  • Ok looking into it. – rock123A Jul 27 '23 at 04:16

0 Answers0